aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2018-06-12 22:35:07 +0200
committertv <tv@krebsco.de>2018-06-12 22:35:07 +0200
commitc8d71ce6acbae124a7bc162323442979a1d6df06 (patch)
tree45940154876a6dc54d8cfe90021947a057cb9f90
parent394590c4b35edbfbb5a503923fed0c8cbb382410 (diff)
lib.types: add pathname
-rw-r--r--lib/types.nix15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/types.nix b/lib/types.nix
index 197633e..572964a 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -20,4 +20,19 @@ rec {
check = test "([0-9A-Za-z._])[0-9A-Za-z._-]*";
merge = mergeOneOption;
};
+
+ # POSIX.1‐2013, 3.267 Pathname
+ pathname = mkOptionType {
+ name = "POSIX pathname";
+ check = x:
+ let
+ # The filter is used to normalize paths, i.e. to remove duplicated and
+ # trailing slashes. It also removes leading slashes, thus we have to
+ # check for "/" explicitly below.
+ xs = filter (s: stringLength s > 0) (splitString "/" x);
+ in
+ isString x && (x == "/" || (length xs > 0 && all filename.check xs));
+ merge = mergeOneOption;
+ };
+
}