From 8f425987f93cddb2aad21524bc52f7d6df29a07c Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 23 Nov 2026 22:57:11 +0000 Subject: krops.nix: add switch argument --- krops.nix | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/krops.nix b/krops.nix index 6f7858db..5a8925cd 100644 --- a/krops.nix +++ b/krops.nix @@ -9,11 +9,22 @@ # diff build the system on the target and show what switching to it # would change # +# ARGUMENTS +# name the host to deploy +# target where to deploy it, instead of spec.nix's target +# switch what switch-to-configuration does: switch (the default), boot, +# or test (no new generation) +# { lib ? import ~/sync/src/krops/lib , pkgs ? import ~/sync/src/krops/pkgs {} , name , target ? null -}@args: rec { +, switch ? "switch" +}@args: + +assert builtins.elem switch [ "switch" "boot" "test" ]; + +rec { spec = { nixpkgs = "nixos-26.05"; @@ -82,16 +93,24 @@ }} ) ${builtins.getAttr deploy-action { - deploy = /* sh */ '' - old_gen=$(readlink -f /nix/var/nix/profiles/system) - new_gen=$(readlink -f "$system") - if [ "x$old_gen" != "x$new_gen" ]; then - nix-env -p /nix/var/nix/profiles/system --set "$system" - "$system"/bin/switch-to-configuration switch - else - echo 'Configuration is already up to date' >&2 - fi - ''; + deploy = let + setAndSwitch = /* sh */ '' + old_gen=$(readlink -f /nix/var/nix/profiles/system) + new_gen=$(readlink -f "$system") + if [ "x$old_gen" != "x$new_gen" ]; then + nix-env -p /nix/var/nix/profiles/system --set "$system" + "$system"/bin/switch-to-configuration ${switch} + else + echo 'Configuration is already up to date' >&2 + fi + ''; + in builtins.getAttr switch { + switch = setAndSwitch; + boot = setAndSwitch; + test = /* sh */ '' + "$system"/bin/switch-to-configuration test + ''; + }; diff = /* sh */ '' nix --extra-experimental-features nix-command \ store diff-closures /run/current-system "$system" -- cgit v1.3.1