8 cfg = config.services.gotenberg;
12 "--api-port=${toString cfg.port}"
13 "--api-timeout=${cfg.timeout}"
14 "--api-root-path=${cfg.rootPath}"
15 "--log-level=${cfg.logLevel}"
16 "--chromium-max-queue-size=${toString cfg.chromium.maxQueueSize}"
17 "--libreoffice-restart-after=${toString cfg.libreoffice.restartAfter}"
18 "--libreoffice-max-queue-size=${toString cfg.libreoffice.maxQueueSize}"
19 "--pdfengines-engines=${lib.concatStringsSep "," cfg.pdfEngines}"
21 ++ optional cfg.enableBasicAuth "--api-enable-basic-auth"
22 ++ optional cfg.chromium.autoStart "--chromium-auto-start"
23 ++ optional cfg.chromium.disableJavascript "--chromium-disable-javascript"
24 ++ optional cfg.chromium.disableRoutes "--chromium-disable-routes"
25 ++ optional cfg.libreoffice.autoStart "--libreoffice-auto-start"
26 ++ optional cfg.libreoffice.disableRoutes "--libreoffice-disable-routes";
40 services.gotenberg = {
41 enable = mkEnableOption "Gotenberg, a stateless API for PDF files";
43 # Users can override only gotenberg, libreoffice and chromium if they want to (eg. ungoogled-chromium, different LO version, etc)
44 # Don't allow setting the qpdf, pdftk, or unoconv paths, as those are very stable
45 # and there's only one version of each.
46 package = mkPackageOption pkgs "gotenberg" { };
51 description = "Port on which the API should listen.";
55 type = types.nullOr types.str;
57 description = "Timeout for API requests.";
63 description = "Root path for the Gotenberg API.";
66 enableBasicAuth = mkOption {
70 HTTP Basic Authentication.
72 If you set this, be sure to set `GOTENBERG_API_BASIC_AUTH_USERNAME`and `GOTENBERG_API_BASIC_AUTH_PASSWORD`
73 in your `services.gotenberg.environmentFile` file.
77 extraFontPackages = mkOption {
78 type = types.listOf types.package;
80 description = "Extra fonts to make available.";
84 package = mkPackageOption pkgs "chromium" { };
86 maxQueueSize = mkOption {
89 description = "Maximum queue size for chromium-based conversions. Setting to 0 disables the limit.";
92 autoStart = mkOption {
95 description = "Automatically start chromium when Gotenberg starts. If false, Chromium will start on the first conversion request that uses it.";
98 disableJavascript = mkOption {
101 description = "Disable Javascript execution.";
104 disableRoutes = mkOption {
107 description = "Disable all routes allowing Chromium-based conversion.";
112 package = mkPackageOption pkgs "libreoffice" { };
114 restartAfter = mkOption {
117 description = "Restart LibreOffice after this many conversions. Setting to 0 disables this feature.";
120 maxQueueSize = mkOption {
123 description = "Maximum queue size for LibreOffice-based conversions. Setting to 0 disables the limit.";
126 autoStart = mkOption {
129 description = "Automatically start LibreOffice when Gotenberg starts. If false, Chromium will start on the first conversion request that uses it.";
132 disableRoutes = mkOption {
135 description = "Disable all routes allowing LibreOffice-based conversion.";
139 pdfEngines = mkOption {
140 type = types.listOf (
144 "libreoffice-pdfengine"
152 "libreoffice-pdfengine"
157 PDF engines to enable. Each one can be used to perform a specific task.
158 See [the documentation](https://gotenberg.dev/docs/configuration#pdf-engines) for more details.
159 Defaults to all possible PDF engines.
163 logLevel = mkOption {
171 description = "The logging level for Gotenberg.";
174 environmentFile = mkOption {
175 type = types.nullOr types.path;
177 description = "Environment file to load extra environment variables from.";
180 extraArgs = mkOption {
181 type = types.listOf types.str;
183 description = "Any extra command-line flags to pass to the Gotenberg service.";
188 config = mkIf cfg.enable {
191 assertion = cfg.enableBasicAuth -> cfg.environmentFile != null;
193 When enabling HTTP Basic Authentication with `services.gotenberg.enableBasicAuth`,
194 you must provide an environment file via `services.gotenberg.environmentFile` with the appropriate environment variables set in it.
196 See `services.gotenberg.enableBasicAuth` for the names of those variables.
201 systemd.services.gotenberg = {
202 description = "Gotenberg API server";
203 after = [ "network.target" ];
204 wantedBy = [ "multi-user.target" ];
205 path = [ cfg.package ];
207 LIBREOFFICE_BIN_PATH = "${cfg.libreoffice.package}/lib/libreoffice/program/soffice.bin";
208 CHROMIUM_BIN_PATH = lib.getExe cfg.chromium.package;
209 FONTCONFIG_FILE = pkgs.makeFontsConf {
210 fontDirectories = [ pkgs.liberation_ttf_v2 ] ++ cfg.extraFontPackages;
216 ExecStart = "${lib.getExe cfg.package} ${lib.escapeShellArgs args}";
219 PrivateDevices = true;
224 ProtectControlGroups = true;
226 ProtectHostname = true;
227 ProtectKernelLogs = true;
228 ProtectKernelModules = true;
229 ProtectKernelTunables = true;
230 ProtectProc = "invisible";
233 RestrictAddressFamilies = [
239 RestrictNamespaces = true;
240 RestrictRealtime = true;
242 LockPersonality = true;
243 MemoryDenyWriteExecute = true;
249 SystemCallArchitectures = "native";
252 } // optionalAttrs (cfg.environmentFile != null) { EnvironmentFile = cfg.environmentFile; };
256 meta.maintainers = with lib.maintainers; [ pyrox0 ];