Skip to content

check-meta.nix: Fix message for nix build users as well - #101367

Closed
doronbehar wants to merge 1 commit into
NixOS:masterfrom
doronbehar:stdenv/impure-nixUnstable-checkMeta
Closed

doronbehar wants to merge 1 commit into
NixOS:masterfrom
doronbehar:stdenv/impure-nixUnstable-checkMeta

Conversation

@doronbehar

Copy link
Copy Markdown
Contributor

As discussed in:
https://discourse.nixos.org/t/why-isnt-config-nixpkgs-config-nix-evaluated-for-nix-build/9579

It's a bit nontrivial that nix build needs the --impure flag in
order to evaluate ~/.config/nixpkgs/config.nix.

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@nixos-discourse

Copy link
Copy Markdown

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

https://discourse.nixos.org/t/why-isnt-config-nixpkgs-config-nix-evaluated-for-nix-build/9579/4

@ofborg ofborg Bot added the 6.topic: stdenv Standard environment label Oct 22, 2020
@ofborg ofborg Bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Oct 22, 2020
@NobbZ

NobbZ commented Oct 22, 2020

Copy link
Copy Markdown
Contributor

Isn't this more about flake than unstable?

As for me it works using non-flake syntax, though fails when using flake syntax:

$ NIXPKGS_ALLOW_UNFREE=1 nix build -f '<nixpkgs>' steam
# builds successfully
$ NIXPKGS_ALLOW_UNFREE=1 nix build nixpkgs#steam
# does not
$ NIXPKGS_ALLOW_UNFREE=1 nix build --impure nixpkgs#steam
# does build again

@sugar700

sugar700 commented Oct 22, 2020 •

Copy link
Copy Markdown
Member

I don't think nixpkgs should point flakes users to --impure as this breaks caching. It is convenient for sure, but it isn't a proper solution.

Instead you may consider defining a flake that is nixpkgs which is configured to allow unfree packages. This isn't ideal, but well, there is a good reason why nixUnstable is in fact unstable :).

{
  inputs.nixpkgs.url = "https://nixos.org/channels/nixos-20.09/nixexprs.tar.xz";
  outputs = { self, nixpkgs }: {
    defaultPackage.x86_64-linux = import nixpkgs {
      system = "x86_64-linux";
      config.allowUnfree = true;
    };
  };
}

It's also possible to avoid flakes entirely which avoids the issue.

@doronbehar

Copy link
Copy Markdown
Contributor Author
{
  inputs.nixpkgs.url = "https://nixos.org/channels/nixos-20.09/nixexprs.tar.xz";
  outputs = { self, nixpkgs }: {
    defaultPackage.x86_64-linux = import nixpkgs {
      system = "x86_64-linux";
      config.allowUnfree = true;
    };
  };
}

This is indeed worth knowing, but I think it's too much information to put on a trace message like here. However, regarding:

I don't think nixpkgs should point flakes users to --impure as this breaks caching. It is convenient for sure, but it isn't a proper solution.

It depends on what you define as "proper". The use case I had in mind, (which was not specific enough indeed) is testing updates via e.g nix build .#zoom-us or nix profile install nixpkgs#zoom-us. I've adjusted the trace message according to your recommendation - it recommends not using --impure and it mentions it's an issue specific to # flakes syntax.

@doronbehar
doronbehar force-pushed the stdenv/impure-nixUnstable-checkMeta branch from f0a22dc to c9024ac Compare October 22, 2020 14:55
@sugar700

sugar700 commented Oct 22, 2020 •

Copy link
Copy Markdown
Member

It depends on what you define as "proper". The use case I had in mind, (which was not specific enough indeed) is testing updates via e.g nix build .#zoom-us or nix profile install nixpkgs#zoom-us. I've adjusted the trace message according to your recommendation - it recommends not using --impure and it mentions it's an issue specific to # flakes syntax.

You can easily avoid flakes by using nix build -f . zoom-us instead. Flakes are experimental and I would say they should be avoided for now.

@doronbehar

Copy link
Copy Markdown
Contributor Author

You can easily avoid flakes by using nix build -f . zoom-us instead. Flakes are experimental and I would say they should be avoided for now.

Hmm I see, but what about nix profile? It won't accept -f. so it seems.

Just because something is experimental doesn't mean we can't at least explain better a tiny detail to users of this experimental feature. We've had contributions before to nixos-rebuild which included flakes support, and this is what helps adopting such an experimental feature.

Besides, what is the worst thing that could happen? If at some point the flakes syntax would change, we'd only have to slightly update that message, and the price is 0 rebuilds, just as it is today. Please note @xfix that nothing in the new message's text recommends using flakes.

@sugar700

sugar700 commented Oct 23, 2020 •

Copy link
Copy Markdown
Member

Providing instructions for flakes makes the error message more noisy for users who don't use flakes.

However, I think an improvement is still possible. It's possible to recognize whether an user is using flakes or not and provide a different message depending on that.

That being said, I think there should be a way to pass configuration options into Nix flakes, it's just that it wasn't implemented yet. Worth noting that this isn't --impure however, as --impure does way too much.

@doronbehar

Copy link
Copy Markdown
Contributor Author

However, I think an improvement is still possible. It's possible to recognize whether an user is using flakes or not and provide a different message depending on that.

Indeed that would be ideal, though I'm not sure how would I do that - should it be a check of the current nix.package.version? Is that possible in the scope of that meta?

@doronbehar
doronbehar force-pushed the stdenv/impure-nixUnstable-checkMeta branch from c9024ac to e8b62f4 Compare December 9, 2020 15:07
@nixos-discourse

Copy link
Copy Markdown

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

https://discourse.nixos.org/t/using-non-free-libraries-in-flakes/8632/15

@rjpcasalino

rjpcasalino commented May 20, 2021 •

Copy link
Copy Markdown
Contributor

@doronbehar sorry for bumping something from over a year ago but I managed to find my way here mostly because of your comments on discourse (in the above mentioned and others). Are there any updates on this? I know things might be a bit wild in your neck of the woods right about now.

@doronbehar

Copy link
Copy Markdown
Contributor Author

@doronbehar sorry for bumping something from over a year ago but I managed to find my way here mostly because of your comments on discourse (in the above mentioned and others). Are there any updates on this?

Not really, the last suggestion by @xfix was to make that eval message different for nixUnstable and nixStable users, but (now) I think it's not possible to do it - nixpkgs on it's own doesn't know what nix version is used. Hence my opinion is that to give "unstable" nix more respect, this PR is one of the things we could improve.

I know things might be a bit wild in your neck of the woods right about now.

Thanks a lot for your concern ☺️. It's not such a big deal in the area where I live in.

@teto

teto commented Oct 2, 2021

Copy link
Copy Markdown
Member

flakes is about improving purity so recommending --impure loooks like the opposite of what we want. Reimporting nixpkgs is s uperior solution IMO. Not sure how to communicate that, point at the nixflake wiki page with this solution described ?

@doronbehar

Copy link
Copy Markdown
Contributor Author

flakes is about improving purity so recommending --impure loooks like the opposite of what we want. Reimporting nixpkgs is s uperior solution IMO. Not sure how to communicate that, point at the nixflake wiki page with this solution described ?

Yea the problem is that it's impossible for that message to know whether it is being evaluated because someone imported Nixpkgs or because someone tried to evaluate a package from Nixpkgs' repo. In the first case I totally agree it'd be a bad advice. I'm not sure there's something we can do.. I'll close this.

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

Labels

6.topic: stdenv Standard environment 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants