2015-04-25 14:10:49 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.confd;
|
|
|
|
|
|
|
|
confdConfig = ''
|
|
|
|
backend = "${cfg.backend}"
|
|
|
|
confdir = "${cfg.confDir}"
|
|
|
|
interval = ${toString cfg.interval}
|
|
|
|
nodes = [ ${concatMapStringsSep "," (s: ''"${s}"'') cfg.nodes}, ]
|
|
|
|
prefix = "${cfg.prefix}"
|
|
|
|
log-level = "${cfg.logLevel}"
|
2017-04-11 16:08:51 +00:00
|
|
|
watch = ${boolToString cfg.watch}
|
2015-04-25 14:10:49 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
in {
|
|
|
|
options.services.confd = {
|
2015-06-21 15:19:46 +00:00
|
|
|
enable = mkEnableOption "confd service";
|
2015-04-25 14:10:49 +00:00
|
|
|
|
|
|
|
backend = mkOption {
|
|
|
|
description = "Confd config storage backend to use.";
|
|
|
|
default = "etcd";
|
|
|
|
type = types.enum ["etcd" "consul" "redis" "zookeeper"];
|
|
|
|
};
|
|
|
|
|
|
|
|
interval = mkOption {
|
|
|
|
description = "Confd check interval.";
|
|
|
|
default = 10;
|
|
|
|
type = types.int;
|
|
|
|
};
|
|
|
|
|
|
|
|
nodes = mkOption {
|
|
|
|
description = "Confd list of nodes to connect to.";
|
2016-09-26 21:03:31 +00:00
|
|
|
default = [ "http://127.0.0.1:2379" ];
|
2015-04-25 14:10:49 +00:00
|
|
|
type = types.listOf types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
watch = mkOption {
|
|
|
|
description = "Confd, whether to watch etcd config for changes.";
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
prefix = mkOption {
|
|
|
|
description = "The string to prefix to keys.";
|
|
|
|
default = "/";
|
|
|
|
type = types.path;
|
|
|
|
};
|
|
|
|
|
|
|
|
logLevel = mkOption {
|
|
|
|
description = "Confd log level.";
|
|
|
|
default = "info";
|
|
|
|
type = types.enum ["info" "debug"];
|
|
|
|
};
|
|
|
|
|
|
|
|
confDir = mkOption {
|
|
|
|
description = "The path to the confd configs.";
|
|
|
|
default = "/etc/confd";
|
|
|
|
type = types.path;
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
description = "Confd package to use.";
|
2015-08-29 19:55:52 +00:00
|
|
|
default = pkgs.confd;
|
2021-10-03 16:06:03 +00:00
|
|
|
defaultText = literalExpression "pkgs.confd";
|
2015-04-25 14:10:49 +00:00
|
|
|
type = types.package;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.confd = {
|
|
|
|
description = "Confd Service.";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
serviceConfig = {
|
2020-04-28 01:50:34 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/confd";
|
2015-04-25 14:10:49 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc = {
|
|
|
|
"confd/confd.toml".text = confdConfig;
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
services.etcd.enable = mkIf (cfg.backend == "etcd") (mkDefault true);
|
|
|
|
};
|
|
|
|
}
|