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

nix will pointlessly re-fetch registry entries if they are defined as store paths #7075

Open
lf- opened this issue Sep 21, 2022 · 7 comments
Labels

Comments

@lf-
Copy link
Member

lf- commented Sep 21, 2022

Describe the bug

On my NixOS and nix-darwin machines I pin the system nixpkgs as nixpkgs so building stuff is faster, using nix.registry.nixpkgs.flake = nixpkgs; in my configuration.

/etc/nix/registry.json looks like so:

{"flakes":[{"exact":true,"from":{"id":"nixpkgs","type":"indirect"},"to":{"path":"/nix/store/cn1ag0zf4388i4s9ymx80hrqvma0p9qy-nixpkgs-src","rev":"36cc29d837e7232e3176e4651e8e117a6f231793","type":"path"}}],"version":2}
 » nix registry list
system flake:nixpkgs path:/nix/store/cn1ag0zf4388i4s9ymx80hrqvma0p9qy-nixpkgs-src?rev=36cc29d837e7232e3176e4651e8e117a6f231793
........

and every time I use nix-command with flakes it pointlessly copies from the nix store to the nix store:

$ nix shell nixpkgs#hello
copying '/nix/store/cn1ag0zf4388i4s9ymx80hrqvma0p9qy-nixpkgs-src'

Steps To Reproduce

  1. Put the result of:
» nix eval --expr '<nixpkgs>' --impure
/nix/store/cn1ag0zf4388i4s9ymx80hrqvma0p9qy-nixpkgs-src

into /etc/nix/registry.json replacing my path above.
2. nix run nixpkgs#hello

Expected behavior

Should execute instantly because it avoids gratuitously copying a store path to the store.

nix-env --version output

 » nix --version
nix (Nix) 2.10.3

however also reproduced on master:

co/nix - [master] » result/bin/nix --version
nix (Nix) 2.12.0pre20220921_f704c27
co/nix - [master] » result/bin/nix build nixpkgs#hello
copying '/nix/store/cn1ag0zf4388i4s9ymx80hrqvma0p9qy-nixpkgs-src

Additional context

Add any other context about the problem here.

@lf- lf- added the bug label Sep 21, 2022
@lf-
Copy link
Member Author

lf- commented Sep 22, 2022

Hmmm. So I've gone bughunting and I think I have found a part answer:

I think based on reading src/libfetchers/path.cc that it will possibly do this silly copying business if it is not a "store path", for instance, it will do the bad thing if you put /nix/store/6hmwry071zcdf5jphlrxgv3amgwwqc7n-nixpkgs/nixpkgs as you would get if it's a channel.

Not fully confident about this though: there's also checks that the name of the store path is "source". I wonder if that's related.

@thufschmitt
Copy link
Member

thufschmitt commented Sep 22, 2022

Are you sure that it's actually copying it, or do you just see the copying message?

Looking at the code, Nix prints the copying message, but then short-circuits if the path is a valid store path (which is still a problem because then we print a misleading message, but a slightly different one)

EDIT: nevermind, didn't see your previous message. Indeed the check for the source name is probably the cause of the copy.

@lf-
Copy link
Member Author

lf- commented Sep 22, 2022

I see the copying message, and it also takes a long time. The taking a long time leads me to believe it is being copied.

@lf-
Copy link
Member Author

lf- commented Sep 22, 2022

A fun thing is that /nix/store/xxx-blah/somesubdir is not considered a "store path" to Nix in this context, due to the subdirectory.

@thufschmitt
Copy link
Member

A fun thing is that /nix/store/xxx-blah/somesubdir is not considered a "store path" to Nix in this context, due to the subdirectory.

Yes. That's a gross approximation, but also required for purity (until/if ever #6530 lands) because relative paths (to the parent) will have a different meaning if you keep it as a subdir.

I think you can do /nix/store/xxx-blah?dir=somesubdir though, although I'm not 100% what the semantics are

@lf-
Copy link
Member Author

lf- commented Dec 18, 2022

Update from later: if you name your thing source, Nix will indeed not do the buggy behaviour. Rather odd.

@Aleksanaa
Copy link
Member

Update from later: if you name your thing source, Nix will indeed not do the buggy behaviour. Rather odd.

But how did you rename it with nix.registry.nixpkgs.flake = nixpkgs;?

@stale stale bot removed the stale label Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants