2016-02-21 07:39:24 +01:00
|
|
|
{ config, lib, ... }:
|
2015-07-24 12:23:52 +02:00
|
|
|
|
2015-07-24 20:48:00 +02:00
|
|
|
with builtins;
|
|
|
|
with lib;
|
|
|
|
|
2015-11-09 19:07:26 +01:00
|
|
|
let out = rec {
|
2015-07-24 20:48:00 +02:00
|
|
|
|
2015-10-15 00:55:07 +02:00
|
|
|
eq = x: y: x == y;
|
2016-02-01 17:30:38 +01:00
|
|
|
ne = x: y: x != y;
|
2015-10-15 00:55:07 +02:00
|
|
|
|
2015-12-26 05:55:13 +01:00
|
|
|
mod = x: y: x - y * (x / y);
|
|
|
|
|
2015-07-24 20:48:00 +02:00
|
|
|
addName = name: set:
|
|
|
|
set // { inherit name; };
|
|
|
|
|
|
|
|
addNames = mapAttrs addName;
|
2015-07-24 12:23:52 +02:00
|
|
|
|
2016-02-21 07:39:24 +01:00
|
|
|
types = import ./types.nix {
|
|
|
|
inherit config;
|
2016-03-16 01:17:07 +01:00
|
|
|
lib = lib // { inherit genid optionalTrace; };
|
2016-02-21 07:39:24 +01:00
|
|
|
};
|
2015-07-24 12:23:52 +02:00
|
|
|
|
2015-11-09 02:58:21 +01:00
|
|
|
dir.has-default-nix = path: pathExists (path + "/default.nix");
|
|
|
|
|
2015-12-26 05:55:13 +01:00
|
|
|
genid = import ./genid.nix { lib = lib // out; };
|
2015-11-09 19:07:26 +01:00
|
|
|
git = import ./git.nix { lib = lib // out; };
|
2015-08-28 20:09:54 +02:00
|
|
|
shell = import ./shell.nix { inherit lib; };
|
2015-07-26 21:04:13 +02:00
|
|
|
tree = import ./tree.nix { inherit lib; };
|
2015-08-28 21:31:59 +02:00
|
|
|
|
2016-02-14 12:28:56 +01:00
|
|
|
toC = x: let
|
|
|
|
type = typeOf x;
|
|
|
|
reject = throw "cannot convert ${type}";
|
|
|
|
in {
|
2015-08-28 21:31:59 +02:00
|
|
|
list = "{ ${concatStringsSep ", " (map toC x)} }";
|
|
|
|
null = "NULL";
|
2016-02-14 12:28:56 +01:00
|
|
|
set = if isDerivation x then toJSON x else reject;
|
2015-08-28 21:31:59 +02:00
|
|
|
string = toJSON x; # close enough
|
2016-02-14 12:28:56 +01:00
|
|
|
}.${type} or reject;
|
2015-10-15 00:59:00 +02:00
|
|
|
|
|
|
|
subdirsOf = path:
|
|
|
|
mapAttrs (name: _: path + "/${name}")
|
|
|
|
(filterAttrs (_: eq "directory") (readDir path));
|
2015-11-09 18:34:02 +01:00
|
|
|
|
|
|
|
setAttr = name: value: set: set // { ${name} = value; };
|
2015-11-09 19:07:26 +01:00
|
|
|
|
2016-03-16 01:17:07 +01:00
|
|
|
optionalTrace = c: msg: x: if c then trace msg x else x;
|
|
|
|
|
2015-11-09 19:07:26 +01:00
|
|
|
}; in out
|