From 0a071aed3d431744d38b4611e3f2b877e085f1ee Mon Sep 17 00:00:00 2001 From: Mohammad Rafiq Date: Tue, 20 May 2025 18:31:18 +0800 Subject: [PATCH] feat(packages/rebuild): improve rebuild script --- .gitignore | 2 ++ packages/rebuild/default.nix | 33 ++++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..87a3018 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +result +*.qcow2 diff --git a/packages/rebuild/default.nix b/packages/rebuild/default.nix index ac5730b..a5bee2d 100644 --- a/packages/rebuild/default.nix +++ b/packages/rebuild/default.nix @@ -2,13 +2,32 @@ pkgs.writeShellScriptBin "rebuild" # sh '' if [ ! -f "flake.nix" ]; then - echo "flake.nix not found in current directory. exiting..." - exit 1 + echo "Error: flake.nix not found in the current directory. Exiting." + exit 1 # Indicate an error fi - git add . && \ - nixos-rebuild switch --flake . --use-remote-sudo && \ - ${pkgs.cowsay}/bin/cowsay -f elephant "Opening a test shell. Type exit 1 to abort and exit to commit your changes." && \ - $SHELL && \ - git commit -a + echo "--- building the new config... ---" + git add . + nixos-rebuild test --flake . --use-remote-sudo || { + echo "Error: nixos-rebuild switch failed. Check the output for details." + exit 1 + } + + echo "--- diffing... ---" + git diff HEAD --color=always --stat --patch + + echo "--- opening test shell... ---" + ${pkgs.cowsay}/bin/cowsay -f elephant "Entering a test shell. Type 'exit 1' to abort changes and 'exit' to commit." + PS1="Test shell> " $SHELL || { + ${pkgs.cowsay}/bin/cowsay -f satanic "You aborted." + exit 1 + } + + echo "--- adding the built configuration to the bootloader... ---" + nixos-rebuild switch --flake . --use-remote-sudo || { + echo "Error: nixos-rebuild switch failed. Check the output for details." + exit 1 + } + git commit + exit 0 ''