2020-04-24 23:36:52 +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}"
|
|
|
|
watch = ${boolToString cfg.watch}
|
|
|
|
'';
|
|
|
|
|
|
|
|
in {
|
|
|
|
options.services.confd = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "confd service");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
backend = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Confd config storage backend to use.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "etcd";
|
|
|
|
type = types.enum ["etcd" "consul" "redis" "zookeeper"];
|
|
|
|
};
|
|
|
|
|
|
|
|
interval = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Confd check interval.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 10;
|
|
|
|
type = types.int;
|
|
|
|
};
|
|
|
|
|
|
|
|
nodes = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Confd list of nodes to connect to.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = [ "http://127.0.0.1:2379" ];
|
|
|
|
type = types.listOf types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
watch = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Confd, whether to watch etcd config for changes.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
prefix = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The string to prefix to keys.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "/";
|
|
|
|
type = types.path;
|
|
|
|
};
|
|
|
|
|
|
|
|
logLevel = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Confd log level.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "info";
|
|
|
|
type = types.enum ["info" "debug"];
|
|
|
|
};
|
|
|
|
|
|
|
|
confDir = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The path to the confd configs.";
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "/etc/confd";
|
|
|
|
type = types.path;
|
|
|
|
};
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "confd" { };
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.confd = {
|
|
|
|
description = "Confd Service.";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
serviceConfig = {
|
2020-05-15 21:57:56 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/confd";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc = {
|
|
|
|
"confd/confd.toml".text = confdConfig;
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
services.etcd.enable = mkIf (cfg.backend == "etcd") (mkDefault true);
|
|
|
|
};
|
|
|
|
}
|