1 { config, lib, pkgs, ... }:
4 inherit (lib) mkIf mkOption optional;
5 inherit (lib.types) path bool listOf str port;
6 cfg = config.services.darkhttpd;
8 args = lib.concatStringsSep " " ([
10 "--port ${toString cfg.port}"
11 "--addr ${cfg.address}"
13 ++ optional cfg.hideServerId "--no-server-id"
14 ++ optional config.networking.enableIPv6 "--ipv6");
17 options.services.darkhttpd = {
18 enable = lib.mkEnableOption "DarkHTTPd web server";
25 Pass 0 to let the system choose any free port for you.
30 default = "127.0.0.1";
34 Pass `all` to listen on all interfaces.
41 Path from which to serve files.
45 hideServerId = mkOption {
49 Don't identify the server type in headers or directory listings.
53 extraArgs = mkOption {
57 Additional configuration passed to the executable.
62 config = mkIf cfg.enable {
63 systemd.services.darkhttpd = {
64 description = "Dark HTTPd";
65 wants = [ "network.target" ];
66 after = [ "network.target" ];
67 wantedBy = [ "multi-user.target" ];
70 ExecStart = "${pkgs.darkhttpd}/bin/darkhttpd ${args}";
71 AmbientCapabilities = lib.mkIf (cfg.port < 1024) [ "CAP_NET_BIND_SERVICE" ];
72 Restart = "on-failure";