2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.calibre-server;
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
documentationLink = "https://manual.calibre-ebook.com";
|
|
|
|
generatedDocumentationLink = documentationLink + "/generated/en/calibre-server.html";
|
|
|
|
|
|
|
|
execFlags = (concatStringsSep " "
|
|
|
|
(mapAttrsToList (k: v: "${k} ${toString v}") (filterAttrs (name: value: value != null) {
|
|
|
|
"--listen-on" = cfg.host;
|
|
|
|
"--port" = cfg.port;
|
|
|
|
"--auth-mode" = cfg.auth.mode;
|
|
|
|
"--userdb" = cfg.auth.userDb;
|
|
|
|
}) ++ [(optionalString (cfg.auth.enable == true) "--enable-auth")])
|
|
|
|
);
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2020-09-25 04:45:31 +00:00
|
|
|
imports = [
|
|
|
|
(mkChangedOptionModule [ "services" "calibre-server" "libraryDir" ] [ "services" "calibre-server" "libraries" ]
|
|
|
|
(config:
|
|
|
|
let libraryDir = getAttrFromPath [ "services" "calibre-server" "libraryDir" ] config;
|
|
|
|
in [ libraryDir ]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
options = {
|
|
|
|
services.calibre-server = {
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "calibre-server (e-book software)";
|
2024-01-02 11:29:13 +00:00
|
|
|
package = lib.mkPackageOption pkgs "calibre" { };
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
libraries = mkOption {
|
2023-07-15 17:15:38 +00:00
|
|
|
type = types.listOf types.path;
|
|
|
|
default = [ "/var/lib/calibre-server" ];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
Make sure each library path is initialized before service startup.
|
2020-09-25 04:45:31 +00:00
|
|
|
The directories of the libraries to serve. They must be readable for the user under which the server runs.
|
2023-07-15 17:15:38 +00:00
|
|
|
See the [calibredb documentation](${documentationLink}/generated/en/calibredb.html#add) for details.
|
2020-09-25 04:45:31 +00:00
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "calibre-server";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "The user under which calibre-server runs.";
|
2020-09-25 04:45:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "calibre-server";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "The group under which calibre-server runs.";
|
2020-09-25 04:45:31 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "0.0.0.0";
|
|
|
|
example = "::1";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
The interface on which to listen for connections.
|
|
|
|
See the [calibre-server documentation](${generatedDocumentationLink}#cmdoption-calibre-server-listen-on) for details.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
default = 8080;
|
|
|
|
type = types.port;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
The port on which to listen for connections.
|
|
|
|
See the [calibre-server documentation](${generatedDocumentationLink}#cmdoption-calibre-server-port) for details.
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
auth = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
Password based authentication to access the server.
|
|
|
|
See the [calibre-server documentation](${generatedDocumentationLink}#cmdoption-calibre-server-enable-auth) for details.
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
mode = mkOption {
|
|
|
|
type = types.enum [ "auto" "basic" "digest" ];
|
|
|
|
default = "auto";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
userDb = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.path;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
systemd.services.calibre-server = {
|
2023-07-15 17:15:38 +00: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}";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
environment.systemPackages = [ pkgs.calibre ];
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
users.users = optionalAttrs (cfg.user == "calibre-server") {
|
|
|
|
calibre-server = {
|
|
|
|
home = "/var/lib/calibre-server";
|
|
|
|
createHome = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
uid = config.ids.uids.calibre-server;
|
2020-09-25 04:45:31 +00:00
|
|
|
group = cfg.group;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2020-09-25 04:45:31 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
users.groups = optionalAttrs (cfg.group == "calibre-server") {
|
|
|
|
calibre-server = {
|
2020-04-24 23:36:52 +00:00
|
|
|
gid = config.ids.gids.calibre-server;
|
|
|
|
};
|
2020-09-25 04:45:31 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
meta.maintainers = with lib.maintainers; [ gaelreyrol ];
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|