1#!/usr/bin/env nix-shell
2#!nix-shell -i bash -p bash nix-update jq
3
4set -xeuo pipefail
5
6SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
7NIXPKGS_DIR=$(readlink -f "$SCRIPT_DIR/../../../..")
8cd "$NIXPKGS_DIR"
9
10nix_versions=$(nix eval --impure --json --expr "with import ./. { config.allowAliases = false; }; builtins.filter (name: builtins.match \"nix_.*\" name != null) (builtins.attrNames nixVersions)" | jq -r '.[]')
11
12for name in $nix_versions; do
13 minor_version=${name#nix_*_}
14 if [[ "$name" = "nix_2_3" ]]; then # not maintained by the nix team
15 continue
16 fi
17
18 nix-update --override-filename "$SCRIPT_DIR/default.nix" --version-regex "(2\\.${minor_version}\..+)" --build --commit "nixVersions.$name"
19done
20
21stable_version_full=$(nix eval --impure --json --expr "with import ./. { config.allowAliases = false; }; nixVersions.stable.version" | jq -r)
22
23# strip patch version
24stable_version_trimmed=${stable_version_full%.*}
25
26for name in $nix_versions; do
27 minor_version=${name#nix_*_}
28 if [[ "$name" = "nix_2_3" ]]; then # not maintained by the nix team
29 continue
30 fi
31 if [[ "$name" = "nix_${stable_version_trimmed//./_}" ]]; then
32 curl https://releases.nixos.org/nix/nix-$stable_version_full/fallback-paths.nix > "$NIXPKGS_DIR/nixos/modules/installer/tools/nix-fallback-paths.nix"
33 # nix-update will commit the file if it has changed
34 git add "$NIXPKGS_DIR/nixos/modules/installer/tools/nix-fallback-paths.nix"
35 git commit -m "nix: update nix-fallback-paths to $stable_version_full"
36 break
37 fi
38done
39
40commit_json=$(curl -s https://api.github.com/repos/NixOS/nix/commits/master) # format: 2024-11-01T10:18:53Z
41date_of_commit=$(echo "$commit_json" | jq -r '.commit.author.date')
42suffix="pre$(date -d "$date_of_commit" +%Y%m%d)_"
43sed -i -e "s|\"pre[0-9]\{8\}_|\"$suffix|g" "$SCRIPT_DIR/default.nix"
44nix-update --override-filename "$SCRIPT_DIR/default.nix" --version branch --build --commit "nixVersions.git"