From 6ca12344b39b0bd0274aca9f98a8790cab4e45d8 Mon Sep 17 00:00:00 2001 From: Jaka Hudoklin Date: Sat, 25 Apr 2015 16:10:49 +0200 Subject: [PATCH] nixos: add confd module --- nixos/modules/module-list.nix | 1 + nixos/modules/services/misc/confd.nix | 89 +++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 nixos/modules/services/misc/confd.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 17717c5988d..950bd59d988 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -184,6 +184,7 @@ ./services/misc/canto-daemon.nix ./services/misc/cpuminer-cryptonight.nix ./services/misc/cgminer.nix + ./services/misc/confd.nix ./services/misc/dictd.nix ./services/misc/disnix.nix ./services/misc/docker-registry.nix diff --git a/nixos/modules/services/misc/confd.nix b/nixos/modules/services/misc/confd.nix new file mode 100644 index 00000000000..7094bb46089 --- /dev/null +++ b/nixos/modules/services/misc/confd.nix @@ -0,0 +1,89 @@ +{ 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 = ${if cfg.watch then "true" else "false"} + ''; + +in { + options.services.confd = { + enable = mkEnableOption "Whether to enable confd service."; + + 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."; + default = [ "http://127.0.0.1:4001" ]; + 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."; + default = pkgs.goPackages.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); + }; +}