This repository has no description
3.6 kB
121 lines
1# Copied from stockholm krebs/3modules/reaktor2.nix (cc283503); the daemon is
2# pkgs/reaktor2, stockholm's packages output does not include it.
3{
4 config,
5 lib,
6 pkgs,
7 self,
8 ...
9}:
10with lib;
11let
12 # drop null and empty attributes until nothing changes, like stockholm's
13 # converge (filterAttrsRecursive …)
14 stripAttr =
15 x:
16 let
17 y = filterAttrsRecursive (_: v: v != { } && v != null) x;
18 in
19 if y == x then x else stripAttr y;
20in
21{
22
23 options.krebs.reaktor2 = mkOption {
24 default = { };
25 type = types.attrsOf (
26 types.submodule (
27 self:
28 let
29 name = self.config._module.args.name;
30 in
31 {
32 options = {
33 nick = mkOption {
34 default = name;
35 # TODO types.irc.nickname
36 type = types.str;
37 };
38 hostname = mkOption {
39 default = "irc.r";
40 type = types.str;
41 };
42 port = mkOption {
43 default = "6667";
44 type = types.str;
45 };
46 plugins = mkOption {
47 default = [ ];
48 type = types.listOf types.attrs;
49 };
50 stateDir = mkOption {
51 default = "/var/lib/${self.config.username}";
52 defaultText = "/var/lib/‹username›";
53 readOnly = true;
54 type = types.path;
55 };
56 systemd-service-name = mkOption {
57 default = "reaktor2${optionalString (name != "default") "-${name}"}";
58 defaultText = "reaktor2-‹name› or just reaktor2 if ‹name› is \"default\"";
59 type = types.strMatching "[0-9A-Za-z._][0-9A-Za-z._-]*";
60 };
61 sendDelaySec = mkOption {
62 default = 0.7;
63 type = types.nullOr types.float;
64 };
65 username = mkOption {
66 default = self.config.systemd-service-name;
67 defaultText = "‹systemd-service-name›";
68 type = types.strMatching "[0-9A-Za-z._][0-9A-Za-z._-]*";
69 };
70 useTLS = mkOption {
71 default = self.config.port == "6697";
72 type = types.bool;
73 };
74 API.listen = mkOption {
75 default = null;
76 type = types.nullOr types.str;
77 };
78 };
79 }
80 )
81 );
82 };
83
84 config = {
85 systemd.services = flip mapAttrs' config.krebs.reaktor2 (
86 _: cfg:
87 nameValuePair cfg.systemd-service-name {
88 after = [ "network.target" ];
89 environment = {
90 LC_ALL = "en_US.UTF-8";
91 };
92 wantedBy = [ "multi-user.target" ];
93 serviceConfig = {
94 User = cfg.username;
95 Group = "reaktor2";
96 DynamicUser = true;
97 StateDirectory = cfg.username;
98 #ExecStartPre = [
99 # (pkgs.writers.writeDash "test-dynamic-user" ''
100 # set -efux
101 # ${pkgs.coreutils}/bin/id
102 # '')
103 #];
104 ExecStart =
105 let
106 configFile = pkgs.writers.writeJSON configFileName configValue;
107 configFileName = "${cfg.systemd-service-name}.config.json";
108 configValue = stripAttr (
109 recursiveUpdate {
110 logTime = false;
111 } (removeAttrs cfg [ "_module" ])
112 );
113 in
114 "${self.packages.${pkgs.stdenv.hostPlatform.system}.reaktor2}/bin/reaktor ${configFile}";
115 Restart = "always";
116 RestartSec = "30";
117 };
118 }
119 );
120 };
121}