Skip to content

Commit

Permalink
add script to update Nix release branches
Browse files Browse the repository at this point in the history
  • Loading branch information
fricklerhandwerk committed Mar 15, 2024
1 parent 926f8fa commit 1e1a1c9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ let
python ${pkgs.writeText "live.py" script}
'';
};
update-nix-releases = pkgs.callPackage ./nix/update-nix-releases.nix { };
in
{
# build with `nix-build -A build`
Expand All @@ -149,6 +150,7 @@ in
inputsFrom = [ nix-dev ];
packages = [
devmode
update-nix-releases
pkgs.niv
pkgs.python310.pkgs.black
pkgs.vale
Expand Down
39 changes: 39 additions & 0 deletions nix/update-nix-releases.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{ writeShellApplication
, git
, gnused
, niv
, nix
, ripgrep
, coreutils
}:
# add or update Nix releases using `niv` in the current directory.
# this will clone the entire Git repository of Nix.
writeShellApplication {
name = "update-nix-releases";
runtimeInputs = [ git gnused niv nix ripgrep ];
text = ''
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
git clone https://github.com/nixos/nix "$tmp"
pushd "$tmp" > /dev/null
git branch -r | rg 'origin/\d\.\d*-maintenance' | sed 's|.*origin/\(.*\)|\1|' > releases.txt
while IFS= read -r release; do
git checkout "$release"
# very old versions don't have a `default.nix`
if [ ! -f default.nix ]; then continue; fi
doc=$(nix-store --query "$(nix-instantiate -A default)" | rg doc)
# only use cached builds, to avoid building Nix locally
if nix-store --query --size "$doc" --store https://cache.nixos.org > /dev/null 2>&1; then
popd > /dev/null
if niv show "$release" > /dev/null 2>&1; then
niv drop "nix_''${release%-maintenance}"
fi
niv add nixos/nix -n "nix_''${release%-maintenance}" -b "$release"
pushd "$tmp" > /dev/null
fi
done < releases.txt
'';
}

0 comments on commit 1e1a1c9

Please sign in to comment.