`allowUnfree` for flake registries

So there is nix.registry.name.flake which I like to quickly try out packages either from stable or unstable like this:

nix shell stable#coreutils
# or if I want the unstable package
nix shell unstable#coreutils

but if I try to download an unfree software (like discord), then I’m getting this:

error:
       … while evaluating condition
         at /nix/store/dgp9wmspgm6zhl66f0c81rvg3v7wwbsb-source/lib/customisation.nix:430:16:
          429|       drvPath =
          430|         assert condition;
             |                ^
          431|         drv.drvPath;

       … while evaluating the attribute 'handled'
         at /nix/store/dgp9wmspgm6zhl66f0c81rvg3v7wwbsb-source/pkgs/stdenv/generic/check-meta.nix:751:9:
          750|         # or, alternatively, just output a warning message.
          751|         handled = (
             |         ^
          752|           if valid == "yes" then

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: Package ‘discord-0.0.116’ in /nix/store/dgp9wmspgm6zhl66f0c81rvg3v7wwbsb-source/pkgs/applications/networking/instant-messengers/discord/default.nix:71 has an unfree license (‘unfree’), refusing to evaluate.

       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: When using `nix shell`, `nix build`, `nix develop`, etc with a flake,
                then pass `--impure` in order to allow use of environment variables.

       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) [
             "discord"
           ];
         }

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

How can I enable allowUnfree for my registries?

One easy method will be add NIXPKGS_ALLOW_UNFREE=1 to your environment and add -–impure to your nix calls.

Erm, don’t do that.

Replace the nixpkgs entry with GitHub - numtide/nixpkgs-unfree: nixpkgs with the unfree bits enabled instead (or make a new registry entry called unfree).

1 Like

Yes, but that solves it only temporal.

Sad that I have to add another flake just for this

@TLATER hm… is the repo which linked really save? Its last commit is 5 months ago although it claims that it gets daily updated:

The following channels are synched daily with upstream:

GitHub - numtide/nixpkgs-unfree at nixos-unstable is updated 2 days ago. They don’t have a stable branch, though. Your only choice is to use --impure or fork nixpkgs yourself.

1 Like

I actually solve this problem by creating a flake that exposes the pkgs set of my nixos configuration, exactly as it’s configured there, with unfree settings, overlays, etc:

(mkFlake is defined here.)

1 Like