summary refs log tree commit diff
path: root/nixos/modules/services/admin/salt/minion.nix
blob: 9ecefb32cfa8fa5713aea0a62ab0951d3b756633 (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
{ config, pkgs, lib, ... }:

with lib;

let

  cfg  = config.services.salt.minion;

  fullConfig = lib.recursiveUpdate {
    # Provide defaults for some directories to allow an immutable config dir
    # NOTE: the config dir being immutable prevents `minion_id` caching

    # Default is equivalent to /etc/salt/minion.d/*.conf
    default_include = "/var/lib/salt/minion.d/*.conf";
    # Default is in /etc/salt/pki/minion
    pki_dir = "/var/lib/salt/pki/minion";
  } cfg.configuration;
  configDir = pkgs.writeTextDir "minion" (builtins.toJSON fullConfig);

in

{
  options = {
    services.salt.minion = {
      enable = mkEnableOption "Salt minion service";
      configuration = mkOption {
        type = types.attrs;
        default = {};
        description = ''
          Salt minion configuration as Nix attribute set.
          See <link xlink:href="https://docs.saltstack.com/en/latest/ref/configuration/minion.html"/>                                                                                                 
          for details.          
        '';
      };
    };
  };

  config = mkIf cfg.enable {
    environment.systemPackages = with pkgs; [ salt ];
    systemd.services.salt-minion = {
      description = "Salt Minion";
      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" ];
      path = with pkgs; [
        utillinux
      ];
      serviceConfig = {
        ExecStart = "${pkgs.salt}/bin/salt-minion --config-dir=${configDir}";
        LimitNOFILE = 8192;
        Type = "notify";
        NotifyAccess = "all";
      };
    };
  };
}