lol

lib.options.mkPackageOption: use lib.showAttrPath (#398066)

authored by

Johannes Kirschbauer and committed by
GitHub
843af863 acc722a1

+33 -5
+6 -4
lib/options.nix
··· 30 inherit (lib.attrsets) 31 attrByPath 32 optionalAttrs 33 ; 34 inherit (lib.strings) 35 concatMapStrings ··· 40 ; 41 inherit (lib.lists) 42 last 43 ; 44 prioritySuggestion = '' 45 Use `lib.mkForce value` or `lib.mkDefault value` to change the priority on any of these definitions. ··· 310 }: 311 let 312 name' = if isList name then last name else name; 313 - default' = if isList default then default else [ default ]; 314 - defaultText = concatStringsSep "." default'; 315 defaultValue = attrByPath default' (throw "${defaultText} cannot be found in ${pkgsText}") pkgs; 316 defaults = 317 if default != null then 318 { 319 default = defaultValue; 320 - defaultText = literalExpression ("${pkgsText}." + defaultText); 321 } 322 else 323 optionalAttrs nullable { ··· 333 } 334 // optionalAttrs (example != null) { 335 example = literalExpression ( 336 - if isList example then "${pkgsText}." + concatStringsSep "." example else example 337 ); 338 } 339 );
··· 30 inherit (lib.attrsets) 31 attrByPath 32 optionalAttrs 33 + showAttrPath 34 ; 35 inherit (lib.strings) 36 concatMapStrings ··· 41 ; 42 inherit (lib.lists) 43 last 44 + toList 45 ; 46 prioritySuggestion = '' 47 Use `lib.mkForce value` or `lib.mkDefault value` to change the priority on any of these definitions. ··· 312 }: 313 let 314 name' = if isList name then last name else name; 315 + default' = toList default; 316 + defaultText = showAttrPath default'; 317 defaultValue = attrByPath default' (throw "${defaultText} cannot be found in ${pkgsText}") pkgs; 318 defaults = 319 if default != null then 320 { 321 default = defaultValue; 322 + defaultText = literalExpression "${pkgsText}.${defaultText}"; 323 } 324 else 325 optionalAttrs nullable { ··· 335 } 336 // optionalAttrs (example != null) { 337 example = literalExpression ( 338 + if isList example then "${pkgsText}.${showAttrPath example}" else example 339 ); 340 } 341 );
+13 -1
lib/tests/modules.sh
··· 315 checkConfigOutput '^"hello"$' config.package.pname ./declare-mkPackageOption.nix 316 checkConfigOutput '^"hello"$' config.namedPackage.pname ./declare-mkPackageOption.nix 317 checkConfigOutput '^".*Hello.*"$' options.namedPackage.description ./declare-mkPackageOption.nix 318 checkConfigOutput '^"hello"$' config.pathPackage.pname ./declare-mkPackageOption.nix 319 checkConfigOutput '^"pkgs\.hello\.override \{ stdenv = pkgs\.clangStdenv; \}"$' options.packageWithExample.example.text ./declare-mkPackageOption.nix 320 checkConfigOutput '^".*Example extra description\..*"$' options.packageWithExtraDescription.description ./declare-mkPackageOption.nix 321 checkConfigError 'The option .undefinedPackage. was accessed but has no value defined. Try setting the option.' config.undefinedPackage ./declare-mkPackageOption.nix 322 checkConfigOutput '^null$' config.nullablePackage ./declare-mkPackageOption.nix 323 - checkConfigOutput '^"null or package"$' options.nullablePackageWithDefault.type.description ./declare-mkPackageOption.nix 324 checkConfigOutput '^"myPkgs\.hello"$' options.packageWithPkgsText.defaultText.text ./declare-mkPackageOption.nix 325 checkConfigOutput '^"hello-other"$' options.packageFromOtherSet.default.pname ./declare-mkPackageOption.nix 326 327 # submoduleWith 328
··· 315 checkConfigOutput '^"hello"$' config.package.pname ./declare-mkPackageOption.nix 316 checkConfigOutput '^"hello"$' config.namedPackage.pname ./declare-mkPackageOption.nix 317 checkConfigOutput '^".*Hello.*"$' options.namedPackage.description ./declare-mkPackageOption.nix 318 + checkConfigOutput '^"literalExpression"$' options.namedPackage.defaultText._type ./declare-mkPackageOption.nix 319 + checkConfigOutput '^"pkgs\.hello"$' options.namedPackage.defaultText.text ./declare-mkPackageOption.nix 320 + checkConfigOutput '^"hello"$' config.namedPackageSingletonDefault.pname ./declare-mkPackageOption.nix 321 + checkConfigOutput '^".*Hello.*"$' options.namedPackageSingletonDefault.description ./declare-mkPackageOption.nix 322 + checkConfigOutput '^"pkgs\.hello"$' options.namedPackageSingletonDefault.defaultText.text ./declare-mkPackageOption.nix 323 checkConfigOutput '^"hello"$' config.pathPackage.pname ./declare-mkPackageOption.nix 324 + checkConfigOutput '^"literalExpression"$' options.packageWithExample.example._type ./declare-mkPackageOption.nix 325 checkConfigOutput '^"pkgs\.hello\.override \{ stdenv = pkgs\.clangStdenv; \}"$' options.packageWithExample.example.text ./declare-mkPackageOption.nix 326 + checkConfigOutput '^"literalExpression"$' options.packageWithPathExample.example._type ./declare-mkPackageOption.nix 327 + checkConfigOutput '^"pkgs\.hello"$' options.packageWithPathExample.example.text ./declare-mkPackageOption.nix 328 checkConfigOutput '^".*Example extra description\..*"$' options.packageWithExtraDescription.description ./declare-mkPackageOption.nix 329 checkConfigError 'The option .undefinedPackage. was accessed but has no value defined. Try setting the option.' config.undefinedPackage ./declare-mkPackageOption.nix 330 checkConfigOutput '^null$' config.nullablePackage ./declare-mkPackageOption.nix 331 + checkConfigOutput '^"null or package"$' options.nullablePackage.type.description ./declare-mkPackageOption.nix 332 + checkConfigOutput '^"hello"$' config.nullablePackageWithDefault.pname ./declare-mkPackageOption.nix 333 checkConfigOutput '^"myPkgs\.hello"$' options.packageWithPkgsText.defaultText.text ./declare-mkPackageOption.nix 334 checkConfigOutput '^"hello-other"$' options.packageFromOtherSet.default.pname ./declare-mkPackageOption.nix 335 + checkConfigOutput '^"hello"$' config.packageInvalidIdentifier.pname ./declare-mkPackageOption.nix 336 + checkConfigOutput '^"pkgs\.\\"123\\"\.\\"with\\\\\\"quote\\"\.hello"$' options.packageInvalidIdentifier.defaultText.text ./declare-mkPackageOption.nix 337 + checkConfigOutput '^"pkgs\.\\"123\\"\.\\"with\\\\\\"quote\\"\.hello"$' options.packageInvalidIdentifierExample.example.text ./declare-mkPackageOption.nix 338 339 # submoduleWith 340
+14
lib/tests/modules/declare-mkPackageOption.nix
··· 57 }; 58 in 59 lib.mkPackageOption myPkgs "hello" { }; 60 }; 61 }
··· 57 }; 58 in 59 lib.mkPackageOption myPkgs "hello" { }; 60 + 61 + packageInvalidIdentifier = 62 + let 63 + myPkgs."123"."with\"quote" = { inherit (pkgs) hello; }; 64 + in 65 + lib.mkPackageOption myPkgs [ "123" "with\"quote" "hello" ] { }; 66 + 67 + packageInvalidIdentifierExample = lib.mkPackageOption pkgs "hello" { 68 + example = [ 69 + "123" 70 + "with\"quote" 71 + "hello" 72 + ]; 73 + }; 74 }; 75 }