2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-10-29 15:55:25 +01:00
|
|
|
let
|
|
|
|
cfg = config.services.haproxy;
|
|
|
|
haproxyCfg = pkgs.writeText "haproxy.conf" cfg.config;
|
|
|
|
in
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2013-10-29 15:55:25 +01:00
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.haproxy = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
2015-02-21 13:23:48 +01:00
|
|
|
type = types.bool;
|
2013-10-29 15:55:25 +01:00
|
|
|
default = false;
|
2015-02-21 13:23:48 +01:00
|
|
|
description = ''
|
|
|
|
Whether to enable HAProxy, the reliable, high performance TCP/HTTP
|
|
|
|
load balancer.
|
|
|
|
'';
|
2013-10-29 15:55:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkOption {
|
2015-02-22 12:30:14 +01:00
|
|
|
type = types.nullOr types.lines;
|
|
|
|
default = null;
|
2015-02-21 13:23:48 +01:00
|
|
|
description = ''
|
|
|
|
Contents of the HAProxy configuration file,
|
|
|
|
<filename>haproxy.conf</filename>.
|
|
|
|
'';
|
2013-10-29 15:55:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2015-02-22 12:30:14 +01:00
|
|
|
assertions = [{
|
|
|
|
assertion = cfg.config != null;
|
|
|
|
message = "You must provide services.haproxy.config.";
|
|
|
|
}];
|
|
|
|
|
2013-10-29 15:55:25 +01:00
|
|
|
systemd.services.haproxy = {
|
|
|
|
description = "HAProxy";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "forking";
|
2015-02-21 13:23:48 +01:00
|
|
|
PIDFile = "/run/haproxy.pid";
|
2013-10-29 15:55:25 +01:00
|
|
|
ExecStartPre = "${pkgs.haproxy}/sbin/haproxy -c -q -f ${haproxyCfg}";
|
2015-02-21 13:23:48 +01:00
|
|
|
ExecStart = "${pkgs.haproxy}/sbin/haproxy -D -f ${haproxyCfg} -p /run/haproxy.pid";
|
|
|
|
ExecReload = "-${pkgs.bash}/bin/bash -c \"exec ${pkgs.haproxy}/sbin/haproxy -D -f ${haproxyCfg} -p /run/haproxy.pid -sf $MAINPID\"";
|
2013-10-29 15:55:25 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.haproxy ];
|
|
|
|
|
2018-06-30 01:58:35 +02:00
|
|
|
users.users.haproxy = {
|
2013-10-29 15:55:25 +01:00
|
|
|
group = "haproxy";
|
|
|
|
uid = config.ids.uids.haproxy;
|
|
|
|
};
|
|
|
|
|
2018-06-30 01:58:35 +02:00
|
|
|
users.groups.haproxy.gid = config.ids.uids.haproxy;
|
2013-10-29 15:55:25 +01:00
|
|
|
};
|
|
|
|
}
|