Skip to content

pins: fall back to fetchTarball/fetchGit on Nix 2.3 - #19

Merged
jonringer merged 1 commit into
masterfrom
jonringer/nix-2-3-pins
Nov 13, 2026
Merged

jonringer merged 1 commit into
masterfrom
jonringer/nix-2-3-pins

Conversation

@jonringer

@jonringer jonringer commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The roadmap says every repository should be Nix 2.3 compatible, but pins.nix calls builtins.fetchTree, which Nix 2.3 doesn't have. Importing default.nix with Nix 2.3 therefore fails immediately with attribute 'fetchTree' missing.

Approach

This adds fetch-locked.nix, a ~45-line helper. The same file is vendored byte-for-byte in all four repos (corepkgs, ekapkgs, python-packages, vim-plugins), and each repo's pins.nix becomes one fetchLocked "<input>" line per pin:

  • It reads flake.lock, so that file stays the single source of truth and nix flake update / nix flake lock keep driving the non-flake pins. It looks up a root input by name and follows follows paths such as nix-lib = ["corepkgs" "nix-lib"], so it doesn't depend on the lock's internal node names (foo_2, ...).
  • Nix >= 2.4: it calls builtins.fetchTree locked, the same as before (this is also what nix flake does).
  • Nix 2.3:
    • github inputs go through builtins.fetchTarball { url = "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"; sha256 = locked.narHash; }.
    • git inputs go through builtins.fetchGit { url; rev; ref?; }. Nix 2.3 rejects allRefs and submodules ("unsupported argument"), so they aren't passed, and a submodules = true input throws a clear error. Note that 2.3's fetchGit does not check narHash.
    • Any other type throws a clear error.
    • The result is { outPath; rev; narHash; }, so import pins.x, pins.x + "/file" and .outPath keep working.
  • Both paths produce the same fixed-output store path (name source plus the locked narHash).

All flake.lock entries in the four repos are github. The git path was tested against a synthetic lock entry. A ref is needed on 2.3 for a rev that isn't on the default branch, and 2.3 accepts ref = "refs/heads/<branch>".

Verification

All of this ran on Nix 2.34.8 unless noted otherwise.

drvPaths before vs after vs forced fallback. I evaluated (import ./default.nix {}).<attr>.drvPath on origin/master, on this branch, and on a copy of this branch whose pins.nix passes fetchers = removeAttrs builtins [ "fetchTree" ] to force the Nix 2.3 code path. All three are identical:

attr drvPath (identical in all three)
python3Packages.requests /nix/store/7p2fff2gns5k4ifjfrb2vs3an3rrf86f-python3.13-requests-2.34.2.drv
python3Packages.numpy /nix/store/81nx0i56smp6n1pmrvfhnrvkhx7q2fiq-python3.13-numpy-2.5.4.drv
openssl /nix/store/7dk1flqpq2qsl525qzxwk5bziqz25jj1-openssl-3.6.3.drv

Each pin's outPath is also identical between the fetchTree path and the fallback path. The flake output can't be compared here because it fails to evaluate on origin/master too (see below).

Real Nix 2.3.16 (nixVersions.nix_2_3 from nixos-23.05, run against the local daemon):

  • builtins ? fetchTree is false, and import ./pins.nix now evaluates. For every pin, the store path is the one fetchTree gives on 2.34 (e.g. nix-lib a52fa86 -> /nix/store/dj7zb40ak0l9f4510gggycs04wv4laii-source).
  • SRI hashes work in 2.3's fetchTarball. A corrupted sha256-... value is rejected with hash mismatch ... wanted: sha256:1a8fng...0000 got: sha256:1a8fng...kwjj2, so the hash is parsed and checked, not ignored.
  • fetchGit on 2.3: the default-branch rev with no ref, a non-default-branch rev with ref, and the forced-fallback path on 2.34 all give the same store path as fetchTree on 2.34.

Caveat: the full package set does not evaluate on Nix 2.3 yet. This PR only fixes the pinning layer. With these changes, Nix 2.3 gets past pins.nix and then fails on newer syntax elsewhere in corepkgs. The first failure is path interpolation (./${majorVersion}/... in pkgs/gcc/patches/default.nix), which needs Nix 2.4. Downstream repos also need their flake.lock bumped to a corepkgs that includes the corepkgs PR before their transitive pins work on 2.3.

Formatting. nix fmt here builds nixfmt-rs from the corepkgs bootstrap (there's no cache hit locally), which wasn't practical to finish. The changed files were instead checked with nixfmt-rs 0.4.1 and nixfmt 1.4.0, and both made no changes.

CI. ci/eval.sh passes: all 7238 packages evaluate.

Pre-existing, unrelated issue. nix eval .#legacyPackages.x86_64-linux.<attr> already fails on origin/master with function 'anonymous lambda' called with unexpected argument 'system': default.nix takes no ... but flake.nix passes system. It's unchanged by this PR and not addressed here.

Sibling PRs

All four PRs use the identical fetch-locked.nix:

`builtins.fetchTree` does not exist in Nix 2.3, so importing pins.nix
failed there. Add fetch-locked.nix, a small helper shared verbatim
across corepkgs, ekapkgs, python-packages and vim-plugins: it resolves
a root input of flake.lock (following `follows`) and fetches it with
`fetchTree` when available, otherwise with `fetchTarball` (github) or
`fetchGit` (git). Both paths yield the same store path, so drvPaths
are unchanged, and flake.lock remains the single source of truth.
@jonringer
jonringer force-pushed the jonringer/nix-2-3-pins branch from 898a2e8 to 614e6ea Compare November 13, 2026 22:15
@jonringer
jonringer merged commit ee77045 into master Nov 13, 2026
2 checks passed
@jonringer
jonringer deleted the jonringer/nix-2-3-pins branch November 14, 2026 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant