2015-09-27 20:31:17 -07:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.calibre-server;
|
|
|
|
|
2023-06-28 14:06:47 +02:00
|
|
|
documentationLink = "https://manual.calibre-ebook.com";
|
|
|
|
generatedDocumentationLink = documentationLink + "/generated/en/calibre-server.html";
|
|
|
|
|
2024-08-24 22:05:39 +02:00
|
|
|
execFlags = (
|
|
|
|
lib.concatStringsSep " " (
|
|
|
|
lib.mapAttrsToList (k: v: "${k} ${toString v}") (
|
|
|
|
lib.filterAttrs (name: value: value != null) {
|
2023-06-28 14:06:47 +02:00
|
|
|
"--listen-on" = cfg.host;
|
|
|
|
"--port" = cfg.port;
|
|
|
|
"--auth-mode" = cfg.auth.mode;
|
|
|
|
"--userdb" = cfg.auth.userDb;
|
2024-10-23 09:55:28 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
++ [ (lib.optionalString (cfg.auth.enable == true) "--enable-auth") ]
|
|
|
|
++ cfg.extraFlags
|
|
|
|
)
|
2023-06-28 14:06:47 +02:00
|
|
|
);
|
2015-09-27 20:31:17 -07:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2020-05-15 17:53:07 +02:00
|
|
|
imports = [
|
2024-08-24 22:05:39 +02:00
|
|
|
(lib.mkChangedOptionModule
|
|
|
|
[ "services" "calibre-server" "libraryDir" ]
|
|
|
|
[ "services" "calibre-server" "libraries" ]
|
2020-05-15 17:53:07 +02:00
|
|
|
(
|
|
|
|
config:
|
2024-08-24 22:05:39 +02:00
|
|
|
let
|
|
|
|
libraryDir = lib.getAttrFromPath [ "services" "calibre-server" "libraryDir" ] config;
|
2020-05-15 17:53:07 +02:00
|
|
|
in
|
|
|
|
[ libraryDir ]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
];
|
2015-09-27 20:31:17 -07:00
|
|
|
|
|
|
|
options = {
|
|
|
|
services.calibre-server = {
|
|
|
|
|
2024-08-24 22:05:39 +02:00
|
|
|
enable = lib.mkEnableOption "calibre-server (e-book software)";
|
2023-11-30 19:03:14 +01:00
|
|
|
package = lib.mkPackageOption pkgs "calibre" { };
|
2015-09-27 20:31:17 -07:00
|
|
|
|
2024-08-24 22:05:39 +02:00
|
|
|
libraries = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.path;
|
2023-06-28 14:06:47 +02:00
|
|
|
default = [ "/var/lib/calibre-server" ];
|
2015-09-27 20:31:17 -07:00
|
|
|
description = ''
|
2023-06-28 14:06:47 +02:00
|
|
|
Make sure each library path is initialized before service startup.
|
2020-05-15 17:53:07 +02:00
|
|
|
The directories of the libraries to serve. They must be readable for the user under which the server runs.
|
2023-06-28 14:06:47 +02:00
|
|
|
See the [calibredb documentation](${documentationLink}/generated/en/calibredb.html#add) for details.
|
2020-05-15 17:53:07 +02:00
|
|
|
'';
|
2015-09-27 20:31:17 -07:00
|
|
|
};
|
|
|
|
|
2024-10-23 09:55:28 -04:00
|
|
|
extraFlags = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.str;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
Extra flags to pass to the calibre-server command.
|
|
|
|
See the [calibre-server documentation](${generatedDocumentationLink}) for details.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:39 +02:00
|
|
|
user = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2020-05-15 17:53:07 +02:00
|
|
|
default = "calibre-server";
|
2023-06-28 14:06:47 +02:00
|
|
|
description = "The user under which calibre-server runs.";
|
2020-05-15 17:53:07 +02:00
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:39 +02:00
|
|
|
group = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2020-05-15 17:53:07 +02:00
|
|
|
default = "calibre-server";
|
2023-06-28 14:06:47 +02:00
|
|
|
description = "The group under which calibre-server runs.";
|
2020-05-15 17:53:07 +02:00
|
|
|
};
|
2015-09-27 20:31:17 -07:00
|
|
|
|
2024-08-24 22:05:39 +02:00
|
|
|
host = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2023-06-28 14:06:47 +02:00
|
|
|
default = "0.0.0.0";
|
|
|
|
example = "::1";
|
|
|
|
description = ''
|
|
|
|
The interface on which to listen for connections.
|
|
|
|
See the [calibre-server documentation](${generatedDocumentationLink}#cmdoption-calibre-server-listen-on) for details.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:39 +02:00
|
|
|
port = lib.mkOption {
|
2023-06-28 14:06:47 +02:00
|
|
|
default = 8080;
|
2024-08-24 22:05:39 +02:00
|
|
|
type = lib.types.port;
|
2023-06-28 14:06:47 +02:00
|
|
|
description = ''
|
|
|
|
The port on which to listen for connections.
|
|
|
|
See the [calibre-server documentation](${generatedDocumentationLink}#cmdoption-calibre-server-port) for details.
|
|
|
|
'';
|
|
|
|
};
|
2015-09-27 20:31:17 -07:00
|
|
|
|
2024-10-23 09:55:28 -04:00
|
|
|
openFirewall = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Open ports in the firewall for the Calibre Server web interface.";
|
|
|
|
};
|
|
|
|
|
2023-06-28 14:06:47 +02:00
|
|
|
auth = {
|
2024-08-24 22:05:39 +02:00
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2023-06-28 14:06:47 +02:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Password based authentication to access the server.
|
|
|
|
See the [calibre-server documentation](${generatedDocumentationLink}#cmdoption-calibre-server-enable-auth) for details.
|
|
|
|
'';
|
|
|
|
};
|
2015-09-27 20:31:17 -07:00
|
|
|
|
2024-08-24 22:05:39 +02:00
|
|
|
mode = lib.mkOption {
|
|
|
|
type = lib.types.enum [
|
|
|
|
"auto"
|
|
|
|
"basic"
|
|
|
|
"digest"
|
|
|
|
];
|
2023-06-28 14:06:47 +02:00
|
|
|
default = "auto";
|
|
|
|
description = ''
|
|
|
|
Choose the type of authentication used.
|
|
|
|
Set the HTTP authentication mode used by the server.
|
|
|
|
See the [calibre-server documentation](${generatedDocumentationLink}#cmdoption-calibre-server-auth-mode) for details.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:39 +02:00
|
|
|
userDb = lib.mkOption {
|
2023-06-28 14:06:47 +02:00
|
|
|
default = null;
|
2024-08-24 22:05:39 +02:00
|
|
|
type = lib.types.nullOr lib.types.path;
|
2023-06-28 14:06:47 +02:00
|
|
|
description = ''
|
|
|
|
Choose users database file to use for authentication.
|
|
|
|
Make sure users database file is initialized before service startup.
|
|
|
|
See the [calibre-server documentation](${documentationLink}/server.html#managing-user-accounts-from-the-command-line-only) for details.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2015-09-27 20:31:17 -07:00
|
|
|
|
2024-08-24 22:05:39 +02:00
|
|
|
config = lib.mkIf cfg.enable {
|
2015-09-27 20:31:17 -07:00
|
|
|
|
2020-05-15 17:53:07 +02:00
|
|
|
systemd.services.calibre-server = {
|
2023-06-28 14:06:47 +02:00
|
|
|
description = "Calibre Server";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
Restart = "always";
|
|
|
|
ExecStart = "${cfg.package}/bin/calibre-server ${lib.concatStringsSep " " cfg.libraries} ${execFlags}";
|
2015-09-27 20:31:17 -07:00
|
|
|
};
|
|
|
|
|
2023-06-28 14:06:47 +02:00
|
|
|
};
|
|
|
|
|
2015-09-27 20:31:17 -07:00
|
|
|
environment.systemPackages = [ pkgs.calibre ];
|
|
|
|
|
2024-08-24 22:05:39 +02:00
|
|
|
users.users = lib.optionalAttrs (cfg.user == "calibre-server") {
|
2020-05-15 17:53:07 +02:00
|
|
|
calibre-server = {
|
|
|
|
home = "/var/lib/calibre-server";
|
|
|
|
createHome = true;
|
2015-09-27 20:31:17 -07:00
|
|
|
uid = config.ids.uids.calibre-server;
|
2020-05-15 17:53:07 +02:00
|
|
|
group = cfg.group;
|
2015-10-03 05:48:46 -07:00
|
|
|
};
|
2020-05-15 17:53:07 +02:00
|
|
|
};
|
2015-09-27 20:31:17 -07:00
|
|
|
|
2024-08-24 22:05:39 +02:00
|
|
|
users.groups = lib.optionalAttrs (cfg.group == "calibre-server") {
|
2020-05-15 17:53:07 +02:00
|
|
|
calibre-server = {
|
2015-09-27 20:31:17 -07:00
|
|
|
gid = config.ids.gids.calibre-server;
|
2015-10-03 05:48:46 -07:00
|
|
|
};
|
2020-05-15 17:53:07 +02:00
|
|
|
};
|
2015-09-27 20:31:17 -07:00
|
|
|
|
2024-10-23 09:55:28 -04:00
|
|
|
networking.firewall = lib.mkIf cfg.openFirewall { allowedTCPPorts = [ cfg.port ]; };
|
|
|
|
|
2015-09-27 20:31:17 -07:00
|
|
|
};
|
|
|
|
|
2023-06-28 14:06:47 +02:00
|
|
|
meta.maintainers = with lib.maintainers; [ gaelreyrol ];
|
2015-09-27 20:31:17 -07:00
|
|
|
}
|