1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfg = config.services.lambdabot;
8
9 rc = builtins.toFile "script.rc" cfg.script;
10
11in
12
13{
14
15 ### configuration
16
17 options = {
18
19 services.lambdabot = {
20
21 enable = mkOption {
22 type = types.bool;
23 default = false;
24 description = "Enable the Lambdabot IRC bot";
25 };
26
27 package = mkPackageOption pkgs "lambdabot" { };
28
29 script = mkOption {
30 type = types.str;
31 default = "";
32 description = "Lambdabot script";
33 };
34
35 };
36
37 };
38
39 ### implementation
40
41 config = mkIf cfg.enable {
42
43 systemd.services.lambdabot = {
44 description = "Lambdabot daemon";
45 after = [ "network.target" ];
46 wantedBy = [ "multi-user.target" ];
47 # Workaround for https://github.com/lambdabot/lambdabot/issues/117
48 script = ''
49 mkdir -p ~/.lambdabot
50 cd ~/.lambdabot
51 mkfifo /run/lambdabot/offline
52 (
53 echo 'rc ${rc}'
54 while true; do
55 cat /run/lambdabot/offline
56 done
57 ) | ${cfg.package}/bin/lambdabot
58 '';
59 serviceConfig = {
60 User = "lambdabot";
61 RuntimeDirectory = [ "lambdabot" ];
62 };
63 };
64
65 users.users.lambdabot = {
66 group = "lambdabot";
67 description = "Lambdabot daemon user";
68 home = "/var/lib/lambdabot";
69 createHome = true;
70 uid = config.ids.uids.lambdabot;
71 };
72
73 users.groups.lambdabot.gid = config.ids.gids.lambdabot;
74
75 };
76
77}