summaryrefslogtreecommitdiff
path: root/module.nix
blob: cf243f97d108423c9e760bf2ed2e2de6c5ed6ae6 (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
self: {
  lib,
  flake-parts-lib,
  ...
}: let
  inherit
    (flake-parts-lib)
    mkPerSystemOption
    ;

  inherit
    (lib)
    literalExpression
    mdDoc
    mkOption
    types
    ;

  procfileSubmodule = {
    config,
    name,
    system,
    ...
  }: {
    options = {
      processes = mkOption {
        type = types.attrsOf types.str;
        default = {};
        description = mdDoc "Attribute set mapping the names of processes to their command";
        example = literalExpression ''
          {
            redis = lib.getExe' pkgs.redis "redis-server";
          }
        '';
      };

      package = mkOption {
        type = types.package;
        description = mdDoc "Final package containing runner for Procfile";
        readOnly = true;
      };
    };

    config = {
      package = self.lib.${system}.mkProcfileRunner {
        inherit name;
        procGroup = config.processes;
      };
    };
  };
in {
  options = {
    perSystem = mkPerSystemOption ({system, ...}: {
      options.procfiles = mkOption {
        type = types.attrsOf (types.submoduleWith {
          modules = [procfileSubmodule];
          specialArgs = {inherit system;};
        });

        default = {};
        description = mdDoc "Attribute set containing procfile declarations";
        example = literalExpression ''
          {
            daemons.processes = {
              redis = lib.getExe' pkgs.redis "redis-server";
          	};
          }
        '';
      };
    });
  };
}