docs/nix-compile.example (790 bytes)
1 #!/bin/sh 2 # Rebuild the Nix profiles; collect garbage at start, after each build and on exit. 3 # Edit the paths and attributes for your sys.nix. Run as root. 4 set -u 5 cd "$(dirname "$0")" || exit 1 6 mkdir -p compile-logs 7 LOG=compile-logs/compile-log-$(date +%Y%m%d-%H%M%S).txt 8 9 # the store needs room for build inputs: drop old generations, then collect garbage 10 gc_cleanup() { 11 echo "== gc_cleanup ($1)"; df -h /nix | tail -1 12 nix-collect-garbage -d >/dev/null 2>&1 13 df -h /nix | tail -1 14 } 15 16 build() { NIXPKGS_ALLOW_UNFREE=1 nix-build sys.nix -A "$1" -o "$2"; } 17 18 main() { 19 trap 'gc_cleanup exit' EXIT 20 rc=0 21 gc_cleanup start 22 build user /usr/local/nix-user || rc=1 23 gc_cleanup after-user 24 build system /usr/local/nix-system || rc=1 25 echo "== done rc=$rc" 26 return $rc 27 } 28 main 2>&1 | tee -a "$LOG"