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 = mkOption {
28 type = types.package;
29 default = pkgs.lambdabot;
30 defaultText = "pkgs.lambdabot";
31 description = "Used lambdabot package";
32 };
33
34 script = mkOption {
35 type = types.str;
36 default = "";
37 description = "Lambdabot script";
38 };
39
40 };
41
42 };
43
44 ### implementation
45
46 config = mkIf cfg.enable {
47
48 systemd.services.lambdabot = {
49 description = "Lambdabot daemon";
50 after = [ "network.target" ];
51 wantedBy = [ "multi-user.target" ];
52 # Workaround for https://github.com/lambdabot/lambdabot/issues/117
53 script = ''
54 mkdir -p ~/.lambdabot
55 cd ~/.lambdabot
56 mkfifo /run/lambdabot/offline
57 (
58 echo 'rc ${rc}'
59 while true; do
60 cat /run/lambdabot/offline
61 done
62 ) | ${cfg.package}/bin/lambdabot
63 '';
64 serviceConfig = {
65 User = "lambdabot";
66 RuntimeDirectory = [ "lambdabot" ];
67 };
68 };
69
70 users.extraUsers.lambdabot = {
71 group = "lambdabot";
72 description = "Lambdabot daemon user";
73 home = "/var/lib/lambdabot";
74 createHome = true;
75 uid = config.ids.uids.lambdabot;
76 };
77
78 users.extraGroups.lambdabot.gid = config.ids.gids.lambdabot;
79
80 };
81
82}