{ 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" && baseName != ".nix-postgres-version"; }; # 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; }; }