about summary refs log tree commit diff
path: root/nixos/modules/services/misc/confd.nix
blob: 17c1be57ccbcd25decf920ee0cd0b33e7e98f076 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{ 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 = {
    enable = mkEnableOption (lib.mdDoc "confd service");

    backend = mkOption {
      description = lib.mdDoc "Confd config storage backend to use.";
      default = "etcd";
      type = types.enum ["etcd" "consul" "redis" "zookeeper"];
    };

    interval = mkOption {
      description = lib.mdDoc "Confd check interval.";
      default = 10;
      type = types.int;
    };

    nodes = mkOption {
      description = lib.mdDoc "Confd list of nodes to connect to.";
      default = [ "http://127.0.0.1:2379" ];
      type = types.listOf types.str;
    };

    watch = mkOption {
      description = lib.mdDoc "Confd, whether to watch etcd config for changes.";
      default = true;
      type = types.bool;
    };

    prefix = mkOption {
      description = lib.mdDoc "The string to prefix to keys.";
      default = "/";
      type = types.path;
    };

    logLevel = mkOption {
      description = lib.mdDoc "Confd log level.";
      default = "info";
      type = types.enum ["info" "debug"];
    };

    confDir = mkOption {
      description = lib.mdDoc "The path to the confd configs.";
      default = "/etc/confd";
      type = types.path;
    };

    package = mkOption {
      description = lib.mdDoc "Confd package to use.";
      default = pkgs.confd;
      defaultText = literalExpression "pkgs.confd";
      type = types.package;
    };
  };

  config = mkIf cfg.enable {
    systemd.services.confd = {
      description = "Confd Service.";
      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" ];
      serviceConfig = {
        ExecStart = "${cfg.package}/bin/confd";
      };
    };

    environment.etc = {
      "confd/confd.toml".text = confdConfig;
    };

    environment.systemPackages = [ cfg.package ];

    services.etcd.enable = mkIf (cfg.backend == "etcd") (mkDefault true);
  };
}