towerops/nix/build.nix
Graham McIntire af9537939b
fix: complete Nix Docker image build and untrack .claude/settings.local.json
Nix build fixes:
- Override beamPackages.elixir to use 1.19.5 instead of default 1.18.4
- Add explicit buildPhase to compile dependencies before application
- Remove postInstall phase (Mix automatically includes priv/ in release)
- Set HEX_OFFLINE=false to allow dependency fetching in Nix sandbox

Docker image build now succeeds (~507 MB compressed).

Also remove .claude/settings.local.json from git tracking (keep local).
File remains in working directory but is now properly ignored.
2026-02-07 14:14:26 -06:00

114 lines
2.8 KiB
Nix

{
lib,
beamPackages,
towerops-nif,
net-snmp,
writeShellScriptBin,
git,
cacert,
}:
beamPackages.mixRelease {
pname = "towerops";
version = "0.1.0";
# Source files (filtered to exclude build artifacts)
src = lib.cleanSourceWith {
src = ../.;
filter =
path: type:
let
baseName = baseNameOf path;
in
# Exclude build artifacts and temp directories
baseName != "_build"
&& baseName != "deps"
&& baseName != ".elixir_ls"
&& baseName != ".elixir-tools"
&& baseName != "node_modules"
&& baseName != "cover"
&& baseName != ".git"
&& baseName != ".nix-postgres"
&& baseName != ".nix-redis"
&& baseName != ".nix-mix"
&& baseName != ".nix-hex"
&& baseName != ".worktrees"
&& baseName != ".nix-services-started";
};
# Mix environment
mixEnv = "prod";
# Environment variables for build
MIX_OS_DEPS_COMPILE_PARTITION_COUNT = "6";
# Need git and SSL certificates for fetching git dependencies
nativeBuildInputs = [
git
cacert
];
# Override Mix phases to handle vendored deps properly
configurePhase = ''
runHook preConfigure
# Set SSL certificate path for git operations
export SSL_CERT_FILE="${cacert}/etc/ssl/certs/ca-bundle.crt"
export GIT_SSL_CAINFO="${cacert}/etc/ssl/certs/ca-bundle.crt"
# Disable Hex offline mode to allow fetching dependencies
export HEX_OFFLINE=false
# Get all deps (including hex deps that vendored packages need)
mix deps.get --only prod
runHook postConfigure
'';
# Pre-build: Copy pre-built NIF and stub the Makefile to skip rebuild
preBuild = ''
# Copy pre-built NIF shared library
mkdir -p priv
cp ${towerops-nif}/lib/towerops_nif.so priv/
# Stub the c_src/Makefile to prevent rebuild
cat > c_src/Makefile << 'EOF'
# Stubbed Makefile - NIF pre-built by Nix
all:
@echo "Using pre-built NIF from ${towerops-nif}"
clean:
@echo "NIF managed by Nix, nothing to clean"
.PHONY: all clean
EOF
'';
# Custom build phase to compile deps first, then app
buildPhase = ''
runHook preBuild
# Compile dependencies (including custom compilers like phoenix_live_view)
mix deps.compile
# Compile application
mix compile
runHook postBuild
'';
# Build assets after Mix compilation
postBuild = ''
# Build production assets (Tailwind + esbuild)
mix assets.deploy
'';
# MIB files and NIF are automatically included by Mix release
# Mix includes everything in priv/ directory when building the release
# No postInstall needed - NIF was copied to priv/ in preBuild
# and MIB files are already in priv/mibs/ from source
meta = {
description = "Towerops - Phoenix LiveView SNMP monitoring platform";
license = lib.licenses.unfree;
platforms = lib.platforms.unix;
};
}