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