summary refs log tree commit diff
path: root/build.sh
diff options
context:
space:
mode:
Diffstat (limited to 'build.sh')
-rwxr-xr-xbuild.sh27
1 files changed, 17 insertions, 10 deletions
diff --git a/build.sh b/build.sh
index 27d0e11..a5abb3c 100755
--- a/build.sh
+++ b/build.sh
@@ -7,21 +7,28 @@ if [ $# -ne 2 ]; then
     cat flake.nix | grep '.lib.nixosSystem' | sed 's/ =.*//' | sed 's/^[ \t]*//;s/[ \t]*$//' | while read cfg; do echo " - $cfg"; done
     exit 1
 fi
-if [ "$1" = "/" ]; then
-    [ -f "host/${2}/pre-rebuild.sh" ] && host/$2/pre-rebuild.sh
-    nixos-generate-config --show-hardware-config > hardware-configuration.nix
+
+ROOT=$1
+CONFIG=$2
+
+DERIVATION=".#nixosConfigurations.${CONFIG}.config.system.build.toplevel"
+EXTRA_NIX_FLAGS="-L --accept-flake-config"
+
+if [ "${ROOT}" = "/" ]; then
+    [ -f "host/${CONFIG}/hooks/pre-rebuild.sh" ] && host/${CONFIG}/hooks/pre-rebuild.sh
+    [ ! -f "hardware-configuration.nix" ] && nixos-generate-config --show-hardware-config > hardware-configuration.nix
     git add -f hardware-configuration.nix
-    nom build .#nixosConfigurations.${2}.config.system.build.toplevel && sudo nixos-rebuild switch --flake .#${HOSTNAME} || exit 1
-    nixos-rebuild switch --flake ".#${2}" -j`nproc` --upgrade-all -L || exit 1
-    [ -f "host/${2}/post-rebuild.sh" ] && host/$2/post-rebuild.sh
+    nom build $DERIVATION $EXTRA_NIX_FLAGS && sudo nixos-rebuild switch --flake .#${CONFIG} --upgrade-all $EXTRA_NIX_FLAGS || exit 1
+    #nixos-rebuild switch --flake ".#${CONFIG}" -j`nproc` --upgrade-all -L || exit 1
+    [ -f "host/${CONFIG}/hooks/post-rebuild.sh" ] && host/${CONFIG}/hooks/post-rebuild.sh
     git rm --cached hardware-configuration.nix
     exit
 else
-    nixos-generate-config --show-hardware-config --root "${1}" > hardware-configuration.nix
+    nixos-generate-config --show-hardware-config --root "${ROOT}" > hardware-configuration.nix
     git add -f hardware-configuration.nix
-    nom build .#nixosConfigurations.${2}.config.system.build.toplevel || exit 1
-    nixos-install --root "${1}" --flake ".#${2}" 
+    nom build $DERIVATION $EXTRA_NIX_FLAGS || exit 1
+    nixos-install --root "${ROOT}" --flake ".#${CONFIG}" --no-channel-copy
     git rm --cached hardware-configuration.nix
-    cp . "${1}/Rory-Open-Architecture" -r
+    cp . "${ROOT}/Rory-Open-Architecture" -r
     exit
 fi