about summary refs log tree commit diff
path: root/application/module.nix
blob: 5f0724517cff44ffbd4a94ac1dd65aecb8088c2d (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
{
  lib,
  config,
  pkgs,
  ...
}:

let
  inherit (lib)
    mkIf
    mkOption
    mkEnableOption
    mkPackageOption
    types
    ;

  cfg = config.services.specimen;
in
{
  options.services.specimen = {
    enable = mkEnableOption "specimen application";

    package = mkPackageOption pkgs "specimen" { };

    port = mkOption {
      type = types.port;
      default = 4444;
      description = "port that specimen will listen on.";
    };

    listenAddress = mkOption {
      type = types.str;
      default = "0.0.0.0";
      description = "address that specimen will listen on.";
    };

    openFirewall = mkOption {
      type = types.bool;
      default = false;
      description = "open specimen port in firewall for incoming connections.";
    };

    namePath = mkOption {
      type = types.path;
      description = "path from which specimen will get the content to reply with.";
    };
  };

  config = mkIf cfg.enable {
    networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];

    systemd.services.specimen = {
      description = "specimen application service";
      wantedBy = [ "multi-user.target" ];
      wants = [ "network.target" ];
      after = [ "network.target" ];

      serviceConfig = {
        DynamicUser = true;
        Type = "exec";
        Restart = "always";
        ExecStart = "${cfg.package}/bin/specimen -address ${cfg.listenAddress} -port ${toString cfg.port} -name ${cfg.namePath}";
      };
    };
  };
}