1
0
Fork 0
mirror of https://github.com/NixOS/nix.dev.git synced 2024-10-18 14:32:43 -04:00
nix.dev/nix/update-nixpkgs-releases.nix
Valentin Gagarin a3b5aad725 add a script to update Nixpkgs releases
this will accumulate releases over time. it's not great, but this is the
price of persistent URLs. otherwise, when people link to supposedly stable
URLs, and we garbage-collect old manuals, those links will rot away.

it's also slightly simpler algorithmically, and therefore easier to
reason about.

this can be incrementally improved in the future, by automatically
adding redirects to e.g. the closest following release for which the
manual is still served. for example, if we currently serve

    23.11
    23.05
    22.11
    22.05

but in the future decide to cut that list to the first two, the script
would drop the excess pins and add redirects like these:

    /manual/nixpkgs/22.05/* /manual/nixpkgs/23.05/:splat 301
    /manual/nixpkgs/22.11/* /manual/nixpkgs/23.05/:splat 301

the condition for that would be that we are reasonably sure that the
manuals will manage their own internal redirects as pages and anchors
move around between releases.
2024-04-03 09:21:26 +02:00

52 lines
1.3 KiB
Nix

{ writeShellApplication
, git
, gnused
, niv
, nix
, ripgrep
, coreutils
}:
# add or update Nixpkgs releases using `niv` in the current directory.
writeShellApplication {
name = "update-nixpkgs-releases";
runtimeInputs = [ git gnused niv nix ripgrep ];
text = ''
tmp=$(mktemp -d)
nixpkgs=$(mktemp -d)
trap 'rm -rf $"tmp" "$nixpkgs"' EXIT
# get release branches
git ls-remote https://github.com/nixos/nixpkgs "refs/heads/*" \
| rg '/nixos-\d\d\.\d\d$' | awk '{sub(/\s*refs\/heads\//, "", $2); print $2, $1}' \
| sort --reverse --version-sort > "$tmp"/releases
niv show | awk '
!/^[[:space:]]/ && $1 ~ /^nixpkgs_/ {
pin = $1
}
/branch:/ {
branch = $2
}
/rev:/ {
print branch, $2, pin
}
' > "$tmp"/pinned
# nixpkgs-unstable moves fast enough to always need updates
niv update nixpkgs-rolling -b nixpkgs-unstable
# only update releases where pins don't match the latest revision
rg --invert-match --file <(awk '{print $1, $2}' "$tmp"/pinned) "$tmp"/releases | cut -d' ' -f1 | while read -r branch; do
version="''${branch/nixos-/}"
version="''${version//./-}"
pin=nixpkgs_"$version"
if rg -q "$pin" "$tmp"/pinned; then
niv update "$pin"
else
niv add nixos/nixpkgs -n "$pin" -b "$branch"
fi
done
'';
}