summaryrefslogtreecommitdiffstats
path: root/krebs/3modules/build.nix
blob: 0f8aec89d7a32575c25999f994819522d1cb5bdc (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
{ config, lib, ... }:

with lib;

let
  target = config.krebs.build // { user.name = "root"; };

  out = {
    # TODO deprecate krebs.build.host
    options.krebs.build.host = mkOption {
      type = types.host;
    };

    # TODO make krebs.build.profile shell safe
    options.krebs.build.profile = mkOption {
      type = types.str;
      default = "/nix/var/nix/profiles/system";
    };

    # TODO make krebs.build.target.host :: host
    options.krebs.build.target = mkOption {
      type = with types; nullOr str;
      default = null;
    };

    # TODO deprecate krebs.build.user
    options.krebs.build.user = mkOption {
      type = types.user;
    };

    options.krebs.build.source-version = mkOption {
      type = types.enum [ 1 2 ];
      default = 1;
    };

    options.krebs.build.source = getAttr "v${toString config.krebs.build.source-version}" {
      v1 = {
        dir = mkOption {
          type = let
            default-host = config.krebs.current.host;
          in types.attrsOf (types.submodule ({ config, ... }: {
            options = {
              host = mkOption {
                type = types.host;
                default = default-host;
              };
              path = mkOption {
                type = types.str;
              };
              target-path = mkOption {
                type = types.str;
                default = "/root/${config._module.args.name}";
              };
              url = mkOption {
                type = types.str;
                default = "file://${config.host.name}${config.path}";
              };
            };
          }));
          default = {};
        };

        git = mkOption {
          type = with types; attrsOf (submodule ({ config, ... }: {
            options = {
              url = mkOption {
                type = types.str; # TODO must be shell safe
              };
              rev = mkOption {
                type = types.str;
              };
              target-path = mkOption {
                type = types.str;
                default = "/root/${config._module.args.name}";
              };
            };
          }));
          default = {};
        };
      };

      v2 = let
        raw = types.either types.str types.path;
        url = types.submodule {
          options = {
            url = mkOption {
              type = types.str;
            };
            rev = mkOption {
              type = types.str;
            };
            dev = mkOption {
              type = types.str;
            };
          };
        };
      in mkOption {
        type = types.attrsOf (types.either types.str url);
        apply = let f = mapAttrs (_: value: {
          string = value;
          path = toString value;
          set = f value;
        }.${typeOf value}); in f;
        default = {};
      };
    };

  };

in out