|
6 | 6 |
|
7 | 7 | cfg = config.services.calibre-server;
|
8 | 8 |
|
| 9 | + documentationLink = "https://manual.calibre-ebook.com"; |
| 10 | + generatedDocumentationLink = documentationLink + "/generated/en/calibre-server.html"; |
| 11 | + |
| 12 | + execFlags = (concatStringsSep " " |
| 13 | + (mapAttrsToList (k: v: "${k} ${toString v}") (filterAttrs (name: value: value != null) { |
| 14 | + "--listen-on" = cfg.host; |
| 15 | + "--port" = cfg.port; |
| 16 | + "--auth-mode" = cfg.auth.mode; |
| 17 | + "--userdb" = cfg.auth.userDb; |
| 18 | + }) ++ [(optionalString (cfg.auth.enable == true) "--enable-auth")]) |
| 19 | + ); |
9 | 20 | in
|
10 | 21 |
|
11 | 22 | {
|
|
18 | 29 | )
|
19 | 30 | ];
|
20 | 31 |
|
21 |
| - ###### interface |
22 |
| - |
23 | 32 | options = {
|
24 | 33 | services.calibre-server = {
|
25 | 34 |
|
26 | 35 | enable = mkEnableOption (lib.mdDoc "calibre-server");
|
| 36 | + package = lib.mkPackageOptionMD pkgs "calibre" { }; |
27 | 37 |
|
28 | 38 | libraries = mkOption {
|
| 39 | + type = types.listOf types.path; |
| 40 | + default = [ "/var/lib/calibre-server" ]; |
29 | 41 | description = lib.mdDoc ''
|
| 42 | + Make sure each library path is initialized before service startup. |
30 | 43 | The directories of the libraries to serve. They must be readable for the user under which the server runs.
|
| 44 | + See the [calibredb documentation](${documentationLink}/generated/en/calibredb.html#add) for details. |
31 | 45 | '';
|
32 |
| - type = types.listOf types.path; |
33 | 46 | };
|
34 | 47 |
|
35 | 48 | user = mkOption {
|
36 |
| - description = lib.mdDoc "The user under which calibre-server runs."; |
37 | 49 | type = types.str;
|
38 | 50 | default = "calibre-server";
|
| 51 | + description = lib.mdDoc "The user under which calibre-server runs."; |
39 | 52 | };
|
40 | 53 |
|
41 | 54 | group = mkOption {
|
42 |
| - description = lib.mdDoc "The group under which calibre-server runs."; |
43 | 55 | type = types.str;
|
44 | 56 | default = "calibre-server";
|
| 57 | + description = lib.mdDoc "The group under which calibre-server runs."; |
45 | 58 | };
|
46 | 59 |
|
47 |
| - }; |
48 |
| - }; |
| 60 | + host = mkOption { |
| 61 | + type = types.str; |
| 62 | + default = "0.0.0.0"; |
| 63 | + example = "::1"; |
| 64 | + description = lib.mdDoc '' |
| 65 | + The interface on which to listen for connections. |
| 66 | + See the [calibre-server documentation](${generatedDocumentationLink}#cmdoption-calibre-server-listen-on) for details. |
| 67 | + ''; |
| 68 | + }; |
| 69 | + |
| 70 | + port = mkOption { |
| 71 | + default = 8080; |
| 72 | + type = types.port; |
| 73 | + description = lib.mdDoc '' |
| 74 | + The port on which to listen for connections. |
| 75 | + See the [calibre-server documentation](${generatedDocumentationLink}#cmdoption-calibre-server-port) for details. |
| 76 | + ''; |
| 77 | + }; |
49 | 78 |
|
| 79 | + auth = { |
| 80 | + enable = mkOption { |
| 81 | + type = types.bool; |
| 82 | + default = false; |
| 83 | + description = lib.mdDoc '' |
| 84 | + Password based authentication to access the server. |
| 85 | + See the [calibre-server documentation](${generatedDocumentationLink}#cmdoption-calibre-server-enable-auth) for details. |
| 86 | + ''; |
| 87 | + }; |
50 | 88 |
|
51 |
| - ###### implementation |
| 89 | + mode = mkOption { |
| 90 | + type = types.enum [ "auto" "basic" "digest" ]; |
| 91 | + default = "auto"; |
| 92 | + description = lib.mdDoc '' |
| 93 | + Choose the type of authentication used. |
| 94 | + Set the HTTP authentication mode used by the server. |
| 95 | + See the [calibre-server documentation](${generatedDocumentationLink}#cmdoption-calibre-server-auth-mode) for details. |
| 96 | + ''; |
| 97 | + }; |
| 98 | + |
| 99 | + userDb = mkOption { |
| 100 | + default = null; |
| 101 | + type = types.nullOr types.path; |
| 102 | + description = lib.mdDoc '' |
| 103 | + Choose users database file to use for authentication. |
| 104 | + Make sure users database file is initialized before service startup. |
| 105 | + See the [calibre-server documentation](${documentationLink}/server.html#managing-user-accounts-from-the-command-line-only) for details. |
| 106 | + ''; |
| 107 | + }; |
| 108 | + }; |
| 109 | + }; |
| 110 | + }; |
52 | 111 |
|
53 | 112 | config = mkIf cfg.enable {
|
54 | 113 |
|
55 | 114 | systemd.services.calibre-server = {
|
56 |
| - description = "Calibre Server"; |
57 |
| - after = [ "network.target" ]; |
58 |
| - wantedBy = [ "multi-user.target" ]; |
59 |
| - serviceConfig = { |
60 |
| - User = cfg.user; |
61 |
| - Restart = "always"; |
62 |
| - ExecStart = "${pkgs.calibre}/bin/calibre-server ${lib.concatStringsSep " " cfg.libraries}"; |
63 |
| - }; |
64 |
| - |
| 115 | + description = "Calibre Server"; |
| 116 | + after = [ "network.target" ]; |
| 117 | + wantedBy = [ "multi-user.target" ]; |
| 118 | + serviceConfig = { |
| 119 | + User = cfg.user; |
| 120 | + Restart = "always"; |
| 121 | + ExecStart = "${cfg.package}/bin/calibre-server ${lib.concatStringsSep " " cfg.libraries} ${execFlags}"; |
65 | 122 | };
|
66 | 123 |
|
| 124 | + }; |
| 125 | + |
67 | 126 | environment.systemPackages = [ pkgs.calibre ];
|
68 | 127 |
|
69 | 128 | users.users = optionalAttrs (cfg.user == "calibre-server") {
|
|
83 | 142 |
|
84 | 143 | };
|
85 | 144 |
|
| 145 | + meta.maintainers = with lib.maintainers; [ gaelreyrol ]; |
86 | 146 | }
|
0 commit comments