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

Allow unfree packages with nix shell #166220

Closed
GuillaumeDesforges opened this issue Mar 29, 2022 · 5 comments
Closed

Allow unfree packages with nix shell #166220

GuillaumeDesforges opened this issue Mar 29, 2022 · 5 comments

Comments

@GuillaumeDesforges
Copy link
Contributor

Issue description

Currently, it's not possible to use unfree packages with nix shell

e.g.

nix shell nixpkgs#python3Packages.cupy

a current workaround is to use --impure, but one can want both unfree and not impure.

Possible fix

My guess is that the legacyPackages is loaded with inherited system.

legacyPackages = forAllSystems (system: import ./. { inherit system; });

There is no way to provide an argument to flakes (see NixOS/nix#3843 (comment)) and pass it to the instanciation, and most likely won't ever be.

Therefore, a suggestion would be to add

legacyPackages.withUnfree = forAllSystems (system: import ./. { inherit system; config.allowUnfree = true; });

The downside is that we get all packages twice, e.g. in commands such as nix search.

Note

We could think of being able to pass an argument such as --allow-unfree to the Nix command, but in my opinion it is too focused on nixpkgs and most likely to be rejected.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 1, 2022
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 24, 2023
@con-f-use
Copy link
Contributor

So is there a solution or workaround for this? I'd like have a devShell with unfree packages.

@GuillaumeDesforges
Copy link
Contributor Author

For now a workaround is to use

$ NIXPKGS_ALLOW_UNFREE=1 nix shell --impure nixpkgs#yourpackage

@con-f-use
Copy link
Contributor

con-f-use commented Mar 25, 2023

Norbert (NobbZ) suggest the following on discord, which seems to work well:

inputs = {
  nixunstable.url = "github:NixOS/nixpkgs/nixos-unstable";
};

outputs = { nixunstable }: {
  devShells.x86_64-linux.default = let
      pkgs = import nixunstable { system = "x86_64-linux"; config.allowUnfree = true; };
  in pkgs.callPackage ./myshelll.nix {};
};

@Artturin
Copy link
Member

Artturin commented Mar 25, 2023

the error message already contains

a) To temporarily allow unfree packages, you can use an environment variable
   for a single invocation of the nix tools.

     $ export NIXPKGS_ALLOW_UNFREE=1

 Note: For `nix shell`, `nix build`, `nix develop` or any other Nix 2.4+
 (Flake) command, `--impure` must be passed in order to read this
 environment variable.

anything else should be discussed in nix instead of nixpkgs

legacyPackages.withUnfree would probably cause a performance impact

@guissalustiano
Copy link

You also could add in nxpkg import

{ pkgs ? (import <nixpkgs> { 
    config.allowUnfree = true;
    config.segger-jlink.acceptLicense = true; 
}), ... }:
pkgs.mkShell {
  packages = with pkgs; [
    nrfconnect
  ];
}

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

No branches or pull requests

4 participants