diff --git a/lib/types.nix b/lib/types.nix index d27d5750dfab..ddd37f260c9a 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -461,6 +461,7 @@ rec { # - strings with context, e.g. "${pkgs.foo}" or (toString pkgs.foo) # - hardcoded store path literals (/nix/store/hash-foo) or strings without context # ("/nix/store/hash-foo"). These get a context added to them using builtins.storePath. + # If you don't need a *top-level* store path, consider using pathInStore instead. package = mkOptionType { name = "package"; descriptionClass = "noun"; @@ -491,6 +492,14 @@ rec { merge = mergeEqualOption; }; + pathInStore = mkOptionType { + name = "pathInStore"; + description = "path in the Nix store"; + descriptionClass = "noun"; + check = x: isStringLike x && builtins.match "${builtins.storeDir}/[^.].*" (toString x) != null; + merge = mergeEqualOption; + }; + listOf = elemType: mkOptionType rec { name = "listOf"; description = "list of ${optionDescriptionPhrase (class: class == "noun" || class == "composite") elemType}"; diff --git a/nixos/doc/manual/development/option-types.section.md b/nixos/doc/manual/development/option-types.section.md index 9e156ebff9d3..44bb3b4782e1 100644 --- a/nixos/doc/manual/development/option-types.section.md +++ b/nixos/doc/manual/development/option-types.section.md @@ -20,6 +20,11 @@ merging is handled. coerced to a string. Even if derivations can be considered as paths, the more specific `types.package` should be preferred. +`types.pathInStore` + +: A path that is contained in the Nix store. This can be a top-level store + path like `pkgs.hello` or a descendant like `"${pkgs.hello}/bin/hello"`. + `types.package` : A top-level store path. This can be an attribute set pointing