Minor build improvements
Not sure if the features come from the new nixos-rebuild but good this simplifies things.
This commit is contained in:
parent
66885ab02e
commit
b170a1581d
3 changed files with 29 additions and 15 deletions
10
flake.lock
generated
10
flake.lock
generated
|
|
@ -784,15 +784,15 @@
|
|||
},
|
||||
"zelbarnixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1748415083,
|
||||
"narHash": "sha256-jmIRxOA7kj1CFNiP6S6pg6e6XeQi3whBVvWsATpEiC4=",
|
||||
"owner": "GeoffreyFrogeye",
|
||||
"lastModified": 1743964214,
|
||||
"narHash": "sha256-tPYh5TeRDOV9qMMr6VrgAOa5ZScqc4bohEDIU2grCnc=",
|
||||
"owner": "wlcx",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "bc0e8ee7d08241e8fbcb5e13a7abb445329e5644",
|
||||
"rev": "53524ff74074e3670c9a34729aa343dd461bfdb4",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "GeoffreyFrogeye",
|
||||
"owner": "wlcx",
|
||||
"ref": "zelbar",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@
|
|||
(pkgs.writeShellApplication {
|
||||
name = "rb";
|
||||
text = ''
|
||||
info() {
|
||||
echo -e '\033[1;34m'"$*"'\033[0m'
|
||||
}
|
||||
verb="switch"
|
||||
if [ "$#" -ge 1 ]
|
||||
then
|
||||
|
|
@ -14,7 +17,9 @@
|
|||
nixos_flake="$(readlink -f /etc/nixos)"
|
||||
if [ -f "$nixos_flake/flake.nix" ]
|
||||
then
|
||||
info "Updating local flakes"
|
||||
update-local-flakes "$nixos_flake"
|
||||
info "Starting script"
|
||||
nix run "$nixos_flake#nixosRebuild" -- "$verb" "$@"
|
||||
fi
|
||||
# TODO Fix nix-on-droid and home-manager
|
||||
|
|
|
|||
|
|
@ -24,18 +24,23 @@ then
|
|||
exit 2
|
||||
fi
|
||||
|
||||
nixosRebuild() {
|
||||
# sudo so the eval cache is shared with nixos-rebuild
|
||||
sudo nixos-rebuild --flake "$self#$HOSTNAME" "$@" --log-format internal-json |& nom --json
|
||||
}
|
||||
|
||||
info "Evaluating"
|
||||
# Evaluating can take a lot of memory, and Nix doesn't free it until the program ends,
|
||||
# which can be limiting on memory-constrained devices. Hence the build step is separate.
|
||||
# Drawback: it will query info about missing paths twice
|
||||
# nix eval doesn't use the eval cache, so we do a nix build --dry-run
|
||||
# sudo so the eval cache is shared with nixos-rebuild
|
||||
json=$(time sudo nix build "$self#nixosConfigurations.$HOSTNAME.config.system.build.toplevel" --dry-run --json )
|
||||
toplevel=$(echo "$json" | jq '.[0].outputs.out' -r)
|
||||
derivation=$(echo "$json" | jq '.[0].drvPath' -r)
|
||||
nixosRebuild dry-build
|
||||
|
||||
info "Building"
|
||||
sudo nom build "$derivation^*" --no-link "$@"
|
||||
tmpdir="$(mktemp --suffix -dry-build -d)"
|
||||
(cd "$tmpdir" && nixosRebuild build)
|
||||
toplevel="$(readlink -f "$tmpdir"/result)"
|
||||
rm "$tmpdir"/result
|
||||
rmdir "$tmpdir"
|
||||
|
||||
info "Showing diff"
|
||||
nvd diff "$(readlink -f /nix/var/nix/profiles/system)" "$toplevel"
|
||||
|
|
@ -59,9 +64,12 @@ then
|
|||
if [ -n "$specialisation" ]
|
||||
then
|
||||
specialisationArgs=("--specialisation" "$specialisation")
|
||||
echo "Currently running specialisation: $specialisation"
|
||||
else
|
||||
echo "Currently running unspecialized system"
|
||||
fi
|
||||
else
|
||||
warn "Could not find link for $currentSystem, will switch to non-specialized system"
|
||||
warn "Could not find link for $currentSystem, will switch to unspecialized system"
|
||||
fi
|
||||
|
||||
|
||||
|
|
@ -75,9 +83,10 @@ then
|
|||
fi
|
||||
if [ "$verb" = "test" ] || [ "$verb" = "switch" ] || [ "$confirm" = "y" ]
|
||||
then
|
||||
info "Applying"
|
||||
info "Installing passwords"
|
||||
"$toplevel/update-password-store"
|
||||
sudo nixos-rebuild --flake "$self#$HOSTNAME" test "${specialisationArgs[@]}" "$@"
|
||||
info "Applying"
|
||||
nixosRebuild test "${specialisationArgs[@]}" "$@"
|
||||
fi
|
||||
|
||||
# Set as boot
|
||||
|
|
@ -89,5 +98,5 @@ fi
|
|||
if [ "$verb" = "boot" ] || [ "$verb" = "switch" ] || [ "$confirm" = "y" ]
|
||||
then
|
||||
info "Setting as boot"
|
||||
sudo nixos-rebuild --flake "$self#$HOSTNAME" boot "$@"
|
||||
nixosRebuild boot "$@"
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue