mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 03:23:29 +03:00
lib/options: refactor mkPackageOption
This commit is contained in:
parent
55ab538abf
commit
7e24b3619f
1 changed files with 13 additions and 13 deletions
|
@ -201,21 +201,21 @@ rec {
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
name' = if isList name then last name else name;
|
name' = if isList name then last name else name;
|
||||||
in mkOption ({
|
default' = if isList default then default else [ default ];
|
||||||
type = with lib.types; (if nullable then nullOr else lib.id) package;
|
defaultText = concatStringsSep "." default';
|
||||||
|
defaultValue = attrByPath default'
|
||||||
|
(throw "${defaultText} cannot be found in ${pkgsText}") pkgs;
|
||||||
|
defaults = if default != null then {
|
||||||
|
default = defaultValue;
|
||||||
|
defaultText = literalExpression ("${pkgsText}." + defaultText);
|
||||||
|
} else optionalAttrs nullable {
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
in mkOption (defaults // {
|
||||||
description = "The ${name'} package to use."
|
description = "The ${name'} package to use."
|
||||||
+ (if extraDescription == "" then "" else " ") + extraDescription;
|
+ (if extraDescription == "" then "" else " ") + extraDescription;
|
||||||
} // (if default != null then let
|
type = with lib.types; (if nullable then nullOr else lib.id) package;
|
||||||
default' = if isList default then default else [ default ];
|
} // optionalAttrs (example != null) {
|
||||||
defaultPath = concatStringsSep "." default';
|
|
||||||
defaultValue = attrByPath default'
|
|
||||||
(throw "${defaultPath} cannot be found in ${pkgsText}") pkgs;
|
|
||||||
in {
|
|
||||||
default = defaultValue;
|
|
||||||
defaultText = literalExpression ("${pkgsText}." + defaultPath);
|
|
||||||
} else if nullable then {
|
|
||||||
default = null;
|
|
||||||
} else { }) // lib.optionalAttrs (example != null) {
|
|
||||||
example = literalExpression
|
example = literalExpression
|
||||||
(if isList example then "${pkgsText}." + concatStringsSep "." example else example);
|
(if isList example then "${pkgsText}." + concatStringsSep "." example else example);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue