-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added static-darkhttpd webservice with darkhttpd backend
- Loading branch information
Showing
6 changed files
with
107 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ config, lib, pkgs, wsName, mkUnique, darkhttpd, ... }: | ||
|
||
with lib; | ||
|
||
{ | ||
options = {}; | ||
|
||
config = rec { | ||
webserver.variant = "darkhttpd"; | ||
tests.wanted = [ ./test.nix ]; | ||
}; | ||
|
||
meta = { | ||
description = "Using darkhttpd for static file serving (no CGI)"; | ||
maintainers = with maintainers; [ qknight ]; | ||
license = lib.licenses.bsd2; | ||
homepage = https://github.com/nixcloud/nixcloud-webservices; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
name = "static-darkhttpd"; | ||
|
||
machine.imports = [ ../../../../tests/common/eatmydata.nix ]; | ||
machine.nixcloud.reverse-proxy.enable = true; | ||
machine.nixcloud.reverse-proxy.extendEtcHosts = true; | ||
machine.nixcloud.webservices.static-darkhttpd = { | ||
foo.enable = true; | ||
foo.proxyOptions.TLS = "none"; | ||
foo.proxyOptions.domain = "example.com"; | ||
foo.proxyOptions.http.mode = "on"; | ||
foo.proxyOptions.https.mode = "off"; | ||
foo.proxyOptions.port = 8080; | ||
|
||
bar.enable = true; | ||
bar.proxyOptions.TLS = "none"; | ||
bar.proxyOptions.domain = "example.org"; | ||
bar.proxyOptions.http.mode = "on"; | ||
bar.proxyOptions.https.mode = "off"; | ||
bar.proxyOptions.port = 8081; | ||
}; | ||
|
||
testScript = let | ||
searchFor = "Generated by darkhttpd"; | ||
in '' | ||
$machine->waitForUnit('multi-user.target'); | ||
$machine->succeed('curl -L http://example.com/ | grep -qF "${searchFor}"'); | ||
$machine->succeed('curl -L http://example.org/ | grep -qF "${searchFor}"'); | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ config, pkgs, lib, options, wsName, mkUnique, ... }: | ||
|
||
with lib; | ||
|
||
{ | ||
options.webserver.darkhttpd = { | ||
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 = mkIf (config.webserver.variant == "darkhttpd" && config.enable) { | ||
directories.log = { | ||
permissions.defaultDirectoryMode = "0750"; | ||
permissions.others.noAccess = true; | ||
owner = mkUnique config.webserver.user; | ||
group = mkUnique 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 ${config.stateDir} --port ${toString config.proxyOptions.port} --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; | ||
}; | ||
}; | ||
}; | ||
} |