Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unstable NAR hash for git inputs using export-subst #7596

Closed
mcwitt opened this issue Jan 13, 2023 · 7 comments
Closed

Unstable NAR hash for git inputs using export-subst #7596

mcwitt opened this issue Jan 13, 2023 · 7 comments
Labels
bug fetching Networking with the outside (non-Nix) world, input locking

Comments

@mcwitt
Copy link

mcwitt commented Jan 13, 2023

Describe the bug

When Flake inputs are git repos that use the export-subst feature in .gitattributes (for example, projects that use python-versioneer), the NAR hashes of these inputs can be unstable over time, leading to NAR hash mismatch in input errors.

Steps To Reproduce

Consider the flake

{
  inputs.export-subst-minimal.url = "git+https://github.com/mcwitt/export-subst-minimal";
  inputs.export-subst-minimal.flake = false;
  outputs = _: { };
}

(the input mcwitt/export-subst-minimal is a minimal example of a repo using export-subst)

The contents of the resulting store path are not reproducible:

$ nix flake lock
$ nix repl
…
nix-repl> :lf .
Added 8 variables.

nix-repl> inputs.export-subst-minimal.outPath
"/nix/store/iy7my74arsc4rgk9xrcs9mxrb0460x8d-source"

$ cat /nix/store/iy7my74arsc4rgk9xrcs9mxrb0460x8d-source/nondeterministic
 (HEAD -> main)

The contents will change for example when the pinned commit is no longer HEAD in main, leading to hash mismatch next time we fetch the input (on a different machine, or if the local cache is invalidated).

Expected behavior

Inputs using the git+https scheme should have stable NAR hashes. In particular, git-archive / export-subst actions should not be run, since these can lead to non-reproducibility as in the example above.

nix-env --version output

nix-env (Nix) 2.11.1

Additional context

Priorities

Add 👍 to issues you find important.

@mcwitt mcwitt added the bug label Jan 13, 2023
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/how-to-deal-with-unstable-flake-input-hashes-due-to-export-subst/24623/3

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-01-13-nix-team-meeting-minutes-23/24644/3

@roberth
Copy link
Member

roberth commented Jan 13, 2023

A different problem with unreproducible git fetchTree was discussed in today's Nix Team meeting.

Another, somewhat-related data point for the github: type is that tree archives appear to receive less or no special processing.
Example: https://github.com/mcwitt/export-subst-minimal/archive/4e289bdc5e251b8aea07ba6cbc6b892450d95600.tar.gz

The tree hash could be stored in the lock file and it would also make subdir fetching more efficient.

@roberth
Copy link
Member

roberth commented Jan 13, 2023

Detailed notes: #4635 (comment)

@roberth roberth mentioned this issue Jan 13, 2023
9 tasks
@mcwitt
Copy link
Author

mcwitt commented Jan 13, 2023

Another, somewhat-related data point for the github: type is that tree archives appear to receive less or no special processing.

I think github: type inputs are still susceptible to a similar issue, though; in this case the substitution is done by github when generating the tree archive. The archives are apparently generated on demand and cached for a short period, so it's still possible to hit the NAR hash mismatch in input issue after some time. (Actually, I initially found this using github: and attempted a workaround by switching to git+https:, hoping the latter would be reproducible)

EDIT: sorry, I'd misunderstood! Indeed, it looks like https://github.com/mcwitt/export-subst-minimal/archive/4e289bdc5e251b8aea07ba6cbc6b892450d95600.tar.gz does not have the substitution applied

@roberth roberth added the fetching Networking with the outside (non-Nix) world, input locking label Nov 17, 2023
@Mic92
Copy link
Member

Mic92 commented Sep 16, 2024

If we were using libgit2 would this give us more control over this?

@roberth
Copy link
Member

roberth commented Sep 16, 2024

It does, and we've been using libgit2 since Nix 2.20

nix-repl> builtins.readFile (builtins.fetchTree { type = "git"; url = "https://github.com/mcwitt/export-subst-minimal"; } + "/nondeterministic")
"$Format:%d$\n"

This is what flakes does internally as well.

Solved since #9240

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fetching Networking with the outside (non-Nix) world, input locking
Projects
None yet
Development

No branches or pull requests

4 participants