ctucx.git: nixfiles

ctucx' nixfiles

commit 51aebfb2c5baa0a4edc8e273d1cc17afacb2ad83
parent 0477f9e0871e3f0045ece9d74302c340ad13e285
Author: Leah (ctucx) <leah@ctu.cx>
Date: Thu, 3 Feb 2022 14:15:38 +0100

nixos-deploy: add deployment-helper script
1 file changed, 27 insertions(+), 0 deletions(-)
A
nixos-deploy
|
27
+++++++++++++++++++++++++++
diff --git a/nixos-deploy b/nixos-deploy
@@ -0,0 +1,27 @@
+ #!/usr/bin/env bash
+set -eo pipefail
+cd "$(dirname "$0")"
+
+machine="${1:-lollo}"
+target="${2:-root@$machine.ctu.cx}"
+mode="${3:-switch}"
+
+if ! [ -d "machines/$machine" ]
+then
+	echo "Machine '$machine' does not exist. Choose from:"
+	ls machines
+	exit
+fi
+
+echo "deploying $machine to $target"
+sleep 1
+
+set -x
+system_drv=$(
+  nix-instantiate "<nixpkgs/nixos>" -A config.system.build.toplevel \
+    -I "$(nix-build nix/sources-dir.nix --no-out-link)" \
+    -I "nixos-config=machines/$machine/configuration.nix"
+)
+nix-copy-closure --to $target $system_drv
+system=$(ssh $target "nix-store --realise $system_drv")
+ssh $target "sudo nix-env -p /nix/var/nix/profiles/system -i $system && sudo /nix/var/nix/profiles/system/bin/switch-to-configuration $mode"