nixpkgs/nixos/modules/services/web-servers/merecat.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.3 KiB
Nix
Raw Normal View History

2022-10-19 08:49:57 +00:00
{ 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 (lib.mdDoc "Merecat HTTP server");
settings = mkOption {
inherit (format) type;
default = { };
description = lib.mdDoc ''
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" ];
};
};
};
}