lol

Merge pull request #7565 from offlinehacker/nixos/confd/module

nixos: add confd module

+90
+1
nixos/modules/module-list.nix
··· 186 186 ./services/misc/canto-daemon.nix 187 187 ./services/misc/cpuminer-cryptonight.nix 188 188 ./services/misc/cgminer.nix 189 + ./services/misc/confd.nix 189 190 ./services/misc/dictd.nix 190 191 ./services/misc/disnix.nix 191 192 ./services/misc/docker-registry.nix
+89
nixos/modules/services/misc/confd.nix
··· 1 + { config, pkgs, lib, ... }: 2 + 3 + with lib; 4 + 5 + let 6 + cfg = config.services.confd; 7 + 8 + confdConfig = '' 9 + backend = "${cfg.backend}" 10 + confdir = "${cfg.confDir}" 11 + interval = ${toString cfg.interval} 12 + nodes = [ ${concatMapStringsSep "," (s: ''"${s}"'') cfg.nodes}, ] 13 + prefix = "${cfg.prefix}" 14 + log-level = "${cfg.logLevel}" 15 + watch = ${if cfg.watch then "true" else "false"} 16 + ''; 17 + 18 + in { 19 + options.services.confd = { 20 + enable = mkEnableOption "Whether to enable confd service."; 21 + 22 + backend = mkOption { 23 + description = "Confd config storage backend to use."; 24 + default = "etcd"; 25 + type = types.enum ["etcd" "consul" "redis" "zookeeper"]; 26 + }; 27 + 28 + interval = mkOption { 29 + description = "Confd check interval."; 30 + default = 10; 31 + type = types.int; 32 + }; 33 + 34 + nodes = mkOption { 35 + description = "Confd list of nodes to connect to."; 36 + default = [ "http://127.0.0.1:4001" ]; 37 + type = types.listOf types.str; 38 + }; 39 + 40 + watch = mkOption { 41 + description = "Confd, whether to watch etcd config for changes."; 42 + default = true; 43 + type = types.bool; 44 + }; 45 + 46 + prefix = mkOption { 47 + description = "The string to prefix to keys."; 48 + default = "/"; 49 + type = types.path; 50 + }; 51 + 52 + logLevel = mkOption { 53 + description = "Confd log level."; 54 + default = "info"; 55 + type = types.enum ["info" "debug"]; 56 + }; 57 + 58 + confDir = mkOption { 59 + description = "The path to the confd configs."; 60 + default = "/etc/confd"; 61 + type = types.path; 62 + }; 63 + 64 + package = mkOption { 65 + description = "Confd package to use."; 66 + default = pkgs.goPackages.confd; 67 + type = types.package; 68 + }; 69 + }; 70 + 71 + config = mkIf cfg.enable { 72 + systemd.services.confd = { 73 + description = "Confd Service."; 74 + wantedBy = [ "multi-user.target" ]; 75 + after = [ "network.target" ]; 76 + serviceConfig = { 77 + ExecStart = "${cfg.package}/bin/confd"; 78 + }; 79 + }; 80 + 81 + environment.etc = { 82 + "confd/confd.toml".text = confdConfig; 83 + }; 84 + 85 + environment.systemPackages = [ cfg.package ]; 86 + 87 + services.etcd.enable = mkIf (cfg.backend == "etcd") (mkDefault true); 88 + }; 89 + }