diff --git a/nixos/modules/misc/nixpkgs.nix b/nixos/modules/misc/nixpkgs.nix index 449a08a97b61..e832cfd2ebdd 100644 --- a/nixos/modules/misc/nixpkgs.nix +++ b/nixos/modules/misc/nixpkgs.nix @@ -20,6 +20,9 @@ let rhs = optCall rhs_ { inherit pkgs; }; in lib.recursiveUpdate lhs rhs + // lib.optionalAttrs (lhs ? allowUnfreePackages) { + allowUnfreePackages = lhs.allowUnfreePackages ++ (lib.attrByPath [ "allowUnfreePackages" ] [ ] rhs); + } // lib.optionalAttrs (lhs ? packageOverrides) { packageOverrides = pkgs: diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix index 28de9c68110e..688429685863 100644 --- a/pkgs/stdenv/generic/check-meta.nix +++ b/pkgs/stdenv/generic/check-meta.nix @@ -158,7 +158,10 @@ let # allowUnfree = false; # allowUnfreePredicate = (x: pkgs.lib.hasPrefix "vscode" x.name); # } - allowUnfreePredicate = config.allowUnfreePredicate or (x: false); + # Defaults to allow all names defined in config.allowUnfreePackages + allowUnfreePredicate = + config.allowUnfreePredicate + or (pkg: builtins.elem (lib.getName pkg) config.allowUnfreePackages or [ ]); # Check whether unfree packages are allowed and if not, whether the # package has an unfree license and is not explicitly allowed by the diff --git a/pkgs/top-level/config.nix b/pkgs/top-level/config.nix index c8e8a3f58590..9d8f1e442c5a 100644 --- a/pkgs/top-level/config.nix +++ b/pkgs/top-level/config.nix @@ -226,6 +226,23 @@ let ''; }; + allowUnfreePackages = mkOption { + type = with lib.types; listOf str; + default = [ ]; + example = [ "ut1999" ]; + description = '' + Allows specific unfree packages to be used. + + This option composes with `nixpkgs.config.allowUnfreePredicate` by also allowing the listed package names. + + Unlike `nixpkgs.config.allowUnfreePredicate`, this option merges additively, similar to `environment.systemPackages`. + This enables defining allowed unfree packages in multiple modules, close to where they are used. + + This avoids the need to centralize all unfree package declarations or globally enable unfree packages via + `nixpkgs.config.allowUnfree = true`. + ''; + }; + allowBroken = mkOption { type = types.bool; default = false;