2015-04-25 16:10:49 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.services.confd;
|
|
|
|
|
|
|
|
confdConfig = ''
|
|
|
|
backend = "${cfg.backend}"
|
|
|
|
confdir = "${cfg.confDir}"
|
|
|
|
interval = ${toString cfg.interval}
|
2024-08-24 22:05:40 +02:00
|
|
|
nodes = [ ${lib.concatMapStringsSep "," (s: ''"${s}"'') cfg.nodes}, ]
|
2015-04-25 16:10:49 +02:00
|
|
|
prefix = "${cfg.prefix}"
|
|
|
|
log-level = "${cfg.logLevel}"
|
2024-08-24 22:05:40 +02:00
|
|
|
watch = ${lib.boolToString cfg.watch}
|
2015-04-25 16:10:49 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.confd = {
|
2024-08-24 22:05:40 +02:00
|
|
|
enable = lib.mkEnableOption "confd, a service to manage local application configuration files using templates and data from etcd/consul/redis/zookeeper";
|
2015-04-25 16:10:49 +02:00
|
|
|
|
2024-08-24 22:05:40 +02:00
|
|
|
backend = lib.mkOption {
|
2015-04-25 16:10:49 +02:00
|
|
|
description = "Confd config storage backend to use.";
|
|
|
|
default = "etcd";
|
2024-08-24 22:05:40 +02:00
|
|
|
type = lib.types.enum [
|
|
|
|
"etcd"
|
|
|
|
"consul"
|
|
|
|
"redis"
|
|
|
|
"zookeeper"
|
|
|
|
];
|
2015-04-25 16:10:49 +02:00
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:40 +02:00
|
|
|
interval = lib.mkOption {
|
2015-04-25 16:10:49 +02:00
|
|
|
description = "Confd check interval.";
|
|
|
|
default = 10;
|
2024-08-24 22:05:40 +02:00
|
|
|
type = lib.types.int;
|
2015-04-25 16:10:49 +02:00
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:40 +02:00
|
|
|
nodes = lib.mkOption {
|
2015-04-25 16:10:49 +02:00
|
|
|
description = "Confd list of nodes to connect to.";
|
2016-09-26 23:03:31 +02:00
|
|
|
default = [ "http://127.0.0.1:2379" ];
|
2024-08-24 22:05:40 +02:00
|
|
|
type = lib.types.listOf lib.types.str;
|
2015-04-25 16:10:49 +02:00
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:40 +02:00
|
|
|
watch = lib.mkOption {
|
2015-04-25 16:10:49 +02:00
|
|
|
description = "Confd, whether to watch etcd config for changes.";
|
|
|
|
default = true;
|
2024-08-24 22:05:40 +02:00
|
|
|
type = lib.types.bool;
|
2015-04-25 16:10:49 +02:00
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:40 +02:00
|
|
|
prefix = lib.mkOption {
|
2015-04-25 16:10:49 +02:00
|
|
|
description = "The string to prefix to keys.";
|
|
|
|
default = "/";
|
2024-08-24 22:05:40 +02:00
|
|
|
type = lib.types.path;
|
2015-04-25 16:10:49 +02:00
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:40 +02:00
|
|
|
logLevel = lib.mkOption {
|
2015-04-25 16:10:49 +02:00
|
|
|
description = "Confd log level.";
|
|
|
|
default = "info";
|
2024-08-24 22:05:40 +02:00
|
|
|
type = lib.types.enum [
|
|
|
|
"info"
|
|
|
|
"debug"
|
|
|
|
];
|
2015-04-25 16:10:49 +02:00
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:40 +02:00
|
|
|
confDir = lib.mkOption {
|
2015-04-25 16:10:49 +02:00
|
|
|
description = "The path to the confd configs.";
|
|
|
|
default = "/etc/confd";
|
2024-08-24 22:05:40 +02:00
|
|
|
type = lib.types.path;
|
2015-04-25 16:10:49 +02:00
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:40 +02:00
|
|
|
package = lib.mkPackageOption pkgs "confd" { };
|
2015-04-25 16:10:49 +02:00
|
|
|
};
|
|
|
|
|
2024-08-24 22:05:40 +02:00
|
|
|
config = lib.mkIf cfg.enable {
|
2015-04-25 16:10:49 +02:00
|
|
|
systemd.services.confd = {
|
|
|
|
description = "Confd Service.";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
serviceConfig = {
|
2020-04-28 11:50:34 +10:00
|
|
|
ExecStart = "${cfg.package}/bin/confd";
|
2015-04-25 16:10:49 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc = {
|
|
|
|
"confd/confd.toml".text = confdConfig;
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
2024-08-24 22:05:40 +02:00
|
|
|
services.etcd.enable = lib.mkIf (cfg.backend == "etcd") (lib.mkDefault true);
|
2015-04-25 16:10:49 +02:00
|
|
|
};
|
|
|
|
}
|