depot/third_party/nixpkgs/nixos/modules/services/web-servers/merecat.nix
Default email 587713944a Project import generated by Copybara.
GitOrigin-RevId: 6143fc5eeb9c4f00163267708e26191d1e918932
2024-04-21 17:54:59 +02:00

55 lines
1.3 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.merecat;
format = pkgs.formats.keyValue {
mkKeyValue = generators.mkKeyValueDefault {
mkValueString = v:
# In merecat.conf, booleans are "true" and "false"
if builtins.isBool v
then if v then "true" else "false"
else generators.mkValueStringDefault {} v;
} "=";
};
configFile = format.generate "merecat.conf" cfg.settings;
in {
options.services.merecat = {
enable = mkEnableOption "Merecat HTTP server";
settings = mkOption {
inherit (format) type;
default = { };
description = ''
Merecat configuration. Refer to merecat(8) for details on supported values.
'';
example = {
hostname = "localhost";
port = 8080;
virtual-host = true;
directory = "/srv/www";
};
};
};
config = mkIf cfg.enable {
systemd.services.merecat = {
description = "Merecat HTTP server";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
DynamicUser = true;
ExecStart = "${pkgs.merecat}/bin/merecat -n -f ${configFile}";
AmbientCapabilities = lib.mkIf ((cfg.settings.port or 80) < 1024) [ "CAP_NET_BIND_SERVICE" ];
};
};
};
}