summaryrefslogtreecommitdiffstats
path: root/lib/default.nix
diff options
context:
space:
mode:
authorlassulus <lass@aidsballs.de>2016-10-20 21:19:26 +0200
committerlassulus <lass@aidsballs.de>2016-10-20 21:19:26 +0200
commit5cfe3f414097a16dfa84cd52739689e08b7fa0b3 (patch)
tree81ef0820be1d91961f18f2e75e2d9172bf865093 /lib/default.nix
parent51a9fb2dccf6996e1f4fe6f795076ebc6bc71d25 (diff)
parentf47bab7f710b7c8a282c3a3c38affc8a0bc30cc9 (diff)
Merge remote-tracking branch 'cd/master'
Diffstat (limited to 'lib/default.nix')
-rw-r--r--lib/default.nix36
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/default.nix b/lib/default.nix
index 1f5010853..2b12fa4bf 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -1,10 +1,44 @@
let
- lib = import <nixpkgs/lib> // builtins // {
+ nixpkgs-lib = import <nixpkgs/lib>;
+ lib = with lib; nixpkgs-lib // builtins // {
+ git = import ./git.nix { inherit lib; };
shell = import ./shell.nix { inherit lib; };
+ types = nixpkgs-lib.types // import ./types.nix { inherit lib; };
eq = x: y: x == y;
ne = x: y: x != y;
mod = x: y: x - y * (x / y);
+
+ genid = import ./genid.nix { inherit lib; };
+ genid_signed = x: ((lib.genid x) + 16777216) / 2;
+
+ lpad = n: c: s:
+ if lib.stringLength s < n
+ then lib.lpad n c (c + s)
+ else s;
+
+ subdirsOf = path:
+ lib.mapAttrs (name: _: path + "/${name}")
+ (filterAttrs (_: eq "directory") (readDir path));
+
+ genAttrs' = names: f: listToAttrs (map f names);
+
+ getAttrs = names: set:
+ listToAttrs (map (name: nameValuePair name set.${name})
+ (filter (flip hasAttr set) names));
+
+ setAttr = name: value: set: set // { ${name} = value; };
+
+ 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;
+
};
in