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 run pure unfree packages #9875

Open
arduano opened this issue Jan 29, 2024 · 7 comments
Open

nix run pure unfree packages #9875

arduano opened this issue Jan 29, 2024 · 7 comments
Labels
feature Feature request or proposal flakes

Comments

@arduano
Copy link

arduano commented Jan 29, 2024

There appears to be no way to run unfree packages in a pure nix run/shell.

The only workaround seems to be NIXPKGS_ALLOW_UNFREE=1 nix run --impure <pkg>, but that doesn't allow for a pure shell.

I understand that nix3 attempts to provide as much isolation as possible, hence it not reading any system-wide configuration (e.g. { allowUnfree = true; } in my ~/.config/nixpkgs/config.nix.).

However, it would be nice to at least have a CLI flag, e.g. --allow-unfree on nix run and nix shell to bypass the check.

@arduano arduano added the feature Feature request or proposal label Jan 29, 2024
@thufschmitt
Copy link
Member

That's quite a bummer, I agree.
You can get that in a pure shell if you're using your own flake (because you can import nixpkgs with { allowUnfree = true; } in it) but it indeed doesn't work if you want to nix run nixpkgs#<something>.

A dedicated flag would be quite ad-hoc and a nasty layer violation (Nix doesn't know about free/unfree things, that's just something encoded in Nixpkgs), but we should find a replacement for that. Maybe that could be solved on the Nixpkgs side by providing an unfreePkgs attribute that allows unfree packages?

@7c6f434c
Copy link
Member

A command-line parameter to pass arguments when importing a flake wouldn't break the command-level purity and would be rather similar to one of the purer ways of achieving it with the previous CLI. (And, as you say, would not do anything that a dependent flake couldn't cause from the caching point of view)

@arduano
Copy link
Author

arduano commented Feb 7, 2024

What about adding a CLI arg for injecting env variables into a pure environment? It should be ok from a sandboxing perspective because it's explicitly specified, rather than inheriting the variables from the host, so I don't see what issues it could cause. Then the solution would just be something like

nix run -e NIXPKGS_ALLOW_UNFREE=1 <pkg>

@tomberek
Copy link
Contributor

This is similar to #5663 and related issues.

A workaround is to use https://github.com/numtide/nixpkgs-unfree. Or to craft your own that specifies a license policy that you want. So while this can be solved by using your own flake, this is a feature that used to exist, but led to problems resulting in the creation of the pure-evaluation mode.

If we want something that makes this easier and built into upstream, one can imagine adding a "config" input to the nixpkgs flake, empty by default allowing something like nix run --override-input config my-policy nixpkgs#slack.

I don't think we've considered adding env var injection. As opposed to making it an explicit input, this would break things like the eval cache if not tracked.

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/2024-02-16-nix-team-meeting-minutes-124/39870/1

@arduano
Copy link
Author

arduano commented Feb 19, 2024

Possibly related: #5567

Maybe it would be nice to inject things like

nixpkgs.config.allowUnfree = true;

or even

nixpkgs.config.cudaSupport = true;

within the command line nix run or nix shell. E.g. personally I want to make an alias or something that always injects unfree/cuda for my invocations because I always use them, but I'm not sure what would be the cleanest approach to adding this to the nix command.

@bobvanderlinden
Copy link
Member

Having it behave the same for nix run and referring to nixpkgs inside a flake would be very welcome.

How about making these configuration options part of the flake uri? We already allow some query parameters for some sources, but it could support config options as well.

github:nixos/nixpkgs/nixpkgs-unstable?config.allowUnfree=true

It would work for package uris as well:

github:nixos/nixpkgs/nixpkgs-unstable?config.allowUnfree=true#<pkgs>

The referred flake would get config as one of its inputs (next to other flake inputs).

outputs = { nixpkgs, config ? {} }:

nixpkgs would need to support this.

@roberth roberth added the flakes label Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal flakes
Projects
None yet
Development

No branches or pull requests

7 participants