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

documentation: mention substituter precedence #3685

Closed
wants to merge 1 commit into from

Conversation

asymmetric
Copy link
Contributor

Mentions the order in which substituters are queried.

@edolstra
Copy link
Member

That's actually not true. Binary caches have a priority field that determines the order (see the Priority field in https://cache.nixos.org/nix-cache-info).

@d-xo
Copy link

d-xo commented Jun 11, 2020

@edolstra what happens if two caches have the same priority?

@edolstra
Copy link
Member

Then they're tried in the order in which they're defined in nix.conf.

@d-xo
Copy link

d-xo commented Jun 11, 2020

@edolstra thanks!

I'm curious about why caches are allowed to define their own priority?

I have a few cachix substituters defined and would like to be able to tell nix to prefer binaries from cache.nixos.org over those from my cachix sustituters, but that doesn't seem to be possible if any cache can set itself to prio 1 without my consent?

@asymmetric
Copy link
Contributor Author

asymmetric commented Jun 11, 2020

@edolstra Would this be better?

Substituters with the same Priority value are queried from left to right.

Doesn't really explain what this Priority is, but at least it's not incorrect.

@grahamc
Copy link
Member

grahamc commented Jun 11, 2020

btw it isnt a good idea to depend on priority as a security feature, since it doesn't provide meaningful control over what you get from what cache.

@edolstra
Copy link
Member

The original use case was to ensure that cache.nixos.org (which is fast) is prioritized over hydra.nixos.org (which is slow). Nowadays hydra.nixos.org no longer provides a binary cache so it doesn't matter anymore.

BTW I think you can also set the priority in the substituter URL (e.g. http://bla?priority=123).

@d-xo
Copy link

d-xo commented Jun 11, 2020

btw it isnt a good idea to depend on priority as a security feature, since it doesn't provide meaningful control over what you get from what cache.

@grahamc Could you elaborate a bit? I'm not sure I follow.

@stale
Copy link

stale bot commented Feb 12, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Feb 12, 2021
@asymmetric asymmetric closed this Feb 12, 2021
@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/how-does-nix-choose-a-substituter-when-there-is-more-than-one-choice/3658/8

@asymmetric asymmetric deleted the doc-subst-precedence branch April 10, 2021 21:45
@Fuuzetsu
Copy link
Member

Is higher Priority better? The source says otherwise https://github.com/NixOS/nix/blob/master/src/libstore/store-api.hh#L195 but common usage and also experimental findings like in https://discourse.nixos.org/t/how-does-nix-choose-a-substituter-when-there-is-more-than-one-choice/3658 suggest otherwise.

@asymmetric
Copy link
Contributor Author

@edolstra does specifying the priority in the substituter URL have precedence over the Priority field in the cache itself?

@Fuuzetsu where do you see disagreement on the sorting? There seems to be agreement on lower value = higher priority.

@Fuuzetsu
Copy link
Member

@asymmetric I set priority 50 in my s3 cache amd it gets picked over priority 40 official nixos cache.

In linked issue, nix-serve with priority 30 gets checked only after the official priority 40 cache.

@asymmetric
Copy link
Contributor Author

@Fuuzetsu in the linked issue, priority 30 gets checked before 40:

My local nix.conf specifies both the internal CI server as well as cache.nixos.org as substituters.

I’ve noticed that the internal CI server is picked for paths that exist on BOTH caches.
I wondered how does it pick a CI server so I tried changing the order of the CI servers in nix.conf but it kept picking the internal CI server.

The CI server cache’s priority is set to 30.

@Fuuzetsu
Copy link
Member

in the linked issue, priority 30 gets checked before 40

Oh, you're right. I have a priority to change. Thank you for the doc update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants