about summary refs log tree commit diff
path: root/lib/default.nix
blob: d121f5e8b3606b44b2802ff56d2948b63d8e0992 (plain) (blame)
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
32
33
34
35
36
37
38
39
40
lib: _: rec {
  my = import ./my.nix lib;

  dns = import ./dns.nix lib;

  isEven = number:
    assert (builtins.isInt number) || (builtins.isFloat number);
      builtins.div number 2 == 0;

  isOdd = !isEven;

  pow = base: exponent:
    assert (builtins.isInt base) && (builtins.isInt exponent);
    assert exponent > 0;
      builtins.foldl' (x: _: x * base) 1 (builtins.genList _ exponent);

  comcat = builtins.concatStringsSep ",";

  mapListToAttrs = f: xs:
    builtins.listToAttrs (map (name: {
        name =
          if builtins.isList name
          then builtins.elemAt name (builtins.length name - 1)
          else name;
        value = f name;
      })
      xs);

  mkTcpMem = min: ini: max:
    assert min <= ini && ini <= max;
      lib.concatMapStrings (x: toString x + " ") (map (pow 2) [min ini max]);

  # TODO Move this somehow to the NGINX module itself.
  nginxInternalOnly = ''
    if ($internal != 1) {
      return 403;
    }
    access_log off;
  '';
}

Consider giving Nix/NixOS a try! <3