-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathos.nix
105 lines (104 loc) · 3.76 KB
/
os.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
self: {config, lib, pkgs, ...}: let
name = "insidious";
displayName = "Insidious";
cfg = config.services.${name};
in {
options.services.${name} = {
enable = lib.mkEnableOption false;
package = lib.mkOption {
type = with lib.types; nullOr package;
description = ''The ${displayName} package to use.'';
default = self.packages.${pkgs.system}.default;
};
address = lib.mkOption {
type = with lib.types; str;
description = "The IP address ${displayName} should bind to.";
default = "127.0.0.1";
};
port = lib.mkOption {
type = with lib.types; port;
description = ''The port ${displayName} should listen on.'';
default = 3030;
};
openFirewall = lib.mkOption {
type = with lib.types; bool;
description = "Open ports in the firewall for ${displayName}.";
default = false;
};
user = lib.mkOption {
type = with lib.types; str;
default = name;
description = "User account under which ${displayName} runs.";
};
group = lib.mkOption {
type = with lib.types; str;
default = name;
description = "Group under which ${displayName} runs.";
};
home = lib.mkOption {
type = with lib.types; path;
default = "/var/lib/${name}";
description = ''
Directory where ${displayName} will keep its application data.
'';
};
};
config = lib.mkIf cfg.enable {
systemd.services.${name} = rec {
description = "${displayName} YouTube front-end";
wantedBy = ["multi-user.target"];
wants = ["network-online.target"];
after = wants;
script = ''
${lib.getExe cfg.package} ${cfg.address} ${toString cfg.port}
'';
serviceConfig = {
User = cfg.user;
Group = cfg.group;
CapabilityBoundingSet = "";
LockPersonality = true;
MemoryDenyWriteExecute = true;
NoNewPrivileges = true;
PrivateDevices = true;
PrivateMounts = true;
PrivateTmp = true;
PrivateUsers = true;
ProtectClock = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectProc = "invisible";
ProtectSystem = "strict";
ReadWritePaths = [cfg.home];
RemoveIPC = true;
RestrictAddressFamilies = ["AF_UNIX" "AF_INET" "AF_INET6"];
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SystemCallArchitectures = "native";
SystemCallFilter = [
"@system-service" "~@privileged" "~@resources"
];
};
};
users.users = lib.optionalAttrs (cfg.user == name) ({
${name} = {
group = cfg.group;
description = "${displayName} runner user";
home = cfg.home;
createHome = true;
isSystemUser = true;
};
});
users.groups = lib.optionalAttrs (cfg.group == name) ({
${name} = {};
});
networking.firewall = lib.mkIf cfg.openFirewall rec {
allowedTCPPorts = [cfg.port];
allowedUDPPorts = allowedTCPPorts;
};
};
}