-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathdarkhttpd.nix
70 lines (65 loc) · 2.52 KB
/
darkhttpd.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
{ config, pkgs, lib, options, wsName, mkUniqueUser, mkUniqueGroup, ... }:
with lib;
let
enabled = config.webserver.variant == "darkhttpd" && config.enable;
isDefaultRoot = config.webserver.darkhttpd.root == "${config.stateDir}/www";
in {
options.webserver.darkhttpd = {
root = mkOption {
type = types.path;
default = "${config.stateDir}/www";
example = /var/www/whatever;
description = "The directory where the static webserver looks for documents to serve.";
};
extraServiceDependencies = mkOption {
type = types.listOf types.str;
default = [ ];
example = [ "postgresql.service" ];
description = "Makes it easy to replace postgresql by mysql and depend on the service before we start the webservice.";
};
};
config = lib.mkMerge [
(mkIf (enabled && isDefaultRoot) {
directories.www = {
owner = mkUniqueUser config.webserver.user;
group = mkUniqueGroup config.webserver.group;
instance.before = [ "webserver-init.service" "instance-init.target" ];
};
})
(mkIf enabled {
directories.log = {
permissions.defaultDirectoryMode = "0750";
permissions.others.noAccess = true;
owner = mkUniqueUser config.webserver.user;
group = mkUniqueGroup config.webserver.group;
instance.before = [ "webserver-init.service" "instance-init.target" ];
};
systemd.services.darkhttpd = {
description = "${config.uniqueName} main service (darkhttpd)";
wantedBy = [ "multi-user.target" ];
wants = [ "keys.target" ];
after = [ "network.target" "fs.target" "keys.target" ];
instance.after = [ "database.target" "webserver-init.service" ];
serviceConfig = {
ExecStart = "${pkgs.darkhttpd}/bin/darkhttpd ${toString config.root} --port ${toString config.proxyOptions.port} --mimetypes ${pkgs.apacheHttpd}/conf/mime.types --addr 127.0.0.1";
KillSignal = "SIGTERM";
Restart = "always";
RestartSec = "10s";
StartLimitInterval = "1min";
User = config.webserver.user;
Group = config.webserver.group;
PermissionsStartOnly = true;
PrivateTmp = config.webserver.privateTmp;
WorkingDirectory = config.stateDir;
MemoryDenyWriteExecute = true;
RestrictNameSpaces = true;
NoNewPrivileges = true;
ProtectHome = true;
PrivateUsers = true;
ProtectSystem = true;
ProtectKernelTunables = true;
};
};
})
];
}