diff options
Diffstat (limited to 'lib/options.nix')
-rw-r--r-- | lib/options.nix | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/options.nix b/lib/options.nix index 53001a3113f93..b3a011168c3b0 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -26,6 +26,7 @@ let take ; inherit (lib.attrsets) + attrByPath optionalAttrs ; inherit (lib.strings) @@ -99,6 +100,24 @@ rec { type = lib.types.bool; }; + /* Creaties an Option attribute set for an option that specifies the + package a module should use. + + The argument default is an attribute set path in pkgs. + */ + mkPackageOption = pkgs: name: + { default ? [ name ], example ? null }: + let default' = if !isList default then [ default ] else default; + in mkOption { + type = lib.types.package; + description = "The ${name} package to use."; + default = attrByPath default' + (throw "${concatStringsSep "." default'} cannot be found in pkgs") pkgs; + defaultText = literalExpression ("pkgs." + concatStringsSep "." default'); + ${if example != null then "example" else null} = literalExpression + (if isList example then "pkgs." + concatStringsSep "." example else example); + }; + /* This option accepts anything, but it does not produce any result. This is useful for sharing a module across different module sets |