Skip to content

Commit

Permalink
nixos/komga: introduce 'settings' option (NixOS#345594)
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisie authored Jan 2, 2025
2 parents 06cb2dd + 3f182f3 commit c53b775
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
62 changes: 54 additions & 8 deletions nixos/modules/services/web-apps/komga.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,31 @@ let
cfg = config.services.komga;
inherit (lib) mkOption mkEnableOption maintainers;
inherit (lib.types) port str bool;

Check failure on line 11 in nixos/modules/services/web-apps/komga.nix

View workflow job for this annotation

GitHub Actions / exp-nixf-tidy-check

sema-unused-def-let

definition `port` in let-expression is not used

settingsFormat = pkgs.formats.yaml { };
in
{
imports = [
(lib.mkRenamedOptionModule
[
"services"
"komga"
"port"
]
[
"services"
"komga"
"settings"
"server"
"port"
]
)
];

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";
Expand All @@ -39,10 +52,25 @@ in
description = "State and configuration directory Komga will use.";
};

settings = lib.mkOption {
inherit (settingsFormat) type;
default = { };
defaultText = lib.literalExpression ''
{
server.port = 8080;
}
'';
description = ''
Komga configuration.
See [documentation](https://komga.org/docs/installation/configuration).
'';
};

openFirewall = mkOption {
type = bool;
default = false;
description = "Whether to open the firewall for the port in {option}`services.komga.port`.";
description = "Whether to open the firewall for the port in {option}`services.komga.settings.server.port`.";
};
};
};
Expand All @@ -52,6 +80,16 @@ in
inherit (lib) mkIf getExe;
in
mkIf cfg.enable {
assertions = [
{
assertion = (cfg.settings.komga.config-dir or cfg.stateDir) == cfg.stateDir;
message = "You must use the `services.komga.stateDir` option to properly configure `komga.config-dir`.";
}
];

services.komga.settings = {
server.port = lib.mkDefault 8080;
};

networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];

Expand All @@ -66,9 +104,17 @@ in
};
};

systemd.tmpfiles.settings."10-komga" = {
${cfg.stateDir}.d = {
inherit (cfg) user group;
};
"${cfg.stateDir}/application.yml"."L+" = {
argument = builtins.toString (settingsFormat.generate "application.yml" cfg.settings);
};
};

systemd.services.komga = {
environment = {
SERVER_PORT = builtins.toString cfg.port;
KOMGA_CONFIGDIR = cfg.stateDir;
};

Expand Down
2 changes: 1 addition & 1 deletion nixos/tests/komga.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ./make-test-python.nix ({ lib, ... }:
{ pkgs, ... }:
{ services.komga = {
enable = true;
port = 1234;
settings.server.port = 1234;
};
};

Expand Down

0 comments on commit c53b775

Please sign in to comment.