summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/misc/conman.nix
blob: 8d00b0353d6dc03faf576b1799e64afc6dc79e05 (plain)
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
{
  config,
  lib,
  pkgs,
  ...
}:

{
  options = {
    services.conman = {
      enable = lib.mkEnableOption ''
        Enable the conman Console manager.

        Either `configFile` or `config` must be specified.
      '';
      package = lib.mkPackageOption pkgs "conman" { };

      configFile = lib.mkOption {
        type = lib.types.nullOr lib.types.path;
        default = null;
        example = "/run/secrets/conman.conf";
        description = ''
          The absolute path to the configuration file.

          Either `configFile` or `config` must be specified.

          See <https://github.com/dun/conman/wiki/Man-5-conman.conf#files>.
        '';
      };
      config = lib.mkOption {
        type = lib.types.nullOr lib.types.lines;
        default = null;
        example = ''
          server coredump=off
          server keepalive=on
          server loopback=off
          server timestamp=1h

          # global config
          global log="/var/log/conman/%N.log"
          global seropts="9600,8n1"
          global ipmiopts="U:<user>,P:<password>"
        '';
        description = ''
          The configuration object.

          Either `configFile` or `config` must be specified.

          See <https://github.com/dun/conman/wiki/Man-5-conman.conf#files>.
        '';
      };
    };
  };
  meta.maintainers = with lib.maintainers; [
    frantathefranta
  ];

  config =
    let
      cfg = config.services.conman;
      configFile =
        if cfg.configFile != null then
          cfg.configFile
        else
          pkgs.writeTextFile {
            name = "conman.conf";
            text = cfg.config;
          };
    in
    lib.mkIf cfg.enable {
      assertions = [
        {
          assertion =
            (cfg.configFile != null) && (cfg.config == null) || (cfg.configFile == null && cfg.config != null);
          message = "Either but not both `configFile` and `config` must be specified for conman.";
        }
      ];
      environment.systemPackages = [ cfg.package ];
      systemd.services.conmand = {
        description = "serial console management program";
        documentation = [ "man:conman(8)" ];
        wantedBy = [ "multi-user.target" ];
        serviceConfig = {
          ExecStart = "${cfg.package}/bin/conmand -F -c ${configFile}";
          KillMode = "process";
        };
      };
    };
}