summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlassulus <git@lassul.us>2023-09-03 12:35:59 +0200
committerlassulus <git@lassul.us>2023-09-03 12:35:59 +0200
commit2ff66b82275fa09f6b8caf0074d1b779a24f29a3 (patch)
tree650c66a26460f88952c5760496c2840942901423
parent2c0e580ba1c1cd28a135639bd8e17df14399db5c (diff)
l krops: add more functions & params
-rw-r--r--lass/krops.nix53
1 files changed, 51 insertions, 2 deletions
diff --git a/lass/krops.nix b/lass/krops.nix
index a7dcaf5bf..407df3bc6 100644
--- a/lass/krops.nix
+++ b/lass/krops.nix
@@ -54,7 +54,7 @@
in {
- deploy = { target ? "root@${name}/var/src", offline ? false }: pkgs.krops.writeCommand "deploy" {
+ deploy = { target ? "root@${name}/var/src", offline ? false, command ? "switch" }: pkgs.krops.writeCommand "deploy" {
command = targetPath: ''
set -xfu
@@ -73,10 +73,21 @@ in {
nix-env -p /nix/var/nix/profiles/system --set "$outDir/out"
- "$outDir/out/bin/switch-to-configuration" switch
+ "$outDir/out/bin/switch-to-configuration" ${command}
'';
source = source { test = false; };
allocateTTY = true;
+ backup = false;
+ inherit target;
+ };
+
+ deployWithFlake = { target ? "root@${name}/var/src", offline ? false }: pkgs.krops.writeCommand "deploy" {
+ source = {
+ inherit (source { test = false; }) stockholm secrets;
+ };
+ command = targetPath: ''
+ '';
+ allocateTTY = true;
inherit target;
};
@@ -93,4 +104,42 @@ in {
inherit target;
source = source { test = true; };
};
+
+ deploy-with-diff = { target ? "root@${name}/var/src" }: pkgs.krops.writeCommand "${name}-deploy" {
+ command = targetPath: ''
+ set -xu
+ deployScript=$(mktemp)
+ cat << EOF > "$deployScript"
+ #! /usr/bin/env nix-shell
+ #! nix-shell -p nix-diff proot rsync -i bash
+ set -xfu
+
+ oldPath=\$(echo "${targetPath}" | sed 's/-new$//')
+ oldSystemDrv=\$(nix show-derivation /run/current-system | jq -r 'keys[0]')
+ newSystemDrv=\$(proot -b /var/src-new:/var/src nix-instantiate -I /var/src '<nixpkgs/nixos>' -A config.system.build.toplevel)
+
+ (
+ diff -rq -x '.git' "\$oldPath" "${targetPath}"
+ nix-diff --color always --line-oriented "\$oldSystemDrv" "\$newSystemDrv"
+ ) | less -R
+ echo 'continue? [(Y)es]/(n)o'
+ read yn
+ case \$yn in
+ [Nn]* ) exit;;
+ esac
+ rsync -ra --delete /var/src-new/ /var/src/
+ nixos-rebuild -I /var/src switch
+ EOF
+
+ chmod +x "$deployScript"
+ echo "$deployScript"
+ cat "$deployScript"
+ exec "$deployScript"
+ rm "$deployScript"
+ '';
+ target = "${target}-new";
+ source = source { test = false; };
+ force = true;
+ allocateTTY = true;
+ };
}