Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

services/calibre-server: Add new http & auth options (#216497)

nixos/doc: add calibre-server new options

authored by Gaël Reyrol and committed by GitHub 3a4e234b 417de14e

+184 -17
+2
nixos/doc/manual/release-notes/rl-2311.section.md
··· 78 79 - `services.prometheus.exporters` has a new exporter to monitor electrical power consumption based on PowercapRAPL sensor called [Scaphandre](https://github.com/hubblo-org/scaphandre), see [#239803](https://github.com/NixOS/nixpkgs/pull/239803) for more details. 80 81 ## Nixpkgs internals {#sec-release-23.11-nixpkgs-internals} 82 83 - The `qemu-vm.nix` module by default now identifies block devices via
··· 78 79 - `services.prometheus.exporters` has a new exporter to monitor electrical power consumption based on PowercapRAPL sensor called [Scaphandre](https://github.com/hubblo-org/scaphandre), see [#239803](https://github.com/NixOS/nixpkgs/pull/239803) for more details. 80 81 + - The module `services.calibre-server` has new options to configure the `host`, `port`, `auth.enable`, `auth.mode` and `auth.userDb` path, see [#216497](https://github.com/NixOS/nixpkgs/pull/216497/) for more details. 82 + 83 ## Nixpkgs internals {#sec-release-23.11-nixpkgs-internals} 84 85 - The `qemu-vm.nix` module by default now identifies block devices via
+77 -17
nixos/modules/services/misc/calibre-server.nix
··· 6 7 cfg = config.services.calibre-server; 8 9 in 10 11 { ··· 18 ) 19 ]; 20 21 - ###### interface 22 - 23 options = { 24 services.calibre-server = { 25 26 enable = mkEnableOption (lib.mdDoc "calibre-server"); 27 28 libraries = mkOption { 29 description = lib.mdDoc '' 30 The directories of the libraries to serve. They must be readable for the user under which the server runs. 31 ''; 32 - type = types.listOf types.path; 33 }; 34 35 user = mkOption { 36 - description = lib.mdDoc "The user under which calibre-server runs."; 37 type = types.str; 38 default = "calibre-server"; 39 }; 40 41 group = mkOption { 42 - description = lib.mdDoc "The group under which calibre-server runs."; 43 type = types.str; 44 default = "calibre-server"; 45 }; 46 47 - }; 48 - }; 49 50 51 - ###### implementation 52 53 config = mkIf cfg.enable { 54 55 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 65 - }; 66 67 environment.systemPackages = [ pkgs.calibre ]; 68 ··· 83 84 }; 85 86 }
··· 6 7 cfg = config.services.calibre-server; 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 + ); 20 in 21 22 { ··· 29 ) 30 ]; 31 32 options = { 33 services.calibre-server = { 34 35 enable = mkEnableOption (lib.mdDoc "calibre-server"); 36 + package = lib.mkPackageOptionMD pkgs "calibre" { }; 37 38 libraries = mkOption { 39 + type = types.listOf types.path; 40 + default = [ "/var/lib/calibre-server" ]; 41 description = lib.mdDoc '' 42 + Make sure each library path is initialized before service startup. 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. 45 ''; 46 }; 47 48 user = mkOption { 49 type = types.str; 50 default = "calibre-server"; 51 + description = lib.mdDoc "The user under which calibre-server runs."; 52 }; 53 54 group = mkOption { 55 type = types.str; 56 default = "calibre-server"; 57 + description = lib.mdDoc "The group under which calibre-server runs."; 58 }; 59 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 + }; 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 + }; 88 + 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 + }; 111 112 config = mkIf cfg.enable { 113 114 systemd.services.calibre-server = { 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}"; 122 + }; 123 124 + }; 125 126 environment.systemPackages = [ pkgs.calibre ]; 127 ··· 142 143 }; 144 145 + meta.maintainers = with lib.maintainers; [ gaelreyrol ]; 146 }
+1
nixos/tests/all-tests.nix
··· 151 cage = handleTest ./cage.nix {}; 152 cagebreak = handleTest ./cagebreak.nix {}; 153 calibre-web = handleTest ./calibre-web.nix {}; 154 cassandra_3_0 = handleTest ./cassandra.nix { testPackage = pkgs.cassandra_3_0; }; 155 cassandra_3_11 = handleTest ./cassandra.nix { testPackage = pkgs.cassandra_3_11; }; 156 cassandra_4 = handleTest ./cassandra.nix { testPackage = pkgs.cassandra_4; };
··· 151 cage = handleTest ./cage.nix {}; 152 cagebreak = handleTest ./cagebreak.nix {}; 153 calibre-web = handleTest ./calibre-web.nix {}; 154 + calibre-server = handleTest ./calibre-server.nix {}; 155 cassandra_3_0 = handleTest ./cassandra.nix { testPackage = pkgs.cassandra_3_0; }; 156 cassandra_3_11 = handleTest ./cassandra.nix { testPackage = pkgs.cassandra_3_11; }; 157 cassandra_4 = handleTest ./cassandra.nix { testPackage = pkgs.cassandra_4; };
+104
nixos/tests/calibre-server.nix
···
··· 1 + { system ? builtins.currentSystem 2 + , config ? { } 3 + , pkgs ? import ../.. { inherit system config; } 4 + }: 5 + 6 + let 7 + inherit (import ../lib/testing-python.nix { inherit system pkgs; }) makeTest; 8 + inherit (pkgs.lib) concatStringsSep maintainers mapAttrs mkMerge 9 + removeSuffix splitString; 10 + 11 + tests = { 12 + default = { 13 + calibreConfig = {}; 14 + calibreScript = '' 15 + wait_for_unit("calibre-server.service") 16 + ''; 17 + }; 18 + customLibrary = { 19 + calibreConfig = { 20 + libraries = [ "/var/lib/calibre-data" ]; 21 + }; 22 + calibreScript = '' 23 + succeed("ls -la /var/lib/calibre-data") 24 + wait_for_unit("calibre-server.service") 25 + ''; 26 + }; 27 + multipleLibraries = { 28 + calibreConfig = { 29 + libraries = [ "/var/lib/calibre-data" "/var/lib/calibre-server" ]; 30 + }; 31 + calibreScript = '' 32 + succeed("ls -la /var/lib/calibre-data") 33 + succeed("ls -la /var/lib/calibre-server") 34 + wait_for_unit("calibre-server.service") 35 + ''; 36 + }; 37 + hostAndPort = { 38 + calibreConfig = { 39 + host = "127.0.0.1"; 40 + port = 8888; 41 + }; 42 + calibreScript = '' 43 + wait_for_unit("calibre-server.service") 44 + wait_for_open_port(8888) 45 + succeed("curl --fail http://127.0.0.1:8888") 46 + ''; 47 + }; 48 + basicAuth = { 49 + calibreConfig = { 50 + host = "127.0.0.1"; 51 + port = 8888; 52 + auth = { 53 + enable = true; 54 + mode = "basic"; 55 + }; 56 + }; 57 + calibreScript = '' 58 + wait_for_unit("calibre-server.service") 59 + wait_for_open_port(8888) 60 + fail("curl --fail http://127.0.0.1:8888") 61 + ''; 62 + }; 63 + }; 64 + in 65 + mapAttrs 66 + (test: testConfig: (makeTest ( 67 + let 68 + nodeName = testConfig.nodeName or test; 69 + calibreConfig = { 70 + enable = true; 71 + libraries = [ "/var/lib/calibre-server" ]; 72 + } // testConfig.calibreConfig or {}; 73 + librariesInitScript = path: '' 74 + ${nodeName}.execute("touch /tmp/test.epub") 75 + ${nodeName}.execute("zip -r /tmp/test.zip /tmp/test.epub") 76 + ${nodeName}.execute("mkdir -p ${path}") 77 + ${nodeName}.execute("calibredb add -d --with-library ${path} /tmp/test.zip") 78 + ''; 79 + in 80 + { 81 + name = "calibre-server-${test}"; 82 + 83 + nodes.${nodeName} = mkMerge [{ 84 + environment.systemPackages = [ pkgs.zip ]; 85 + services.calibre-server = calibreConfig; 86 + } testConfig.calibreProvider or { }]; 87 + 88 + testScript = '' 89 + ${nodeName}.start() 90 + ${concatStringsSep "\n" (map librariesInitScript calibreConfig.libraries)} 91 + ${concatStringsSep "\n" (map (line: 92 + if (builtins.substring 0 1 line == " " || builtins.substring 0 1 line == ")") 93 + then line 94 + else "${nodeName}.${line}" 95 + ) (splitString "\n" (removeSuffix "\n" testConfig.calibreScript)))} 96 + ${nodeName}.shutdown() 97 + ''; 98 + 99 + meta = with maintainers; { 100 + maintainers = [ gaelreyrol ]; 101 + }; 102 + } 103 + ))) 104 + tests