1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8{
9 options = {
10 services.conman = {
11 enable = lib.mkEnableOption ''
12 Enable the conman Console manager.
13
14 Either `configFile` or `config` must be specified.
15 '';
16 package = lib.mkPackageOption pkgs "conman" { };
17
18 configFile = lib.mkOption {
19 type = lib.types.nullOr lib.types.path;
20 default = null;
21 example = "/run/secrets/conman.conf";
22 description = ''
23 The absolute path to the configuration file.
24
25 Either `configFile` or `config` must be specified.
26
27 See <https://github.com/dun/conman/wiki/Man-5-conman.conf#files>.
28 '';
29 };
30 config = lib.mkOption {
31 type = lib.types.nullOr lib.types.lines;
32 default = null;
33 example = ''
34 server coredump=off
35 server keepalive=on
36 server loopback=off
37 server timestamp=1h
38
39 # global config
40 global log="/var/log/conman/%N.log"
41 global seropts="9600,8n1"
42 global ipmiopts="U:<user>,P:<password>"
43 '';
44 description = ''
45 The configuration object.
46
47 Either `configFile` or `config` must be specified.
48
49 See <https://github.com/dun/conman/wiki/Man-5-conman.conf#files>.
50 '';
51 };
52 };
53 };
54 meta.maintainers = with lib.maintainers; [
55 frantathefranta
56 ];
57
58 config =
59 let
60 cfg = config.services.conman;
61 configFile =
62 if cfg.configFile != null then
63 cfg.configFile
64 else
65 pkgs.writeTextFile {
66 name = "conman.conf";
67 text = cfg.config;
68 };
69 in
70 lib.mkIf cfg.enable {
71 assertions = [
72 {
73 assertion =
74 (cfg.configFile != null) && (cfg.config == null) || (cfg.configFile == null && cfg.config != null);
75 message = "Either but not both `configFile` and `config` must be specified for conman.";
76 }
77 ];
78 environment.systemPackages = [ cfg.package ];
79 systemd.services.conmand = {
80 description = "serial console management program";
81 documentation = [ "man:conman(8)" ];
82 wantedBy = [ "multi-user.target" ];
83 serviceConfig = {
84 ExecStart = "${cfg.package}/bin/conmand -F -c ${configFile}";
85 KillMode = "process";
86 };
87 };
88 };
89}