Files
imphnen-frontend-service/nix/mkViteApp.nix
T
maulanasdqn 7d1370d7f2 fix(nix): run nx build in background to handle SIGABRT
Background process signal handling allows wait to catch SIGABRT
and || true to suppress the non-zero exit status.
2026-01-21 18:39:05 +07:00

48 lines
1.2 KiB
Nix

# Helper function to build Vite-based static apps
{ pkgs, src, npmDepsHash }:
{ name, buildScript, envVars ? {} }:
pkgs.buildNpmPackage {
pname = "imphnen-${name}";
version = "0.0.1";
inherit src npmDepsHash;
npmFlags = [ "--legacy-peer-deps" ];
makeCacheWritable = true;
nativeBuildInputs = with pkgs; [
nodejs_22
nodePackages.npm
];
buildPhase = ''
runHook preBuild
export NX_DAEMON=false
export HOME=$TMPDIR
export CI=true
export NO_COLOR=1
export TERM=dumb
export NX_SKIP_NX_CACHE=true
export NX_TASKS_RUNNER_DYNAMIC_OUTPUT=false
export NX_NATIVE=false
${pkgs.lib.concatStringsSep "\n" (pkgs.lib.mapAttrsToList (k: v: "export ${k}=\"${v}\"") envVars)}
# Run nx build, ignore terminal crash after successful build
# Run in background and wait to handle SIGABRT from Nx terminal crash
./node_modules/.bin/nx build ${name} --output-style=static &
wait $! || true
# Verify the build output exists
test -d dist/apps/${name}
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r dist/apps/${name}/* $out/
runHook postInstall
'';
dontNpmBuild = true;
}