zero-to-nix icon indicating copy to clipboard operation
zero-to-nix copied to clipboard

Allow unfree?

Open DanLipsitt opened this issue 1 year ago • 1 comments

How do I enable unfree packages? When attempting to run one with nix shell, I get the following error:

       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.

       b) For `nixos-rebuild` you can set
         { nixpkgs.config.allowUnfree = true; }
       in configuration.nix to override this.

       Alternatively you can configure a predicate to allow specific packages:
         { nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
             "vscode"
           ];
         }

       c) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
         { allowUnfree = true; }
       to ~/.config/nixpkgs/config.nix.

a) doesn't apply because I want the setting to persist. b) doesn't apply because I'm on Darwin, not NixOS. c) doesn't work. ~/.config/nixpkgs/config.nix doesn't exist, and creating it with the suggested contents doesn't appear to do anything. I'm using Home Manager but it doesn't appear to have its own setting for this.

In the future, could this be configured based on a prompt from the Determinate installer?

DanLipsitt avatar Jul 02 '23 00:07 DanLipsitt

Is this related to #370?

adamjsawicki avatar Sep 27 '24 22:09 adamjsawicki

The issue is that the experimental-features = flakes effectively ignores all options related to the nixpkgs in all nix.conf files. This is mentioned all over Nix Discourse (though much less clearly).

There are two options to solve this:

  1. Set the NIXPKGS_ALLOW_UNFREE=1 and use --impure so the environment variable can affect the build (can be setup to be "permanent" with profile or shell rc files and an alias).
  2. Add a new flake registry that has allowUnfree enabled.

The first option is less than ideal, but the most directly compatible.

The second option can be done by making use of a Numtide repo designed for exactly this purpose.

nix registry add nixpkgs-unfree 'github:numtide/nixpkgs-unfree?ref=nixos-unstable'

Then unfree packages from the unstable nixpkgs repo can be installed with:

nix profile install 'nixpkgs-unfree#pkgname'

mtalexan avatar Nov 27 '24 02:11 mtalexan