|
| 1 | +{ config, pkgs, lib, options, wsName, mkUnique, ... }: |
| 2 | + |
| 3 | +with lib; |
| 4 | + |
| 5 | +{ |
| 6 | + options.webserver.darkhttpd = { |
| 7 | + extraServiceDependencies = mkOption { |
| 8 | + type = types.listOf types.str; |
| 9 | + default = [ ]; |
| 10 | + example = [ "postgresql.service" ]; |
| 11 | + description = "Makes it easy to replace postgresql by mysql and depend on the service before we start the webservice."; |
| 12 | + }; |
| 13 | + }; |
| 14 | + |
| 15 | + config = mkIf (config.webserver.variant == "darkhttpd" && config.enable) { |
| 16 | + directories.log = { |
| 17 | + permissions.defaultDirectoryMode = "0750"; |
| 18 | + permissions.others.noAccess = true; |
| 19 | + owner = mkUnique config.webserver.user; |
| 20 | + group = mkUnique config.webserver.group; |
| 21 | + instance.before = [ "webserver-init.service" "instance-init.target" ]; |
| 22 | + }; |
| 23 | + |
| 24 | + systemd.services.darkhttpd = { |
| 25 | + description = "${config.uniqueName} main service (darkhttpd)"; |
| 26 | + wantedBy = [ "multi-user.target" ]; |
| 27 | + wants = [ "keys.target" ]; |
| 28 | + after = [ "network.target" "fs.target" "keys.target" ]; |
| 29 | + instance.after = [ "database.target" "webserver-init.service" ]; |
| 30 | + |
| 31 | + serviceConfig = { |
| 32 | + ExecStart = "${pkgs.darkhttpd}/bin/darkhttpd ${config.stateDir} --port ${toString config.proxyOptions.port} --addr 127.0.0.1"; |
| 33 | + KillSignal = "SIGTERM"; |
| 34 | + Restart = "always"; |
| 35 | + RestartSec = "10s"; |
| 36 | + StartLimitInterval = "1min"; |
| 37 | + User = config.webserver.user; |
| 38 | + Group = config.webserver.group; |
| 39 | + PermissionsStartOnly = true; |
| 40 | + PrivateTmp = config.webserver.privateTmp; |
| 41 | + WorkingDirectory = config.stateDir; |
| 42 | + MemoryDenyWriteExecute = true; |
| 43 | + RestrictNameSpaces = true; |
| 44 | + NoNewPrivileges = true; |
| 45 | + ProtectHome = true; |
| 46 | + PrivateUsers = true; |
| 47 | + ProtectSystem = true; |
| 48 | + ProtectKernelTunables = true; |
| 49 | + }; |
| 50 | + }; |
| 51 | + }; |
| 52 | +} |
0 commit comments