1{ config, pkgs, lib, ... }:
2
3with lib;
4
5let
6 cfg = config.services.komga;
7
8in {
9 options = {
10 services.komga = {
11 enable = mkEnableOption (lib.mdDoc "Komga, a free and open source comics/mangas media server");
12
13 port = mkOption {
14 type = types.port;
15 default = 8080;
16 description = lib.mdDoc ''
17 The port that Komga will listen on.
18 '';
19 };
20
21 user = mkOption {
22 type = types.str;
23 default = "komga";
24 description = lib.mdDoc ''
25 User account under which Komga runs.
26 '';
27 };
28
29 group = mkOption {
30 type = types.str;
31 default = "komga";
32 description = lib.mdDoc ''
33 Group under which Komga runs.
34 '';
35 };
36
37 stateDir = mkOption {
38 type = types.str;
39 default = "/var/lib/komga";
40 description = lib.mdDoc ''
41 State and configuration directory Komga will use.
42 '';
43 };
44
45 openFirewall = mkOption {
46 type = types.bool;
47 default = false;
48 description = lib.mdDoc ''
49 Whether to open the firewall for the port in {option}`services.komga.port`.
50 '';
51 };
52 };
53 };
54
55 config = mkIf cfg.enable {
56
57 networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
58
59 users.groups = mkIf (cfg.group == "komga") {
60 komga = {};
61 };
62
63 users.users = mkIf (cfg.user == "komga") {
64 komga = {
65 group = cfg.group;
66 home = cfg.stateDir;
67 description = "Komga Daemon user";
68 isSystemUser = true;
69 };
70 };
71
72 systemd.services.komga = {
73 environment = {
74 SERVER_PORT = builtins.toString cfg.port;
75 KOMGA_CONFIGDIR = cfg.stateDir;
76 };
77
78 description = "Komga is a free and open source comics/mangas media server";
79
80 wantedBy = [ "multi-user.target" ];
81 wants = [ "network-online.target" ];
82 after = [ "network-online.target" ];
83
84 serviceConfig = {
85 User = cfg.user;
86 Group = cfg.group;
87
88 Type = "simple";
89 Restart = "on-failure";
90 ExecStart = "${pkgs.komga}/bin/komga";
91
92 StateDirectory = mkIf (cfg.stateDir == "/var/lib/komga") "komga";
93 };
94
95 };
96 };
97
98 meta.maintainers = with maintainers; [ govanify ];
99}