nixpkgs/nixos/modules/services/web-apps/komga.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

123 lines
3.1 KiB
Nix
Raw Normal View History

{
config,
pkgs,
lib,
...
}:
2022-08-12 21:52:52 +00:00
let
cfg = config.services.komga;
inherit (lib) mkOption mkEnableOption maintainers;
inherit (lib.types) port str bool;
in
{
2022-08-12 21:52:52 +00:00
options = {
services.komga = {
enable = mkEnableOption "Komga, a free and open source comics/mangas media server";
2022-08-12 21:52:52 +00:00
port = mkOption {
type = port;
2022-08-12 21:52:52 +00:00
default = 8080;
description = "The port that Komga will listen on.";
2022-08-12 21:52:52 +00:00
};
user = mkOption {
type = str;
2022-08-12 21:52:52 +00:00
default = "komga";
description = "User account under which Komga runs.";
2022-08-12 21:52:52 +00:00
};
group = mkOption {
type = str;
2022-08-12 21:52:52 +00:00
default = "komga";
description = "Group under which Komga runs.";
2022-08-12 21:52:52 +00:00
};
stateDir = mkOption {
type = str;
2022-08-12 21:52:52 +00:00
default = "/var/lib/komga";
description = "State and configuration directory Komga will use.";
2022-08-12 21:52:52 +00:00
};
openFirewall = mkOption {
type = bool;
2022-08-12 21:52:52 +00:00
default = false;
description = "Whether to open the firewall for the port in {option}`services.komga.port`.";
2022-08-12 21:52:52 +00:00
};
};
};
config =
let
2024-03-01 02:12:45 +00:00
inherit (lib) mkIf getExe;
in
mkIf cfg.enable {
2022-08-12 21:52:52 +00:00
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
2022-08-12 21:52:52 +00:00
users.groups = mkIf (cfg.group == "komga") { komga = { }; };
2022-08-12 21:52:52 +00:00
users.users = mkIf (cfg.user == "komga") {
komga = {
group = cfg.group;
home = cfg.stateDir;
description = "Komga Daemon user";
isSystemUser = true;
};
2022-08-12 21:52:52 +00:00
};
systemd.services.komga = {
environment = {
SERVER_PORT = builtins.toString cfg.port;
KOMGA_CONFIGDIR = cfg.stateDir;
};
2022-08-12 21:52:52 +00:00
description = "Komga is a free and open source comics/mangas media server";
2022-08-12 21:52:52 +00:00
wantedBy = [ "multi-user.target" ];
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
2022-08-12 21:52:52 +00:00
serviceConfig = {
User = cfg.user;
Group = cfg.group;
2022-08-12 21:52:52 +00:00
Type = "simple";
Restart = "on-failure";
2024-03-01 02:12:45 +00:00
ExecStart = getExe pkgs.komga;
2022-08-12 21:52:52 +00:00
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;
};
2022-08-12 21:52:52 +00:00
};
};
meta.maintainers = with maintainers; [ govanify ];
}