-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.nix
110 lines (108 loc) · 3.07 KB
/
module.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
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,
pkgs,
utils,
...
}:
let
cfg = config.services.ipwatch;
deps = map (
iface: "sys-subsystem-net-devices-${utils.escapeSystemdPath iface}.device"
) cfg.interfaces;
in
{
options.services.ipwatch = with lib; {
enable = mkEnableOption "Enable ipwatch service";
package = mkPackageOption pkgs "ipwatch" { };
extraArgs = mkOption {
type = types.listOf types.str;
default = [ ];
description = ''
Extra arguments to be passed to ipwatch.
'';
};
hooks = mkOption {
type = types.listOf types.str;
default = [ "internal:echo" ];
description = ''
Hooks to run after receiving a new IP address.
'';
};
interfaces = lib.mkOption {
type = types.listOf types.str;
default = [ ];
description = ''
Interfaces to listen for changes on.
'';
};
filters = lib.mkOption {
type = types.listOf types.str;
default = [ ];
description = ''
Filters to apply on new IP addresses that will conditionally run hooks.
'';
};
hookEnvironmentFile = lib.mkOption {
type = types.nullOr types.path;
default = null;
description = ''
File to use to set the environment for executable hooks. Each line in
this file should be of the form `KEY=VAL`.
'';
};
};
config = lib.mkIf cfg.enable {
systemd.services.ipwatch = {
enable = true;
description = "ipwatch (https://github.com/jmbaur/ipwatch)";
serviceConfig = {
LoadCredential = lib.optional (
cfg.hookEnvironmentFile != null
) "hook-environment-file:${cfg.hookEnvironmentFile}";
ExecStart = lib.escapeShellArgs (
[ "${cfg.package}/bin/ipwatch" ]
++ lib.flatten (
(map (iface: "-interface=${iface}") cfg.interfaces)
++ (map (hook: "-hook=${hook}") cfg.hooks)
++ (map (filter: "-filter=${filter}") cfg.filters)
)
++ (lib.optional (
cfg.hookEnvironmentFile != null
) "-env=\${CREDENTIALS_DIRECTORY}/hook-environment-file")
++ cfg.extraArgs
);
CapabilityBoundingSet = [ ];
DeviceAllow = [ ];
DynamicUser = true;
LockPersonality = true;
MemoryDenyWriteExecute = true;
NoNewPrivileges = true;
PrivateDevices = true;
ProtectClock = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectSystem = "strict";
RemoveIPC = true;
RestrictAddressFamilies = [
"AF_NETLINK"
"AF_INET"
"AF_INET6"
];
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SystemCallArchitectures = "native";
};
wantedBy = [ "multi-user.target" ] ++ deps;
wants = [ "network.target" ];
bindsTo = deps;
after = deps;
before = [ "network.target" ];
};
};
}