From 216805a80d226d6182c8a0a19a07dfd973f22400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20R=C3=B6ger?= Date: Sat, 15 Mar 2025 19:31:07 +0100 Subject: [PATCH] System Gen151 @ 2025-03-15-19:31:07 --- modules/bin/nix-scripts.nix | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/modules/bin/nix-scripts.nix b/modules/bin/nix-scripts.nix index 41f6273..67a830b 100644 --- a/modules/bin/nix-scripts.nix +++ b/modules/bin/nix-scripts.nix @@ -38,12 +38,23 @@ echo ".nixos is unclean!" exit 1 fi + branch_staging="staging-update" + + if ${pkgs.git}/bin/git rev-parse --verify "$branch_staging" >/dev/null 2>&1; then + echo "Using staging update branch." + else + echo "No staging update branch found." + exit 1 + fi + + ${pkgs.git}/bin/git checkout "$branch_staging" flake.lock echo "Updating nix-flake..." nix flake update --flake . echo "NixOS Rebuilding..." ${pkgs.nh}/bin/nh os switch ~/.nixos gen=$(sudo nix-env --list-generations --profile /nix/var/nix/profiles/system | ${pkgs.gnugrep}/bin/grep current | ${pkgs.gawk}/bin/awk '{print "Gen" $1 " @ " $2 "-" $3}') ${pkgs.git}/bin/git commit --no-gpg-sign -am "Upgrade $gen" + ${pkgs.git}/bin/git branch -D "$branch_staging" popd ''; update = @@ -55,15 +66,28 @@ echo ".nixos is unclean!" exit 1 fi - echo "Updating nix-flake..." - nix flake update --flake . - echo "NixOS Building..." - ${pkgs.nh}/bin/nh os build ~/.nixos + branch_staging="staging-update" + branch_current="$(${pkgs.git}/bin/git branch --show-current)" + + if ${pkgs.git}/bin/git rev-parse --verify "$branch_staging" >/dev/null 2>&1; then + echo "There is already a staging update branch." + else + echo "Creating a new staging update branch." + ${pkgs.git}/bin/git switch -c "$branch_staging" + nix flake update --verbose --flake . + ${pkgs.git}/bin/git add flake.lock + ${pkgs.git}/bin/git commit --no-gpg-sign -m "staging update" + ${pkgs.git}/bin/git switch "$branch_current" + fi + + nix store diff-closures \ + '.?ref='"$branch_current"'#nixosConfigurations.'"$(${pkgs.hostname}/bin/hostname)"'.config.system.build.toplevel' \ + '.?ref='"$branch_staging"'#nixosConfigurations.'"$(${pkgs.hostname}/bin/hostname)"'.config.system.build.toplevel' + popd ''; in { environment.systemPackages = [ - pkgs.bash home-rebuild rebuild upgrade