2016-02-21 06:39:24 +00:00
|
|
|
|
{ config, lib, ... }:
|
2015-07-24 10:23:52 +00:00
|
|
|
|
|
2015-07-24 18:48:00 +00:00
|
|
|
|
with builtins;
|
|
|
|
|
with lib;
|
|
|
|
|
|
2015-11-09 18:07:26 +00:00
|
|
|
|
let out = rec {
|
2015-07-24 18:48:00 +00:00
|
|
|
|
|
2015-10-14 22:55:07 +00:00
|
|
|
|
eq = x: y: x == y;
|
2016-02-01 16:30:38 +00:00
|
|
|
|
ne = x: y: x != y;
|
2015-10-14 22:55:07 +00:00
|
|
|
|
|
2015-12-26 04:55:13 +00:00
|
|
|
|
mod = x: y: x - y * (x / y);
|
|
|
|
|
|
2015-07-24 18:48:00 +00:00
|
|
|
|
addName = name: set:
|
|
|
|
|
set // { inherit name; };
|
|
|
|
|
|
|
|
|
|
addNames = mapAttrs addName;
|
2015-07-24 10:23:52 +00:00
|
|
|
|
|
2016-06-12 23:12:10 +00:00
|
|
|
|
guard = spec@{ type, value, ... }:
|
|
|
|
|
assert isOptionType type;
|
|
|
|
|
if type.check value
|
|
|
|
|
then value
|
|
|
|
|
else throw (toString (filter isString [
|
|
|
|
|
"argument"
|
|
|
|
|
(if spec ? name then "‘${spec.name}’" else null)
|
|
|
|
|
"is not a ${type.name}"
|
|
|
|
|
]));
|
|
|
|
|
|
2016-02-21 06:39:24 +00:00
|
|
|
|
types = import ./types.nix {
|
|
|
|
|
inherit config;
|
2016-03-16 00:17:07 +00:00
|
|
|
|
lib = lib // { inherit genid optionalTrace; };
|
2016-02-21 06:39:24 +00:00
|
|
|
|
};
|
2015-07-24 10:23:52 +00:00
|
|
|
|
|
2015-11-09 01:58:21 +00:00
|
|
|
|
dir.has-default-nix = path: pathExists (path + "/default.nix");
|
|
|
|
|
|
2015-12-26 04:55:13 +00:00
|
|
|
|
genid = import ./genid.nix { lib = lib // out; };
|
2016-07-23 17:17:36 +00:00
|
|
|
|
genid_signed = x: ((genid x) + 16777216) / 2;
|
2015-11-09 18:07:26 +00:00
|
|
|
|
git = import ./git.nix { lib = lib // out; };
|
2015-08-28 18:09:54 +00:00
|
|
|
|
shell = import ./shell.nix { inherit lib; };
|
2015-07-26 19:04:13 +00:00
|
|
|
|
tree = import ./tree.nix { inherit lib; };
|
2015-08-28 19:31:59 +00:00
|
|
|
|
|
2016-06-12 23:23:44 +00:00
|
|
|
|
lpad = n: c: s:
|
|
|
|
|
if stringLength s < n
|
|
|
|
|
then lpad n c (c + s)
|
|
|
|
|
else s;
|
|
|
|
|
|
2016-02-14 11:28:56 +00:00
|
|
|
|
toC = x: let
|
|
|
|
|
type = typeOf x;
|
|
|
|
|
reject = throw "cannot convert ${type}";
|
|
|
|
|
in {
|
2015-08-28 19:31:59 +00:00
|
|
|
|
list = "{ ${concatStringsSep ", " (map toC x)} }";
|
|
|
|
|
null = "NULL";
|
2016-02-14 11:28:56 +00:00
|
|
|
|
set = if isDerivation x then toJSON x else reject;
|
2015-08-28 19:31:59 +00:00
|
|
|
|
string = toJSON x; # close enough
|
2016-02-14 11:28:56 +00:00
|
|
|
|
}.${type} or reject;
|
2015-10-14 22:59:00 +00:00
|
|
|
|
|
|
|
|
|
subdirsOf = path:
|
|
|
|
|
mapAttrs (name: _: path + "/${name}")
|
|
|
|
|
(filterAttrs (_: eq "directory") (readDir path));
|
2015-11-09 17:34:02 +00:00
|
|
|
|
|
2016-06-12 23:48:59 +00:00
|
|
|
|
genAttrs' = names: f: listToAttrs (map f names);
|
|
|
|
|
|
2016-06-30 18:31:43 +00:00
|
|
|
|
getAttrs = names: set:
|
|
|
|
|
listToAttrs (map (name: nameValuePair name set.${name})
|
|
|
|
|
(filter (flip hasAttr set) names));
|
|
|
|
|
|
2015-11-09 17:34:02 +00:00
|
|
|
|
setAttr = name: value: set: set // { ${name} = value; };
|
2015-11-09 18:07:26 +00:00
|
|
|
|
|
2016-03-16 00:17:07 +00:00
|
|
|
|
optionalTrace = c: msg: x: if c then trace msg x else x;
|
|
|
|
|
|
2015-11-09 18:07:26 +00:00
|
|
|
|
}; in out
|