aboutsummaryrefslogtreecommitdiffstats
path: root/lib/default.nix
blob: bf634b66af9a936e89f02d7b78b112b84897b141 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{ nixpkgs }:
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; };
  });
}