treewide: migrate usages of nix hash to nix-hash#436570
treewide: migrate usages of nix hash to nix-hash#436570Frontear wants to merge 1 commit intoNixOS:masterfrom
nix hash to nix-hash#436570Conversation
|
cc @wolfgangwalther -- seems relevant to the minfeatures discussion? |
|
Here's my take on this:
|
I've intentionally skipped out on a hundred or so files that still use |
|
I agree with Wolfgang's thoughts above. For update scripts, it seems worthwhile to insist on them being self-contained: that is, they're not reliant on the user's ambient environment and $PATH to do their job. The use of the double shebang and the nixpkgs/pkgs/by-name/qq/qq/update.sh Lines 1 to 2 in 45bbb3c So the only thing they rely on, then, is that If they are self-contained, in their update step they have their choice of using Nix or Lix or Now, previously I called the Nix The best option, in my view, is to have a tool which comes from neither Nix nor Lix, is fit for the Nixpkgs update process, and is used across all the update scripts. |
I disagree wrt to
I disagree here, too: These scripts should be mostly self-contained, but not regarding
I don't know |
OK, I see that point, though I don't think it's really in opposition -- it's just raising the containedness from "this single script" to "the ambient environment provided by the CI default.nix". Sounds good to me!
Here we do have a real opposition. Claiming a "working implementation" in the face of the real lack of coordination w.r.t. command line interface, default configuration, and more between the projects is just false to facts. And the divergences will continue, and they should!. The cited differences between them above are enough for me to want to make either the update script itself or the CI environment remove the non-determinism through providing a consistent copy. It's a false economy to avoid the download. |
|
We can't make an update script independent of the "host nix", though: It determines how the nix-shell shebang behaves etc. (also see #425551). So we can't dodge the issue of which implementations in which versions we support or not. |
|
Also related: #421261 and #400784. I think there were some other issues somewhere around incompatibilities between running certain Nix versions with certain Lix daemons or the other way around (maybe even newer Nix vs older Nix). So even with a pinned Lix/Nix in the shell, it would still have to talk to the daemon if any builds were made. Not sure whether that's the case for any update script, but certainly for some of the other scripts we have in-tree. |
|
Thanks, #425551 is quite relevant, and the other issues you linked sketch out the problem also. I've subscribed to that issue. I think I now agree with you that using the ambient Nix is the only way to go in light of the Nix-in-Nix (or Lix-in-Lix or various version combinations outlined in those issues) problems. I wish it were not so. |
|
From what I'm reading, the consensus seems to be that a) yes, this is an issue and support should be provided for both Nix and Lix, and b) a wrapper/external tool would be a good way to provide this functionality (I'm thinking of the name My ideas for the wrapper would just be to leverage
Could you clarify what you mean by ambient here? Does ambient = using the locally installed Nix? |
Yes. |
|
I assume somewhere in |
NOTE: This PR is incomplete, pending discussion of the changes. Once a consensus is reached I will add in the rest of the changes.
This PR is inspired by the discussion at #436230, and seeks to resolve the issues mentioned in #421823, but from a different direction.
The
nix hashsubcommand requiresexperimental-features = nix-command ...in/etc/nix/nix.conf(or passed via CLI args) in order to be used, otherwise it will fail with an error. Furthermore, other distributions of Nix (namely Lix) seem to lack thenix hash convertsubcommand that the official Nix has, despite it having been added 2 years ago in Nix 2.20 (NixOS/nix#9452). This means Lix users have to usenix hash to-(base16|base32|base64|sri) ..., which is considered deprecated by Nix (but still supported as of 2.28.4, though could be removed anytime).Both of these issues will cause problems for other users looking to execute any code that uses them in Nixpkgs. One obvious solution is to tack on
--extra-experimental-features 'nix-command'to the Nix command, but this flag is really long and easy to forget by most users (a few scripts were missed or added after #421823 that have been fixed here), and the issue ofnix hash convertbeing non-existent on Lix is an issue that can cause a lot of confusion (as per #436230).My solution involves transforming all calls to
nix hash(and variations with--(extra-)?experimental-features) into the equivalentnix-hashinvocations. This will avoid the issues of forgetting thenix-commandexperimental-feature and be stable across all other Nix implementations since this is part of the legacy CLI interface.cc @philiptaron @lonerOrz as relevant parties to this discussion.
Problems
The most obvious one to me is that
nix-hashby default usesmd5as the hashing algorithm (nix hashuses sha256), and uses base16 representation (nix hashuses sri). These can be fixed by adding--sri --type sha256to the CLI arguments, but this creates an issue for forward compatibility withnix hash, and once again brings the same issue of "forgetting to add flags".Alternative
We can instead choose to not concern ourselves with Lix being incompatible with upstream Nix (this isn't the only one, the experimental feature
pipe-operatorvspipe-operatorsis another). This does mean that any contributors who use Lix will have to resolve their issues as they are encountered.In this situation, the only thing this PR would seek to do would be to add the missing
--extra-experimental-featuresto allnix hashcalls that have it missing and remove all of thenix hash->nix-hashchanges.Sidenote
I originally considered PRing to replace all of the new nix3 subcommands with their nix-legacy equivalents, but I didn't do so because I figured that warranted a larger discussion. One benefit of doing so would be faster evaluation times (going from
nix evaltonix-instantiatehad pretty significant improvements due to not needing to copy the flake directory so much), but similar issues about forward compatibility arise, hence the need for a discussion.Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.Add a 👍 reaction to pull requests you find important.