mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 03:23:29 +03:00
lib.options.mkPackageOption: use lib.showAttrPath (#398066)
This commit is contained in:
commit
843af863e6
3 changed files with 33 additions and 5 deletions
|
@ -30,6 +30,7 @@ let
|
||||||
inherit (lib.attrsets)
|
inherit (lib.attrsets)
|
||||||
attrByPath
|
attrByPath
|
||||||
optionalAttrs
|
optionalAttrs
|
||||||
|
showAttrPath
|
||||||
;
|
;
|
||||||
inherit (lib.strings)
|
inherit (lib.strings)
|
||||||
concatMapStrings
|
concatMapStrings
|
||||||
|
@ -40,6 +41,7 @@ let
|
||||||
;
|
;
|
||||||
inherit (lib.lists)
|
inherit (lib.lists)
|
||||||
last
|
last
|
||||||
|
toList
|
||||||
;
|
;
|
||||||
prioritySuggestion = ''
|
prioritySuggestion = ''
|
||||||
Use `lib.mkForce value` or `lib.mkDefault value` to change the priority on any of these definitions.
|
Use `lib.mkForce value` or `lib.mkDefault value` to change the priority on any of these definitions.
|
||||||
|
@ -310,14 +312,14 @@ rec {
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
name' = if isList name then last name else name;
|
name' = if isList name then last name else name;
|
||||||
default' = if isList default then default else [ default ];
|
default' = toList default;
|
||||||
defaultText = concatStringsSep "." default';
|
defaultText = showAttrPath default';
|
||||||
defaultValue = attrByPath default' (throw "${defaultText} cannot be found in ${pkgsText}") pkgs;
|
defaultValue = attrByPath default' (throw "${defaultText} cannot be found in ${pkgsText}") pkgs;
|
||||||
defaults =
|
defaults =
|
||||||
if default != null then
|
if default != null then
|
||||||
{
|
{
|
||||||
default = defaultValue;
|
default = defaultValue;
|
||||||
defaultText = literalExpression ("${pkgsText}." + defaultText);
|
defaultText = literalExpression "${pkgsText}.${defaultText}";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
optionalAttrs nullable {
|
optionalAttrs nullable {
|
||||||
|
@ -333,7 +335,7 @@ rec {
|
||||||
}
|
}
|
||||||
// optionalAttrs (example != null) {
|
// optionalAttrs (example != null) {
|
||||||
example = literalExpression (
|
example = literalExpression (
|
||||||
if isList example then "${pkgsText}." + concatStringsSep "." example else example
|
if isList example then "${pkgsText}.${showAttrPath example}" else example
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -315,14 +315,26 @@ checkConfigOutput '^false$' config.enableAlias ./alias-with-priority-can-overrid
|
||||||
checkConfigOutput '^"hello"$' config.package.pname ./declare-mkPackageOption.nix
|
checkConfigOutput '^"hello"$' config.package.pname ./declare-mkPackageOption.nix
|
||||||
checkConfigOutput '^"hello"$' config.namedPackage.pname ./declare-mkPackageOption.nix
|
checkConfigOutput '^"hello"$' config.namedPackage.pname ./declare-mkPackageOption.nix
|
||||||
checkConfigOutput '^".*Hello.*"$' options.namedPackage.description ./declare-mkPackageOption.nix
|
checkConfigOutput '^".*Hello.*"$' options.namedPackage.description ./declare-mkPackageOption.nix
|
||||||
|
checkConfigOutput '^"literalExpression"$' options.namedPackage.defaultText._type ./declare-mkPackageOption.nix
|
||||||
|
checkConfigOutput '^"pkgs\.hello"$' options.namedPackage.defaultText.text ./declare-mkPackageOption.nix
|
||||||
|
checkConfigOutput '^"hello"$' config.namedPackageSingletonDefault.pname ./declare-mkPackageOption.nix
|
||||||
|
checkConfigOutput '^".*Hello.*"$' options.namedPackageSingletonDefault.description ./declare-mkPackageOption.nix
|
||||||
|
checkConfigOutput '^"pkgs\.hello"$' options.namedPackageSingletonDefault.defaultText.text ./declare-mkPackageOption.nix
|
||||||
checkConfigOutput '^"hello"$' config.pathPackage.pname ./declare-mkPackageOption.nix
|
checkConfigOutput '^"hello"$' config.pathPackage.pname ./declare-mkPackageOption.nix
|
||||||
|
checkConfigOutput '^"literalExpression"$' options.packageWithExample.example._type ./declare-mkPackageOption.nix
|
||||||
checkConfigOutput '^"pkgs\.hello\.override \{ stdenv = pkgs\.clangStdenv; \}"$' options.packageWithExample.example.text ./declare-mkPackageOption.nix
|
checkConfigOutput '^"pkgs\.hello\.override \{ stdenv = pkgs\.clangStdenv; \}"$' options.packageWithExample.example.text ./declare-mkPackageOption.nix
|
||||||
|
checkConfigOutput '^"literalExpression"$' options.packageWithPathExample.example._type ./declare-mkPackageOption.nix
|
||||||
|
checkConfigOutput '^"pkgs\.hello"$' options.packageWithPathExample.example.text ./declare-mkPackageOption.nix
|
||||||
checkConfigOutput '^".*Example extra description\..*"$' options.packageWithExtraDescription.description ./declare-mkPackageOption.nix
|
checkConfigOutput '^".*Example extra description\..*"$' options.packageWithExtraDescription.description ./declare-mkPackageOption.nix
|
||||||
checkConfigError 'The option .undefinedPackage. was accessed but has no value defined. Try setting the option.' config.undefinedPackage ./declare-mkPackageOption.nix
|
checkConfigError 'The option .undefinedPackage. was accessed but has no value defined. Try setting the option.' config.undefinedPackage ./declare-mkPackageOption.nix
|
||||||
checkConfigOutput '^null$' config.nullablePackage ./declare-mkPackageOption.nix
|
checkConfigOutput '^null$' config.nullablePackage ./declare-mkPackageOption.nix
|
||||||
checkConfigOutput '^"null or package"$' options.nullablePackageWithDefault.type.description ./declare-mkPackageOption.nix
|
checkConfigOutput '^"null or package"$' options.nullablePackage.type.description ./declare-mkPackageOption.nix
|
||||||
|
checkConfigOutput '^"hello"$' config.nullablePackageWithDefault.pname ./declare-mkPackageOption.nix
|
||||||
checkConfigOutput '^"myPkgs\.hello"$' options.packageWithPkgsText.defaultText.text ./declare-mkPackageOption.nix
|
checkConfigOutput '^"myPkgs\.hello"$' options.packageWithPkgsText.defaultText.text ./declare-mkPackageOption.nix
|
||||||
checkConfigOutput '^"hello-other"$' options.packageFromOtherSet.default.pname ./declare-mkPackageOption.nix
|
checkConfigOutput '^"hello-other"$' options.packageFromOtherSet.default.pname ./declare-mkPackageOption.nix
|
||||||
|
checkConfigOutput '^"hello"$' config.packageInvalidIdentifier.pname ./declare-mkPackageOption.nix
|
||||||
|
checkConfigOutput '^"pkgs\.\\"123\\"\.\\"with\\\\\\"quote\\"\.hello"$' options.packageInvalidIdentifier.defaultText.text ./declare-mkPackageOption.nix
|
||||||
|
checkConfigOutput '^"pkgs\.\\"123\\"\.\\"with\\\\\\"quote\\"\.hello"$' options.packageInvalidIdentifierExample.example.text ./declare-mkPackageOption.nix
|
||||||
|
|
||||||
# submoduleWith
|
# submoduleWith
|
||||||
|
|
||||||
|
|
|
@ -57,5 +57,19 @@ in
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
lib.mkPackageOption myPkgs "hello" { };
|
lib.mkPackageOption myPkgs "hello" { };
|
||||||
|
|
||||||
|
packageInvalidIdentifier =
|
||||||
|
let
|
||||||
|
myPkgs."123"."with\"quote" = { inherit (pkgs) hello; };
|
||||||
|
in
|
||||||
|
lib.mkPackageOption myPkgs [ "123" "with\"quote" "hello" ] { };
|
||||||
|
|
||||||
|
packageInvalidIdentifierExample = lib.mkPackageOption pkgs "hello" {
|
||||||
|
example = [
|
||||||
|
"123"
|
||||||
|
"with\"quote"
|
||||||
|
"hello"
|
||||||
|
];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue