2e751c0772
the conversion procedure is simple: - find all things that look like options, ie calls to either `mkOption` or `lib.mkOption` that take an attrset. remember the attrset as the option - for all options, find a `description` attribute who's value is not a call to `mdDoc` or `lib.mdDoc` - textually convert the entire value of the attribute to MD with a few simple regexes (the set from mdize-module.sh) - if the change produced a change in the manual output, discard - if the change kept the manual unchanged, add some text to the description to make sure we've actually found an option. if the manual changes this time, keep the converted description this procedure converts 80% of nixos options to markdown. around 2000 options remain to be inspected, but most of those fail the "does not change the manual output check": currently the MD conversion process does not faithfully convert docbook tags like <code> and <package>, so any option using such tags will not be converted at all.
113 lines
3.3 KiB
Nix
113 lines
3.3 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
cfg = config.services.haproxy;
|
|
|
|
haproxyCfg = pkgs.writeText "haproxy.conf" ''
|
|
global
|
|
# needed for hot-reload to work without dropping packets in multi-worker mode
|
|
stats socket /run/haproxy/haproxy.sock mode 600 expose-fd listeners level user
|
|
|
|
${cfg.config}
|
|
'';
|
|
|
|
in
|
|
with lib;
|
|
{
|
|
options = {
|
|
services.haproxy = {
|
|
|
|
enable = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = lib.mdDoc ''
|
|
Whether to enable HAProxy, the reliable, high performance TCP/HTTP
|
|
load balancer.
|
|
'';
|
|
};
|
|
|
|
user = mkOption {
|
|
type = types.str;
|
|
default = "haproxy";
|
|
description = lib.mdDoc "User account under which haproxy runs.";
|
|
};
|
|
|
|
group = mkOption {
|
|
type = types.str;
|
|
default = "haproxy";
|
|
description = lib.mdDoc "Group account under which haproxy runs.";
|
|
};
|
|
|
|
config = mkOption {
|
|
type = types.nullOr types.lines;
|
|
default = null;
|
|
description = lib.mdDoc ''
|
|
Contents of the HAProxy configuration file,
|
|
{file}`haproxy.conf`.
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
assertions = [{
|
|
assertion = cfg.config != null;
|
|
message = "You must provide services.haproxy.config.";
|
|
}];
|
|
|
|
# configuration file indirection is needed to support reloading
|
|
environment.etc."haproxy.cfg".source = haproxyCfg;
|
|
|
|
systemd.services.haproxy = {
|
|
description = "HAProxy";
|
|
after = [ "network.target" ];
|
|
wantedBy = [ "multi-user.target" ];
|
|
serviceConfig = {
|
|
User = cfg.user;
|
|
Group = cfg.group;
|
|
Type = "notify";
|
|
ExecStartPre = [
|
|
# when the master process receives USR2, it reloads itself using exec(argv[0]),
|
|
# so we create a symlink there and update it before reloading
|
|
"${pkgs.coreutils}/bin/ln -sf ${pkgs.haproxy}/sbin/haproxy /run/haproxy/haproxy"
|
|
# when running the config test, don't be quiet so we can see what goes wrong
|
|
"/run/haproxy/haproxy -c -f ${haproxyCfg}"
|
|
];
|
|
ExecStart = "/run/haproxy/haproxy -Ws -f /etc/haproxy.cfg -p /run/haproxy/haproxy.pid";
|
|
# support reloading
|
|
ExecReload = [
|
|
"${pkgs.haproxy}/sbin/haproxy -c -f ${haproxyCfg}"
|
|
"${pkgs.coreutils}/bin/ln -sf ${pkgs.haproxy}/sbin/haproxy /run/haproxy/haproxy"
|
|
"${pkgs.coreutils}/bin/kill -USR2 $MAINPID"
|
|
];
|
|
KillMode = "mixed";
|
|
SuccessExitStatus = "143";
|
|
Restart = "always";
|
|
RuntimeDirectory = "haproxy";
|
|
# upstream hardening options
|
|
NoNewPrivileges = true;
|
|
ProtectHome = true;
|
|
ProtectSystem = "strict";
|
|
ProtectKernelTunables = true;
|
|
ProtectKernelModules = true;
|
|
ProtectControlGroups = true;
|
|
SystemCallFilter= "~@cpu-emulation @keyring @module @obsolete @raw-io @reboot @swap @sync";
|
|
# needed in case we bind to port < 1024
|
|
AmbientCapabilities = "CAP_NET_BIND_SERVICE";
|
|
};
|
|
};
|
|
|
|
users.users = optionalAttrs (cfg.user == "haproxy") {
|
|
haproxy = {
|
|
group = cfg.group;
|
|
isSystemUser = true;
|
|
};
|
|
};
|
|
|
|
users.groups = optionalAttrs (cfg.group == "haproxy") {
|
|
haproxy = {};
|
|
};
|
|
};
|
|
}
|