Remove buggy conditional that was always true. Now the filter correctly excludes only build artifacts while including all source files including vendor directory.
107 lines
2.9 KiB
Nix
107 lines
2.9 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.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";
|
|
};
|
|
|
|
# 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;
|
|
};
|
|
}
|