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 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 );
+3
lib/tests/modules.sh
··· 332 332 checkConfigOutput '^"hello"$' config.nullablePackageWithDefault.pname ./declare-mkPackageOption.nix 333 333 checkConfigOutput '^"myPkgs\.hello"$' options.packageWithPkgsText.defaultText.text ./declare-mkPackageOption.nix 334 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 335 338 336 339 # submoduleWith 337 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 }