-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.nix
96 lines (94 loc) · 2.6 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
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.ipwatch;
in
{
options.services.ipwatch = with lib; {
enable = mkEnableOption "Enable ipwatch service";
package = mkPackageOption pkgs "ipwatch" { };
hooks = mkOption {
type = types.attrsOf (
types.submodule (
{ name, ... }:
{
options = {
interface = mkOption {
type = types.str;
default = name;
description = ''
Interface to listen for changes on.
'';
};
filters = mkOption {
type = types.listOf types.str;
default = [ ];
description = ''
Filters to apply on new IP addresses that will conditionally
run hooks.
'';
};
program = mkOption {
type = types.path;
description = ''
Program to run when filter passes for changes to ''${interface}.
'';
};
};
}
)
);
default = { };
description = ''
Hooks to run after receiving a new IP address.
'';
};
};
config = lib.mkIf cfg.enable {
systemd.services.ipwatch = {
enable = true;
description = "ipwatch (https://github.com/jmbaur/ipwatch)";
before = [ "network-pre.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "notify";
ExecStart = lib.escapeShellArgs (
[ (lib.getExe cfg.package) ]
++ lib.flatten (
map (hook: "-hook=${hook.interface}:${lib.concatStringsSep "," hook.filters}:${hook.program}") (
lib.attrValues cfg.hooks
)
)
);
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_UNIX" # needed for notify support
];
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SystemCallArchitectures = "native";
};
};
};
}