1 { config, pkgs, lib, ... }:
4 cfg = config.services.suwayomi-server;
5 inherit (lib) mkOption mkEnableOption mkIf types;
7 format = pkgs.formats.hocon { };
11 services.suwayomi-server = {
12 enable = mkEnableOption "Suwayomi, a free and open source manga reader server that runs extensions built for Tachiyomi";
14 package = lib.mkPackageOption pkgs "suwayomi-server" { };
18 default = "/var/lib/suwayomi-server";
19 example = "/var/data/mangas";
21 The path to the data directory in which Suwayomi-Server will download scans.
30 User account under which Suwayomi-Server runs.
39 Group under which Suwayomi-Server runs.
43 openFirewall = mkOption {
47 Whether to open the firewall for the port in {option}`services.suwayomi-server.settings.server.port`.
52 type = types.submodule {
53 freeformType = format.type;
59 example = "127.0.0.1";
61 The ip that Suwayomi will bind to.
70 The port that Suwayomi will listen to.
74 basicAuthEnabled = mkEnableOption ''
75 basic access authentication for Suwayomi-Server.
76 Enabling this option is useful when hosting on a public network/the Internet
79 basicAuthUsername = mkOption {
80 type = types.nullOr types.str;
83 The username value that you have to provide when authenticating.
87 # NOTE: this is not a real upstream option
88 basicAuthPasswordFile = mkOption {
89 type = types.nullOr types.path;
91 example = "/var/secrets/suwayomi-server-password";
93 The password file containing the value that you have to provide when authenticating.
97 downloadAsCbz = mkOption {
101 Download chapters as `.cbz` files.
105 extensionRepos = mkOption {
106 type = types.listOf types.str;
109 "https://raw.githubusercontent.com/MY_ACCOUNT/MY_REPO/repo/index.min.json"
112 URL of repositories from which the extensions can be installed.
116 localSourcePath = mkOption {
118 default = cfg.dataDir;
119 defaultText = lib.literalExpression "suwayomi-server.dataDir";
120 example = "/var/data/local_mangas";
122 Path to the local source folder.
126 systemTrayEnabled = mkOption {
130 Whether to enable a system tray icon, if possible.
137 Configuration to write to {file}`server.conf`.
138 See <https://github.com/Suwayomi/Suwayomi-Server/wiki/Configuring-Suwayomi-Server> for more information.
142 server.socksProxyEnabled = true;
143 server.socksProxyHost = "yourproxyhost.com";
144 server.socksProxyPort = "8080";
150 config = mkIf cfg.enable {
153 assertion = with cfg.settings.server; basicAuthEnabled -> (basicAuthUsername != null && basicAuthPasswordFile != null);
155 [suwayomi-server]: the username and the password file cannot be null when the basic auth is enabled
159 networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.settings.server.port ];
161 users.groups = mkIf (cfg.group == "suwayomi") {
165 users.users = mkIf (cfg.user == "suwayomi") {
168 # Need to set the user home because the package writes to ~/.local/Tachidesk
170 description = "Suwayomi Daemon user";
175 systemd.tmpfiles.settings."10-suwayomi-server" = {
176 "${cfg.dataDir}/.local/share/Tachidesk".d = {
178 inherit (cfg) user group;
182 systemd.services.suwayomi-server =
184 configFile = format.generate "server.conf" (lib.pipe cfg.settings [
185 (settings: lib.recursiveUpdate settings {
186 server.basicAuthPasswordFile = null;
187 server.basicAuthPassword =
188 if settings.server.basicAuthEnabled
189 then "$TACHIDESK_SERVER_BASIC_AUTH_PASSWORD"
192 (lib.filterAttrsRecursive (_: x: x != null))
196 description = "A free and open source manga reader server that runs extensions built for Tachiyomi.";
198 wantedBy = [ "multi-user.target" ];
199 wants = [ "network-online.target" ];
200 after = [ "network-online.target" ];
203 ${lib.optionalString cfg.settings.server.basicAuthEnabled ''
204 export TACHIDESK_SERVER_BASIC_AUTH_PASSWORD="$(<${cfg.settings.server.basicAuthPasswordFile})"
206 ${lib.getExe pkgs.envsubst} -i ${configFile} -o ${cfg.dataDir}/.local/share/Tachidesk/server.conf
207 ${lib.getExe cfg.package} -Dsuwayomi.tachidesk.config.server.rootDir=${cfg.dataDir}
215 Restart = "on-failure";
217 StateDirectory = mkIf (cfg.dataDir == "/var/lib/suwayomi-server") "suwayomi-server";
223 maintainers = with lib.maintainers; [ ratcornu ];
224 doc = ./suwayomi-server.md;