summaryrefslogtreecommitdiff
path: root/lib/path/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'lib/path/default.nix')
-rw-r--r--lib/path/default.nix31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/path/default.nix b/lib/path/default.nix
index 24a7f85affc1..5c6c5f608954 100644
--- a/lib/path/default.nix
+++ b/lib/path/default.nix
@@ -438,6 +438,37 @@ in /* No rec! Add dependencies on this file at the top. */ {
${subpathInvalidReason path}''
) 0 subpaths;
+ /*
+ Split [a subpath](#function-library-lib.path.subpath.isValid) into its path component strings.
+ Throw an error if the subpath isn't valid.
+ Note that the returned path components are also valid subpath strings, though they are intentionally not [normalised](#function-library-lib.path.subpath.normalise).
+
+ Laws:
+
+ - Splitting a subpath into components and [joining](#function-library-lib.path.subpath.join) the components gives the same subpath but [normalised](#function-library-lib.path.subpath.normalise):
+
+ subpath.join (subpath.components s) == subpath.normalise s
+
+ Type:
+ subpath.components :: String -> [ String ]
+
+ Example:
+ subpath.components "."
+ => [ ]
+
+ subpath.components "./foo//bar/./baz/"
+ => [ "foo" "bar" "baz" ]
+
+ subpath.components "/foo"
+ => <error>
+ */
+ subpath.components =
+ subpath:
+ assert assertMsg (isValid subpath) ''
+ lib.path.subpath.components: Argument is not a valid subpath string:
+ ${subpathInvalidReason subpath}'';
+ splitRelPath subpath;
+
/* Normalise a subpath. Throw an error if the subpath isn't valid, see
`lib.path.subpath.isValid`