Allow customizing fetchurl hashedMirrors#409010
Conversation
61f2eca to
c80c516
Compare
|
I would vaguely prefer to drop the whole mirrors machinery: they’re not very useful in a CDN‐oriented 2025 and it’s not just firewalls that cause issues, since sometimes mirrors lag behind or have other issues. Especially the How would you feel about just dropping the mirrors that have caused you issues? I think that for cases where there is one obvious primary mirror, especially one that doesn’t have an explicit warning against using it or that is behind a CDN or load‐balancing redirect, we should just list that mirror. Then when all of these entries have only one URL we can think about dropping the mechanism entirely. If you wanted to make that happen, that would be great, but otherwise maybe you can just drop specific problematic ones? |
|
Okay I just looked at the mirrors list again and got annoyed so I’m going to tackle trimming it down myself. Hopefully you can look at the resulting PR and let me know if it will fix your issue here. |
Although dropping problematic mirrors would help some cases, allowing customizations to the set of mirrors remains a primary concern for us: We're working in a company scenario where access to external urls is deliberately blocked by firewalls, and package sources must be fetched through company-internal mirrors. The customizations we want to apply to the mirror list include e.g. replacing Adding this customization point allows us to get away with a configuration change rather than having to patch nixpkgs in our deployment.
Do you mean dropping the |
|
I’ve put up #409110.
Right. But the vast majority of packages don’t use the
The remaining value I see in |
|
To quote #409110 (comment) which is relevant here:
|
It's currently handled by the same mechanism, and adding an override specifically for it is more work than adding an override for the entire mirror list, all for less functionality. If in the future we want to get rid of non-hashed mirrors entirely, this PR doesn't make it any more difficult to do. |
2168363 to
3a64d1f
Compare
|
I'm loathe to merge this since it's my belief that #410186 allows your usecases to complete without this complication of the mirror system. |
Actually, it's not possible to use Another possibility is to change |
There was a problem hiding this comment.
It's currently handled by the same mechanism, and adding an override specifically for it is more work than adding an override for the entire mirror list, all for less functionality. If in the future we want to get rid of non-hashed mirrors entirely, this PR doesn't make it any more difficult to do.
I have to disagree with that:
- Making only
hashedMirrorsoverridable is not substantially harder than making allmirrorsoverridable, see suggestion below - The goal should not be to have the most functionality, but to have functionality according to what we need. And @jherland confirmed that they only need
hashedMirrorsto be overridable:The customizations we want to apply to the mirror list include e.g. replacing
hashedMirrors = ["https://tarballs.nixos.org"]withhashedMirrors = [COMPANY_INTERNAL_MIRROR]. - This PR in its current state does make it harder to get rid of non-hashed mirrors in the future, because it introduces a public interface for them, which comes with expectation of stability and deprecation periods, which does require maintenance and consideration to handle properly.
So, I think we should just expose an override interface for hashedMirrors, which is also a great step towards avoiding conflation with mirrors. The fact that those are specified with the same attribute set is really just an implementation detail anyways, it's not fit for an interface.
If there is also a requirement to override non-hashed mirrors (now or in the future), a separate PR would be more appropriate to not conflate the discussions of the two any more.
PS: I'd like to refer to C4, which I hope to see used more, point 2.3.2:
A patch SHOULD be a minimal and accurate answer to exactly one identified and agreed problem.
pkgs/top-level/config.nix
Outdated
| mirrors = mkOption { | ||
| type = types.attrsOf (types.listOf types.str); |
There was a problem hiding this comment.
Only make hashedMirrors customisable, and set the default using the module system. Other code needs adjustments.
| mirrors = mkOption { | |
| type = types.attrsOf (types.listOf types.str); | |
| hashedMirrors = mkOption { | |
| type = types.listOf types.str; | |
| default = [ "https://tarballs.nixos.org" ]; |
Description should mention https://github.com/NixOS/nixpkgs/blob/master/maintainers/scripts/copy-tarballs.pl
pkgs/top-level/all-packages.nix
Outdated
| mirrors = config.mirrors; | ||
|
|
There was a problem hiding this comment.
There shouldn't be a need to expose this as a top-level attribute.
| mirrors = config.mirrors; |
| }: | ||
|
|
||
| let | ||
|
|
||
| mirrors = import ./mirrors.nix; |
There was a problem hiding this comment.
This will be just
mirrors = import ./mirrors.nix // {
inherit hashedMirrors;
};I also suggest setting hashedMirrors in mirrors.nix to:
hashedMirrors = throw "Use config.hashedMirrors instead of (import ./pkgs/build-support/fetchurl/mirrors.nix).hashedMirrors"Hopefully nobody did that, but if they did it's a free good error message, and at the same time prevents people from trying to make mirror://hashedMirrors/... work.
There was a problem hiding this comment.
Hopefully nobody did that, but if they did it's a free good error message, and at the same time prevents people from trying to make mirror://hashedMirrors/... work.
Unless I'm missing something, this change would have no effect on mirror://hashedMirrors; we would have to separate the two entirely (which I'm in favor of).
3a64d1f to
3b1e78c
Compare
Was missing from abda866 While the native stdenv's eval seems to be broken anyways, the freebsd one at least evaluates again with this
Allows having alternate hashed mirrors as fallbacks. Useful in case the default hashed mirror is not accessible or doesn't have everything needed. Co-authored-by: Johan Herland <[email protected]> Co-authored-by: Yuriy Taraday <[email protected]> Co-authored-by: Alexander Bantyev <[email protected]>
3b1e78c to
56f680d
Compare
There was a problem hiding this comment.
My memory from #414769 is that there's an equivalent change needed in pkgs/build-support/fetchurl/booter.nix and minimal-bootstrap for any change in pkgs/build-support/fetchurl/default.nix.
There was a problem hiding this comment.
rewriteURL made sense to apply to fetchurlBoot because it's an eval-time feature and fetchurlBoot supported mirror:// too. hashedMirrors however is a build-time feature that fetchurlBoot doesn't support, so can't be applied here. I tested the command in the PR, works without issues.
Nix users behind a firewall may have difficulties reaching the default mirrors referenced from
pkgs/build-support/fetchurl/mirrors.nix. Additionally, Nix users inside corporations may need to prefer company-internal mirrors.This PR exposes the set of mirrors used by
fetchurlvia the nixpkgs config, allowing users to customize it via their~/.config/nixpkgs/config.nix. The default mirror list is made available inconfig.mirrors, and users may remove/add/replace/adjust the mirrors via the module system, as shown in the documented example.@infinisil edit: This PR is now changed to only allow customisation of
hashedMirrorsThings done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)config.mirrorsattributeAdd a 👍 reaction to pull requests you find important.