1 { config, lib, pkgs, ... }:
4 cfg = config.services.calibre-server;
6 documentationLink = "https://manual.calibre-ebook.com";
7 generatedDocumentationLink = documentationLink + "/generated/en/calibre-server.html";
9 execFlags = (lib.concatStringsSep " "
10 (lib.mapAttrsToList (k: v: "${k} ${toString v}") (lib.filterAttrs (name: value: value != null) {
11 "--listen-on" = cfg.host;
13 "--auth-mode" = cfg.auth.mode;
14 "--userdb" = cfg.auth.userDb;
15 }) ++ [(lib.optionalString (cfg.auth.enable == true) "--enable-auth")])
21 (lib.mkChangedOptionModule [ "services" "calibre-server" "libraryDir" ] [ "services" "calibre-server" "libraries" ]
23 let libraryDir = lib.getAttrFromPath [ "services" "calibre-server" "libraryDir" ] config;
30 services.calibre-server = {
32 enable = lib.mkEnableOption "calibre-server (e-book software)";
33 package = lib.mkPackageOption pkgs "calibre" { };
35 libraries = lib.mkOption {
36 type = lib.types.listOf lib.types.path;
37 default = [ "/var/lib/calibre-server" ];
39 Make sure each library path is initialized before service startup.
40 The directories of the libraries to serve. They must be readable for the user under which the server runs.
41 See the [calibredb documentation](${documentationLink}/generated/en/calibredb.html#add) for details.
47 default = "calibre-server";
48 description = "The user under which calibre-server runs.";
51 group = lib.mkOption {
53 default = "calibre-server";
54 description = "The group under which calibre-server runs.";
62 The interface on which to listen for connections.
63 See the [calibre-server documentation](${generatedDocumentationLink}#cmdoption-calibre-server-listen-on) for details.
69 type = lib.types.port;
71 The port on which to listen for connections.
72 See the [calibre-server documentation](${generatedDocumentationLink}#cmdoption-calibre-server-port) for details.
77 enable = lib.mkOption {
78 type = lib.types.bool;
81 Password based authentication to access the server.
82 See the [calibre-server documentation](${generatedDocumentationLink}#cmdoption-calibre-server-enable-auth) for details.
87 type = lib.types.enum [ "auto" "basic" "digest" ];
90 Choose the type of authentication used.
91 Set the HTTP authentication mode used by the server.
92 See the [calibre-server documentation](${generatedDocumentationLink}#cmdoption-calibre-server-auth-mode) for details.
96 userDb = lib.mkOption {
98 type = lib.types.nullOr lib.types.path;
100 Choose users database file to use for authentication.
101 Make sure users database file is initialized before service startup.
102 See the [calibre-server documentation](${documentationLink}/server.html#managing-user-accounts-from-the-command-line-only) for details.
109 config = lib.mkIf cfg.enable {
111 systemd.services.calibre-server = {
112 description = "Calibre Server";
113 after = [ "network.target" ];
114 wantedBy = [ "multi-user.target" ];
118 ExecStart = "${cfg.package}/bin/calibre-server ${lib.concatStringsSep " " cfg.libraries} ${execFlags}";
123 environment.systemPackages = [ pkgs.calibre ];
125 users.users = lib.optionalAttrs (cfg.user == "calibre-server") {
127 home = "/var/lib/calibre-server";
129 uid = config.ids.uids.calibre-server;
134 users.groups = lib.optionalAttrs (cfg.group == "calibre-server") {
136 gid = config.ids.gids.calibre-server;
142 meta.maintainers = with lib.maintainers; [ gaelreyrol ];