lol

lib.options.mkPackageOption: use lib.showAttrPath

Make use of `lib.showAttrPath` instead of manually doing `concatStringsSep "."`.

This means edge-cases such as the attr-path including names that are not
valid nix identifiers will be handled better.

See:
- https://nix.dev/manual/nix/2.26/language/identifiers
- https://nixos.org/manual/nixpkgs/unstable/#function-library-lib.attrsets.showAttrPath

+23 -4
+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 );
+3
lib/tests/modules.sh
··· 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 336 # submoduleWith 337
··· 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 }