{ lib, beamPackages, towerops-nif, net-snmp, writeShellScriptBin, }: beamPackages.mixRelease { pname = "towerops"; version = "0.1.0"; # Source files (filtered to exclude build artifacts) src = lib.sourceFilesBySuffices ../. [ ".ex" ".exs" ".eex" ".heex" ".leex" ".erl" ".hrl" ".js" ".ts" ".css" ".json" ".proto" ".md" ".txt" ".mib" ".gitignore" ]; # Filter function to include necessary files and directories # but exclude build artifacts postUnpack = '' # Remove build artifacts and temp directories from source find $sourceRoot -type d \( \ -name "_build" -o \ -name "deps" -o \ -name ".elixir_ls" -o \ -name ".elixir-tools" -o \ -name "node_modules" -o \ -name "cover" -o \ -name ".git" \ \) -exec rm -rf {} + 2>/dev/null || true # Remove dotfiles that shouldn't be in the build find $sourceRoot -maxdepth 1 -type f -name ".*" ! -name ".formatter.exs" ! -name ".credo.exs" -delete 2>/dev/null || true ''; # Mix environment mixEnv = "prod"; # Environment variables for build MIX_OS_DEPS_COMPILE_PARTITION_COUNT = "6"; # 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 ''; # Build assets after Mix compilation postBuild = '' # Build production assets (Tailwind + esbuild) mix assets.deploy ''; # Install MIB files to the release postInstall = '' # Copy MIB files directory if [ -d "$src/priv/mibs" ]; then mkdir -p $out/lib/towerops-${version}/priv/mibs cp -r $src/priv/mibs/* $out/lib/towerops-${version}/priv/mibs/ fi # Ensure NIF is in the release mkdir -p $out/lib/towerops-${version}/priv cp ${towerops-nif}/lib/towerops_nif.so $out/lib/towerops-${version}/priv/ ''; meta = { description = "Towerops - Phoenix LiveView SNMP monitoring platform"; license = lib.licenses.proprietary; platforms = lib.platforms.unix; }; }