update-flake.sh: add workflow for updating the NixOS version

This commit is contained in:
Erik Arvstedt 2024-12-13 23:21:22 +01:00
parent f60a50607d
commit ba46d20a25
No known key found for this signature in database
GPG key ID: 33312B944DD97846
2 changed files with 12 additions and 7 deletions

View file

@ -97,8 +97,7 @@ It's easiest to use an existing service as a template:
Most other services use packages that are already included in nixpkgs.
## Switching to a new NixOS release
- [flake.nix](../flake.nix): update `nixpkgs.url`
- Run command `update-flake.sh 24.11`
- [cirrus.yml](../.cirrus.yml): update toplevel container -> image attribute
- [examples/configuration.nix](../examples/configuration.nix): update `system.stateVersion`
- [examples/flakes/flake.nix](../examples/flakes/flake.nix): update `inputs.nix-bitcoin.url`

View file

@ -2,7 +2,9 @@
set -euo pipefail
# This script does the following:
# - Update all flake inputs, including nixpkgs
# - When called without arguments, update all flake inputs, including nixpkgs.
# - When called with a version argument, set input `nixpkgs` in `flake.nix` to the
# specified version and only update this input.
# - Print version updates of pinned pkgs like so:
# Pkg updates in nixpkgs unstable:
# bitcoin: 0.20.0 -> 0.21.1
@ -39,9 +41,11 @@ if [[ $forceRun ]] && ! git diff --quiet ../flake.{nix,lock}; then
exit 1
fi
echo "Updating flake 'nixos-search'"
nix flake update --flake ../test/nixos-search
echo
if [[ ! $nixosVersion ]]; then
echo "Updating flake 'nixos-search'"
nix flake update --flake ../test/nixos-search
echo
fi
versions=$(nix eval --json -f update-flake.nix versions)
@ -51,8 +55,10 @@ versions=$(nix eval --json -f update-flake.nix versions)
echo "Updating main flake"
if [[ $nixosVersion ]]; then
sed -Ei "s|(nixpkgs.url = .*nixos-)[^\"]+|\1$nixosVersion|" ../flake.nix
nix flake update nixpkgs --flake ..
else
nix flake update --flake ..
fi
nix flake update --flake ..
echo
nix eval --raw -f update-flake.nix --argstr prevVersions "$versions" showUpdates; echo