|
25 | 25 | package = cfg.package.override { inherit (cfg) stateDir; }; |
26 | 26 |
|
27 | 27 | cfg = config.services.dolibarr; |
28 | | - vhostCfg = lib.optionalAttrs (cfg.nginx != null) config.services.nginx.virtualHosts."${cfg.domain}"; |
| 28 | + |
| 29 | + forcedTLS = |
| 30 | + if cfg.h2o != null then |
| 31 | + cfg.h2o.tls != null && cfg.h2o.tls.policy == "force" |
| 32 | + else if cfg.nginx != null then |
| 33 | + cfg.nginx.forceSSL |
| 34 | + else |
| 35 | + false; |
29 | 36 |
|
30 | 37 | mkConfigFile = |
31 | 38 | filename: settings: |
|
72 | 79 | else |
73 | 80 | cfg.database.port; |
74 | 81 |
|
| 82 | + # exclusivity asserted in `assertions` |
| 83 | + webServerService = |
| 84 | + if cfg.h2o != null then |
| 85 | + "h2o.service" |
| 86 | + else if cfg.nginx != null then |
| 87 | + "nginx.service" |
| 88 | + else |
| 89 | + null; |
| 90 | + |
| 91 | + socketOwner = if cfg.h2o != null then config.services.h2o.user else cfg.user; |
| 92 | + |
75 | 93 | # see https://github.com/Dolibarr/dolibarr/blob/develop/htdocs/install/install.forced.sample.php for all possible values |
76 | 94 | install = { |
77 | 95 | force_install_noedit = 2; |
|
90 | 108 | force_install_database = cfg.database.name; |
91 | 109 | force_install_databaselogin = cfg.database.user; |
92 | 110 |
|
93 | | - force_install_mainforcehttps = vhostCfg.forceSSL or false; |
| 111 | + force_install_mainforcehttps = forcedTLS; |
94 | 112 | force_install_createuser = false; |
95 | 113 | force_install_dolibarrlogin = null; |
96 | 114 | } |
|
204 | 222 | description = "Dolibarr settings, see <https://github.com/Dolibarr/dolibarr/blob/develop/htdocs/conf/conf.php.example> for details."; |
205 | 223 | }; |
206 | 224 |
|
| 225 | + h2o = mkOption { |
| 226 | + type = types.nullOr ( |
| 227 | + types.submodule (import ../web-servers/h2o/vhost-options.nix { inherit config lib; }) |
| 228 | + ); |
| 229 | + default = null; |
| 230 | + example = |
| 231 | + lib.literalExpression # nix |
| 232 | + '' |
| 233 | + { |
| 234 | + acme.enable = true; |
| 235 | + tls.policy = "force"; |
| 236 | + compress = "ON"; |
| 237 | + } |
| 238 | + ''; |
| 239 | + description = '' |
| 240 | + With this option, you can customize an H2O virtual host which already |
| 241 | + has sensible defaults for Dolibarr. Set to `{ }` if you do not need any |
| 242 | + customization to the virtual host. If enabled, then by default, the |
| 243 | + {option}`serverName` is `''${domain}`, If this is set to `null` (the |
| 244 | + default), no H2O `hosts` will be configured. |
| 245 | + ''; |
| 246 | + }; |
| 247 | + |
207 | 248 | nginx = mkOption { |
208 | 249 | type = types.nullOr ( |
209 | 250 | types.submodule ( |
|
267 | 308 | assertion = cfg.database.createLocally -> cfg.database.user == cfg.user; |
268 | 309 | message = "services.dolibarr.database.user must match services.dolibarr.user if the database is to be automatically provisioned"; |
269 | 310 | } |
| 311 | + ( |
| 312 | + let |
| 313 | + webServers = [ |
| 314 | + "h2o" |
| 315 | + "nginx" |
| 316 | + ]; |
| 317 | + checkConfigs = lib.concatMapStringsSep ", " (ws: "services.dolibarr.${ws}") webServers; |
| 318 | + in |
| 319 | + { |
| 320 | + assertion = builtins.length (lib.lists.filter (ws: cfg.${ws} != null) webServers) <= 1; |
| 321 | + message = '' |
| 322 | + At most 1 web server virtual host configuration should be enabled |
| 323 | + for Dolibarr at a time. Check ${checkConfigs}. |
| 324 | + ''; |
| 325 | + } |
| 326 | + ) |
270 | 327 | ]; |
271 | 328 |
|
272 | 329 | services.dolibarr.settings = { |
|
297 | 354 |
|
298 | 355 | # Security settings |
299 | 356 | dolibarr_main_prod = true; |
300 | | - dolibarr_main_force_https = vhostCfg.forceSSL or false; |
| 357 | + dolibarr_main_force_https = forcedTLS; |
301 | 358 | dolibarr_main_restrict_os_commands = |
302 | 359 | { |
303 | 360 | "mysql" = "${pkgs.mariadb}/bin/mysqldump, ${pkgs.mariadb}/bin/mysql"; |
|
350 | 407 | ''; |
351 | 408 | }; |
352 | 409 |
|
| 410 | + services.h2o = mkIf (cfg.h2o != null) { |
| 411 | + enable = true; |
| 412 | + hosts."${cfg.domain}" = mkMerge [ |
| 413 | + { |
| 414 | + settings = { |
| 415 | + paths = { |
| 416 | + "/" = { |
| 417 | + "file.dir" = "${package}/htdocs"; |
| 418 | + "file.index" = [ |
| 419 | + "index.php" |
| 420 | + "index.html" |
| 421 | + ]; |
| 422 | + redirect = { |
| 423 | + url = "/index.php/"; |
| 424 | + internal = "YES"; |
| 425 | + status = 307; |
| 426 | + }; |
| 427 | + }; |
| 428 | + }; |
| 429 | + "file.custom-handler" = { |
| 430 | + extension = [ ".php" ]; |
| 431 | + "fastcgi.document_root" = "${package}/htdocs"; |
| 432 | + "fastcgi.connect" = { |
| 433 | + port = config.services.phpfpm.pools.dolibarr.socket; |
| 434 | + type = "unix"; |
| 435 | + }; |
| 436 | + }; |
| 437 | + }; |
| 438 | + } |
| 439 | + cfg.h2o |
| 440 | + ]; |
| 441 | + }; |
| 442 | + |
353 | 443 | services.nginx.enable = mkIf (cfg.nginx != null) true; |
354 | 444 | services.nginx.virtualHosts."${cfg.domain}" = mkIf (cfg.nginx != null) ( |
355 | 445 | lib.mkMerge [ |
|
368 | 458 | ); |
369 | 459 |
|
370 | 460 | systemd.services."phpfpm-dolibarr" = { |
| 461 | + wantedBy = lib.optional (webServerService != null) webServerService; |
| 462 | + before = lib.optional (webServerService != null) webServerService; |
371 | 463 | after = lib.optional cfg.database.createLocally dbUnit; |
372 | 464 | requires = lib.optional cfg.database.createLocally dbUnit; |
373 | 465 | }; |
|
388 | 480 |
|
389 | 481 | settings = { |
390 | 482 | "listen.mode" = "0660"; |
391 | | - "listen.owner" = cfg.user; |
| 483 | + "listen.owner" = socketOwner; |
392 | 484 | "listen.group" = cfg.group; |
393 | 485 | } |
394 | 486 | // cfg.poolConfig; |
|
427 | 519 | }; |
428 | 520 | }; |
429 | 521 |
|
430 | | - users.users.dolibarr = mkIf (cfg.user == "dolibarr") { |
431 | | - isSystemUser = true; |
432 | | - group = cfg.group; |
433 | | - }; |
434 | | - |
435 | | - users.groups = optionalAttrs (cfg.group == "dolibarr") { |
436 | | - dolibarr = { }; |
| 522 | + users = { |
| 523 | + users = { |
| 524 | + dolibarr = mkIf (cfg.user == "dolibarr") { |
| 525 | + isSystemUser = true; |
| 526 | + group = cfg.group; |
| 527 | + }; |
| 528 | + } |
| 529 | + // lib.optionalAttrs (cfg.h2o != null) { |
| 530 | + "${config.services.h2o.user}".extraGroups = [ cfg.group ]; |
| 531 | + } |
| 532 | + // lib.optionalAttrs (cfg.nginx != null) { |
| 533 | + "${config.services.nginx.user}".extraGroups = [ cfg.group ]; |
| 534 | + }; |
| 535 | + groups = optionalAttrs (cfg.group == "dolibarr") { |
| 536 | + dolibarr = { }; |
| 537 | + }; |
437 | 538 | }; |
438 | 539 | } |
439 | | - (mkIf (cfg.nginx != null) { |
440 | | - users.users."${config.services.nginx.group}".extraGroups = mkIf (cfg.nginx != null) [ cfg.group ]; |
441 | | - }) |
442 | 540 | ]); |
443 | 541 | } |
0 commit comments