nixos/misc/nixpkgs: add setting nixpkgs.config.allowUnfreePackages = ["list" "of "packages"]
Inspired by https://github.com/NixOS/nixpkgs/issues/197325 this adds a new option nixpkgs.allowUnfreePackages, which merges additively and can thus be defined in multiple modules close to where the unfree package is installed. I would have liked ot name this option nixpkgs.config.allowUnfreePackages, to define it closer to where the allowUnfree and allowUnfreePredicate are defined, but I didn't see how this could be achived. I would welcome some guidance on how to do this.
This commit is contained in:
committed by
Martin Häcker
parent
329baca036
commit
a3c9221d64
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user