-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwarp-systemd-example.nix
60 lines (55 loc) · 1.53 KB
/
warp-systemd-example.nix
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
/*
A NixOS module that runs the example from the ../example directory as a
systemd system service.
*/
{ lib, config, ... }:
let
cfg = config.services.warp-systemd-example;
in
{
options = {
services.warp-systemd-example = {
enable = lib.mkEnableOption "Example service";
port = lib.mkOption {
type = lib.types.int;
default = 80;
description = "Port to listen on";
};
package = lib.mkOption {
type = lib.types.package;
# If you publish to hackage, perhaps add the default.
# In any case, this is set in the flake and/or test.
# default = pkgs.haskellPackages.warp-systemd-example;
description = "Example service package to run";
};
openFirewall = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Open the firewall for the port";
};
};
};
config = lib.mkIf cfg.enable {
systemd.sockets.warp-systemd-example = {
wantedBy = [ "sockets.target" ];
socketConfig = {
ListenStream = "${toString cfg.port}";
Accept = "no";
};
};
systemd.services.warp-systemd-example = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
ExecStart = lib.getExe cfg.package;
Restart = "always";
KillSignal = "SIGINT";
Type = "notify";
WatchdogSec = "15";
};
};
networking.firewall = lib.mkIf cfg.openFirewall {
allowedTCPPorts = [ cfg.port ];
};
};
}