mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-09-11 15:08:33 +01:00
lib/options: Add mkPackageOption
This is a squashed commit. These are the original commit messages: lib/options: Add mkPackageOption lib/options: Add missing semicolon lib/options.nix: Make mkPackageOption more complicated lib/options: Fix indent. & spacing lib/options.nix: Remove example and align comment lib/options: ravenous overuse of arguments lib/options: Format better lib/options: Add default examplePath decl lib/options: Make better mkPackageOption function lib/options: Remove trailing whitespace lib/options: Improve mkPackageOptions lib/options: Remove pkgs prefixing Co-authored-by: pennae <82953136+pennae@users.noreply.github.com> lib/options: Slim down mkPackageOption further lib/options: mkPackageOption: Add "pkgs." to example lib/options: mkPackageOption: Make name & pkgs single arguments lib/options: mkPackageOption: Swap name & pkgs lib/options: Remove unnecessary import Co-authored-by: pennae <82953136+pennae@users.noreply.github.com>
This commit is contained in:
parent
f2fe7b9b52
commit
fdf7ede344
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue