1 files changed, 22 insertions, 0 deletions
diff --git a/prebuild.sh b/prebuild.sh
new file mode 100755
index 0000000..74357cf
--- /dev/null
+++ b/prebuild.sh
@@ -0,0 +1,22 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash -p git nixos-install-tools
+if [ $# -ne 1 ]; then
+ echo "Usage: $0 <config>"
+ echo "NOTE: hardware config will be generated from root!"
+ echo "Defined configs:"
+ cat flake.nix | grep '.lib.nixosSystem' | sed 's/ =.*//' | sed 's/^[ \t]*//;s/[ \t]*$//' | while read cfg; do echo " - $cfg"; done
+ exit 1
+fi
+
+CONFIG=$1
+
+DERIVATION=".#nixosConfigurations.${CONFIG}.config.system.build.toplevel"
+EXTRA_NIX_FLAGS="-vL --accept-flake-config --keep-going --show-trace --option allow-import-from-derivation false"
+EXTRA_NIXOS_REBUILD_FLAGS="--sudo --no-reexec --offline" # legacy: --use-remote-sudo --fast
+
+[ -f "host/${CONFIG}/hooks/pre-rebuild.sh" ] && echo "<=== RUNNING PRE-REBUILD HOOK AT host/${CONFIG}/hooks/pre-rebuild.sh ===>" && host/${CONFIG}/hooks/pre-rebuild.sh
+[ ! -f "hardware-configuration.nix" ] && echo "<=== GENERATING NEW HARDWARE CONFIG ===>" && nixos-generate-config --show-hardware-config > hardware-configuration.nix
+git add -f hardware-configuration.nix
+echo "<=== REBUILDING NIXOS CONFIGURATION FOR ${CONFIG} ===>"
+nom build $DERIVATION $EXTRA_NIX_FLAGS && echo "<=== SWITCHING TO NEW CONFIGURATION ===>"
+git rm --cached hardware-configuration.nix
|