summaryrefslogtreecommitdiff
path: root/nixos/modules/sentinel-minipot.nix
blob: 8dcf370c78079141fe3f45cefba1bf3166157101 (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
{ config, lib, pkgs, ... }:

with lib;

let

  cnf = config.sentinel.minipot;
  inherit (pkgs) sentinel-minipot;

  minipotOpts = { name, port }: {
    enable = mkOption {
      type = types.bool;
      default = true;
      description = ''
        Whether to enable the Turris Sentinel ${name} Minipot.
        The services.sentinel.enable and service.sentinel.minipot.enable have to be enabled as well.
      '';
    };
    port = mkOption {
      type = types.port;
      default = port;
      description = "The port ${name} minipot should bind to.";
    };
  };

in {

  imports = [ ./sentinel.nix ];

  options = {
    services.sentinel.minipot = {
      enable = mkOption {
        type = types.bool;
        default = true;
        description = ''
          Whether to enable the Turris Sentinel Minipot system.
          The services.sentinel.enable has to be enabled as well.
        '';
      };

      http = minipotOpts { name = "HTTP"; port = 8033; };
      ftp = minipotOpts { name = "FTP"; port = 2133; };
      smtp = minipotOpts { name = "SMTP"; port = 5873; };
      telnet = minipotOpts { name = "Telnet"; port = 2333; };
    };
  };


  config = mkIf (config.services.sentinel.enable && cnf.enable) {
    assertions = [
      {
        assertion = cnf.http.enable || cnf.ftp.enable || cnf.smtp.enable || cnf.telnet.enable;
        message = "Sentinel minipot requires at least one of the protocols to be enabled";
      }
    ];

    environment.systemPackages = [ sentinel-minipot ];

    systemd.services.sentinel-minipot = {
      description = "Turris Sentinel Minipot";
      wantedBy = [ "multi-user.target" ];
      path = [ sentinel-minipot ];
      serviceConfig.ExecStart = "${sentinel-minipot}/bin/sentinel-minipot"
        + optionalString cnf.http.enable " --http=${cnf.http.port}"
        + optionalString cnf.ftp.enable " --ftp=${cnf.ftp.port}"
        + optionalString cnf.smtp.enable " --smtp=${cnf.smtp.port}"
        + optionalString cnf.telnet.enable " --telnet=${cnf.telnet.port}";
    };

  };

}