From 361dd6dc67771e7098d4172ad7d78f2856e1791f Mon Sep 17 00:00:00 2001 From: uku Date: Wed, 5 Mar 2025 09:34:03 +0100 Subject: [PATCH] who needs temporary files and tee and whatever when you can have BASH SCRIPTS :3 --- configs/common.nix | 5 ----- flake.nix | 1 - justfile | 27 ++------------------------- switch.sh | 20 ++++++++++++++++++++ 4 files changed, 22 insertions(+), 31 deletions(-) create mode 100644 switch.sh diff --git a/configs/common.nix b/configs/common.nix index 98a898b..49fcc54 100644 --- a/configs/common.nix +++ b/configs/common.nix @@ -196,11 +196,6 @@ in }; }; - system.activationScripts."upgrade-diff" = { - supportsDryActivation = true; - text = "${lib.getExe pkgs.nvd} --nix-bin-dir=${config.nix.package}/bin diff /run/current-system $systemConfig 1>&2"; - }; - systemd = { services.NetworkManager-wait-online.enable = lib.mkForce false; diff --git a/flake.nix b/flake.nix index f1f80d6..61a7cfb 100644 --- a/flake.nix +++ b/flake.nix @@ -31,7 +31,6 @@ agenix.packages.${system}.default just nixfmt-rfc-style - nvd statix ]; }; diff --git a/justfile b/justfile index da5b398..442513e 100644 --- a/justfile +++ b/justfile @@ -5,17 +5,7 @@ check: nix flake check switch *args: - #!/usr/bin/env bash - set -euo pipefail - configuration=$(sudo nixos-rebuild dry-activate --flake . --keep-going {{args}}) - echo $configuration - read -n1 -p "Activate new configuration? [y/N] " answer - if [[ $answer =~ ^[Yy]$ ]]; then - sudo "$configuration/bin/switch-to-configuration" switch - else - echo "Not activating :(" - exit 1 - fi + bash switch.sh {{args}} rollback: sudo nixos-rebuild switch --rollback @@ -27,21 +17,8 @@ deploy system user="leo": #!/usr/bin/env bash set -euo pipefail flake=$(nix eval --impure --raw --expr "(builtins.getFlake \"git+file://$PWD\").outPath") - sshout=$(mktemp) - nix copy "$flake" --to "ssh://{{user}}@{{system}}" - ssh -t "{{user}}@{{system}}" "sudo nixos-rebuild dry-activate --flake $flake --keep-going" | tee "$sshout" - configuration=$(tail -n1 "$sshout" | grep -Po "/nix/store/[\w\d\.\-]+") - echo "$configuration" - rm "$sshout" - - read -n1 -p "Activate new configuration? [y/N] " answer - if [[ $answer =~ ^[Yy]$ ]]; then - ssh -t "{{user}}@{{system}}" "sudo \"$configuration/bin/switch-to-configuration\" switch" - else - echo "Not activating :(" - exit 1 - fi + ssh -t "{{user}}@{{system}}" "bash $flake/switch.sh" lint *args: statix check -i flake.nix **/hardware-configuration.nix {{args}} diff --git a/switch.sh b/switch.sh new file mode 100644 index 0000000..9ecfb17 --- /dev/null +++ b/switch.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -euo pipefail + +script_path=$(readlink -f "${BASH_SOURCE[0]}") +flake=$(dirname "$script_path") + +configuration=$(sudo nixos-rebuild dry-activate --flake "$flake" --keep-going "$@") +echo "$configuration" + +nix run --inputs-from "$flake" nixpkgs#nvd -- diff /run/current-system "$configuration" + +read -n1 -rp "Activate new configuration? [y/N] " answer +echo + +if [[ $answer =~ ^[Yy]$ ]]; then + sudo "$configuration/bin/switch-to-configuration" switch +else + echo "Not activating :(" + exit 1 +fi