Use nixpkgs.config.allowUnfreePredicate in multiple nix file

Hi, I am a beginner of NixOS.
I am using some unfree drivers and putting them into separated .nix file:

brother-printer-unfree.nix:

{ pkgs, lib, ... }:
{
  nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
    "dcp375cwlpr"
    "dcp375cw-cupswrapper"
  ];
  services.printing = {
    enable = true;
    drivers = [ pkgs.dcp375cwlpr pkgs.dcp375cw-cupswrapper ];
  };
  # other printer config...
}

nvidia-unfree.nix:

{ config, lib, pkgs, ... }:
{
  nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
    "nvidia-x11"
    "nvidia-settings"
    "nvidia-persistenced"
  ];
  services.xserver.videoDrivers = ["nvidia"];
  hardware.nvidia = {
    # some other nvidia config...
  };
}

Both of them are imported in configuration.nix
However, seems nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) []; cannot be duplicate in multiple file like environment.systemPackages = with pkgs; [], I have to put all of them in one place to make it work.
How can I separate them into multiple .nix file? Thanks!

1 Like

I’ve settled on using a polyfill for #55674 so that individual files only specify a list that gets automatically merged.

2 Likes

There’s no better way than to implement this downstream via a polyfill like that currently.

@piegames asked about changing the option a while ago, aiming to simplify things a bit, there’s some fear of breaking backwards-compatibility by introducing an option that only matches package names (though this could be avoided by making any new options incompatible). Not much has happened on the topic since.

1 Like

Crazy, I can’t believe it can be achieved by just a few lines!

I think that the best way forward from here is to continue implementing RFC 127, then figure out how to migrate the individual options. Unfortunately nobody is currently working on that at the moment

1 Like