From 394590c4b35edbfbb5a503923fed0c8cbb382410 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 12 Jun 2018 20:08:24 +0200 Subject: import writers from stockholm 0bc2409 --- lib/default.nix | 24 ++++++++++++++++++++++++ lib/types.nix | 23 +++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 lib/default.nix create mode 100644 lib/types.nix (limited to 'lib') diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 0000000..01d43f7 --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,24 @@ +let { + body = lib; + + lib = nixpkgs.lib // builtins // (with lib; { + genAttrs' = names: f: listToAttrs (map f names); + getAttrs = names: set: + listToAttrs (map (name: nameValuePair name set.${name}) + (filter (flip hasAttr set) names)); + toC = x: let + type = typeOf x; + reject = throw "cannot convert ${type}"; + in { + list = "{ ${concatStringsSep ", " (map toC x)} }"; + null = "NULL"; + set = if isDerivation x then toJSON x else reject; + string = toJSON x; # close enough + }.${type} or reject; + test = re: x: isString x && testString re x; + testString = re: x: match re x != null; + types = nixpkgs.lib.types // import ./types.nix { lib = body; }; + }); + + nixpkgs.lib = import ; +} diff --git a/lib/types.nix b/lib/types.nix new file mode 100644 index 0000000..197633e --- /dev/null +++ b/lib/types.nix @@ -0,0 +1,23 @@ +{ lib, ... }: +with lib; +rec { + # POSIX.1‐2013, 3.2 Absolute Pathname + absolute-pathname = mkOptionType { + name = "POSIX absolute pathname"; + check = x: isString x && substring 0 1 x == "/" && pathname.check x; + merge = mergeOneOption; + }; + + file-mode = mkOptionType { + name = "file mode"; + check = test "[0-7]{4}"; + merge = mergeOneOption; + }; + + # POSIX.1‐2013, 3.278 Portable Filename Character Set + filename = mkOptionType { + name = "POSIX filename"; + check = test "([0-9A-Za-z._])[0-9A-Za-z._-]*"; + merge = mergeOneOption; + }; +} -- cgit v1.2.3