blob: d7ab2a9e612ef6765617cf0c22fc1937391f942a (
plain) (
blame)
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
111
112
113
114
115
116
117
118
119
120
121
122
|
{
config,
pkgs,
lib,
...
}:
let
cfg = config.services.komga;
inherit (lib) mkOption mkEnableOption maintainers;
inherit (lib.types) port str bool;
in
{
options = {
services.komga = {
enable = mkEnableOption "Komga, a free and open source comics/mangas media server";
port = mkOption {
type = port;
default = 8080;
description = "The port that Komga will listen on.";
};
user = mkOption {
type = str;
default = "komga";
description = "User account under which Komga runs.";
};
group = mkOption {
type = str;
default = "komga";
description = "Group under which Komga runs.";
};
stateDir = mkOption {
type = str;
default = "/var/lib/komga";
description = "State and configuration directory Komga will use.";
};
openFirewall = mkOption {
type = bool;
default = false;
description = "Whether to open the firewall for the port in {option}`services.komga.port`.";
};
};
};
config =
let
inherit (lib) mkIf getExe;
in
mkIf cfg.enable {
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
users.groups = mkIf (cfg.group == "komga") { komga = { }; };
users.users = mkIf (cfg.user == "komga") {
komga = {
group = cfg.group;
home = cfg.stateDir;
description = "Komga Daemon user";
isSystemUser = true;
};
};
systemd.services.komga = {
environment = {
SERVER_PORT = builtins.toString cfg.port;
KOMGA_CONFIGDIR = cfg.stateDir;
};
description = "Komga is a free and open source comics/mangas media server";
wantedBy = [ "multi-user.target" ];
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
serviceConfig = {
User = cfg.user;
Group = cfg.group;
Type = "simple";
Restart = "on-failure";
ExecStart = getExe pkgs.komga;
StateDirectory = mkIf (cfg.stateDir == "/var/lib/komga") "komga";
RemoveIPC = true;
NoNewPrivileges = true;
CapabilityBoundingSet = "";
SystemCallFilter = [ "@system-service" ];
ProtectSystem = "full";
PrivateTmp = true;
ProtectProc = "invisible";
ProtectClock = true;
ProcSubset = "pid";
PrivateUsers = true;
PrivateDevices = true;
ProtectHostname = true;
ProtectKernelTunables = true;
RestrictAddressFamilies = [
"AF_INET"
"AF_INET6"
"AF_NETLINK"
];
LockPersonality = true;
RestrictNamespaces = true;
ProtectKernelLogs = true;
ProtectControlGroups = true;
ProtectKernelModules = true;
SystemCallArchitectures = "native";
RestrictSUIDSGID = true;
RestrictRealtime = true;
};
};
};
meta.maintainers = with maintainers; [ govanify ];
}
|