lib/types: add pathInStore

This commit is contained in:
Naïm Favier 2023-06-12 13:02:00 +02:00
parent 2e7efc14f2
commit 14d3e5685a
No known key found for this signature in database
GPG Key ID: 95AFCE8211908325
2 changed files with 14 additions and 0 deletions

View File

@ -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}";

View File

@ -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