New rebuild mechanism
Put most of it as a flake app, so we can mess with it without relying on `rb` being rebuilt. Also nom nom!
This commit is contained in:
parent
7b9d9053bf
commit
17f0ba3370
8 changed files with 115 additions and 85 deletions
|
@ -9,7 +9,6 @@
|
|||
./common.nix
|
||||
./desktop
|
||||
./dev
|
||||
./diff
|
||||
disko.nixosModules.disko
|
||||
./gaming
|
||||
./geoffrey.nix
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
{ pkgs, lib, config, ... }:
|
||||
{
|
||||
config = {
|
||||
system.activationScripts.diff = {
|
||||
supportsDryActivation = true;
|
||||
text = ''
|
||||
if [ -h /run/current-system ]
|
||||
then
|
||||
${pkgs.nvd}/bin/nvd --nix-bin-dir=${pkgs.nix}/bin diff /run/current-system "$systemConfig"
|
||||
fi
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
54
os/rebuild.sh
Normal file
54
os/rebuild.sh
Normal file
|
@ -0,0 +1,54 @@
|
|||
# Handle arguments
|
||||
self="$1"
|
||||
verb="$2"
|
||||
shift
|
||||
shift
|
||||
|
||||
if [ "$verb" != "build" ] && [ "$verb" != "test" ] && [ "$verb" != "boot" ] && [ "$verb" != "switch" ] && [ "$verb" != "confirm" ]
|
||||
then
|
||||
echo "Action should be one of: build, test, boot, switch, confirm"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Build, looking nice
|
||||
tmpdir="$(mktemp -d)"
|
||||
# sudo so the eval cache is shared with nixos-rebuild
|
||||
sudo nom build "$self#nixosConfigurations.$HOSTNAME.config.system.build.toplevel" -o "$tmpdir/toplevel" "$@"
|
||||
toplevel="$(readlink "$tmpdir/toplevel")"
|
||||
rm -rf "$tmpdir"
|
||||
|
||||
# Show diff
|
||||
nvd diff /nix/var/nix/profiles/system "$toplevel"
|
||||
|
||||
# Figure out specialisation
|
||||
specialisationArgs=""
|
||||
currentSystem="$(readlink /run/current-system)"
|
||||
while read -r specialisation
|
||||
do
|
||||
if [ "$(readlink "/nix/var/nix/profiles/system/specialisation/$specialisation")" = "$currentSystem" ]
|
||||
then
|
||||
specialisationArgs=("--specialisation" "$specialisation")
|
||||
fi
|
||||
done <<< "$(ls /nix/var/nix/profiles/system/specialisation)"
|
||||
|
||||
# Apply
|
||||
if [ "$verb" = "confirm" ]
|
||||
then
|
||||
echo "Apply configuration? [y/N]"
|
||||
read -r confirm
|
||||
fi
|
||||
if [ "$verb" = "test" ] || [ "$verb" = "switch" ] || [ "$confirm" = "y" ]
|
||||
then
|
||||
sudo nixos-rebuild --flake "$self#$HOSTNAME" test "${specialisationArgs[@]}" "$@"
|
||||
fi
|
||||
|
||||
# Set as boot
|
||||
if [ "$verb" = "confirm" ]
|
||||
then
|
||||
echo "Set configuration as boot? [y/N]"
|
||||
read -r confirm
|
||||
fi
|
||||
if [ "$verb" = "boot" ] || [ "$verb" = "switch" ] || [ "$confirm" = "y" ]
|
||||
then
|
||||
sudo nixos-rebuild --flake "$self#$HOSTNAME" boot "$@"
|
||||
fi
|
Loading…
Add table
Add a link
Reference in a new issue