towerops/nix/build.nix
Graham McIntire 44b5c204fa
fix: Use lib.licenses.unfree instead of proprietary
Change license from 'proprietary' (which doesn't exist in nixpkgs)
to 'unfree' which is the correct license type for closed-source
software in Nix.
2026-02-07 12:44:28 -06:00

103 lines
2.5 KiB
Nix

{
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 = ''
# Find the release directory (mixRelease creates lib/<name>-<version>)
RELEASE_DIR=$(find $out/lib -maxdepth 1 -type d -name "towerops-*" | head -1)
if [ -n "$RELEASE_DIR" ]; then
# Copy MIB files directory
if [ -d "$src/priv/mibs" ]; then
mkdir -p $RELEASE_DIR/priv/mibs
cp -r $src/priv/mibs/* $RELEASE_DIR/priv/mibs/
fi
# Ensure NIF is in the release
mkdir -p $RELEASE_DIR/priv
cp ${towerops-nif}/lib/towerops_nif.so $RELEASE_DIR/priv/
fi
'';
meta = {
description = "Towerops - Phoenix LiveView SNMP monitoring platform";
license = lib.licenses.unfree;
platforms = lib.platforms.unix;
};
}