Nixpkgs unfree configs not respected

Hello,

I have module that install non-free applications and allow them using allowUnfreePredicate (also tried allowUnfree config) like these.

{ config, pkgs, lib, ... }:

let
   upkg = import <unstable> {};
in rec {
  nixpkgs.config = {
    allowUnfreePredicate = pkg: (builtins.elem (lib.getName pkg) [
      builtins.trace (lib.getName upkg.slack) (lib.getName upkg.slack)
      builtins.trace (lib.getName upkg.obsidian) (lib.getName upkg.obsidian)
      "slack"
      "obsidian"
    ]);
  };

  environment.systemPackages = with pkgs; [
    upkg.slack
    upkg.obsidian
  ];
};

Despite that, it still conflict whenever I use obsidian and slack package.

building Nix...
building the system configuration...
error: Package ‘obsidian-0.14.15’ in /nix/store/xxxxxxxx-unstable/unstable/pkgs/applications/misc/obsidian/default.nix:18 has an unfree license (‘obsidian’), 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: 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) [
             "obsidian"
           ];
         }

       c) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
         { allowUnfree = true; }
       to ~/.config/nixpkgs/config.nix.
(use '--show-trace' to show detailed location information)

I’m trying to builtins.trace in the config entry, but nothing traced (like not called at all).
I want to report this as a bug but need someone that might points out a mis-configuration.

Your upkg does not magically inherit the config, you need to manually configure it in its input to allow unfree.

1 Like

The nixpkgs.* options are configuring pkgs, but you didn’t pull the packages from pkgs. Try upkg = import <unstable> { config.allowUnfreePredicate = ...; };

2 Likes

Cool! it works now after setting both predicates.

let
  allowUnfreesP = pkg: (builtins.elem (lib.getName pkg) [
    "obsidian"
    "slack"
  ];
  upkg = import <unstable> {
    config.allowUnfreePredicate = allowUnfreesP;
  };
in rec {
    nixpkgs.config.allowUnfreePredicate = unfreelistP;
    # ...
}

Thank you @NobbZ @tejing

1 Like

This situation where 1. setting allowUnfree* in a module does nothing by itself and 2. setting allowUnfree* when importing Nixpkgs does not work unless you also set it in a module, is fairly recent and pretty weird actually.

I think there are a couple of GH issues about this that apparently nobody knows what to do about.

I have never observed the described behaviour.

Can you point me to those “unresolved issues” anywhere?

That is specific to HM and not reproducible in nixos modules.

They are probably related to how nixpkgs gets evaluated in HM.

There’s also this issue on home-manager.

https://github.com/nix-community/home-manager/pull/2720 - makes it easier to directly used a passed in pkgs instead of home-manager creating a new one, waiting for review for a while :frowning: