1 { config, pkgs, lib, ... }:
3 cfg = config.services.confd;
6 backend = "${cfg.backend}"
7 confdir = "${cfg.confDir}"
8 interval = ${toString cfg.interval}
9 nodes = [ ${lib.concatMapStringsSep "," (s: ''"${s}"'') cfg.nodes}, ]
10 prefix = "${cfg.prefix}"
11 log-level = "${cfg.logLevel}"
12 watch = ${lib.boolToString cfg.watch}
16 options.services.confd = {
17 enable = lib.mkEnableOption "confd, a service to manage local application configuration files using templates and data from etcd/consul/redis/zookeeper";
19 backend = lib.mkOption {
20 description = "Confd config storage backend to use.";
22 type = lib.types.enum ["etcd" "consul" "redis" "zookeeper"];
25 interval = lib.mkOption {
26 description = "Confd check interval.";
31 nodes = lib.mkOption {
32 description = "Confd list of nodes to connect to.";
33 default = [ "http://127.0.0.1:2379" ];
34 type = lib.types.listOf lib.types.str;
37 watch = lib.mkOption {
38 description = "Confd, whether to watch etcd config for changes.";
40 type = lib.types.bool;
43 prefix = lib.mkOption {
44 description = "The string to prefix to keys.";
46 type = lib.types.path;
49 logLevel = lib.mkOption {
50 description = "Confd log level.";
52 type = lib.types.enum ["info" "debug"];
55 confDir = lib.mkOption {
56 description = "The path to the confd configs.";
57 default = "/etc/confd";
58 type = lib.types.path;
61 package = lib.mkPackageOption pkgs "confd" { };
64 config = lib.mkIf cfg.enable {
65 systemd.services.confd = {
66 description = "Confd Service.";
67 wantedBy = [ "multi-user.target" ];
68 after = [ "network.target" ];
70 ExecStart = "${cfg.package}/bin/confd";
75 "confd/confd.toml".text = confdConfig;
78 environment.systemPackages = [ cfg.package ];
80 services.etcd.enable = lib.mkIf (cfg.backend == "etcd") (lib.mkDefault true);