summaryrefslogtreecommitdiffstats
path: root/krebs/4lib/default.nix
blob: 396307c22a1276e8a20b8c0d95beb7fd985b51b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{ lib, ... }:

with builtins;
with lib;

rec {

  eq = x: y: x == y;

  addName = name: set:
    set // { inherit name; };

  addNames = mapAttrs addName;

  types = import ./types.nix { inherit lib; };

  dns = import ./dns.nix { inherit lib; };
  listset = import ./listset.nix { inherit lib; };
  shell = import ./shell.nix { inherit lib; };
  tree = import ./tree.nix { inherit lib; };

  toC = x: {
    list = "{ ${concatStringsSep ", " (map toC x)} }";
    null = "NULL";
    string = toJSON x; # close enough
  }.${typeOf x};

  subdirsOf = path:
    mapAttrs (name: _: path + "/${name}")
             (filterAttrs (_: eq "directory") (readDir path));
}