summary refs log tree commit diff
path: root/nixos/modules/services/networking/lambdabot.nix
blob: 3005e58245546d35d015b862799df22fce709b2c (plain) (blame)
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
{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.services.lambdabot;

  rc = builtins.toFile "script.rc" cfg.script;

in

{

  ### configuration

  options = {

    services.lambdabot = {

      enable = mkOption {
        type = types.bool;
        default = false;
        description = "Enable the Lambdabot IRC bot";
      };

      package = mkOption {
        type = types.package;
        default = pkgs.lambdabot;
        defaultText = literalExpression "pkgs.lambdabot";
        description = "Used lambdabot package";
      };

      script = mkOption {
        type = types.str;
        default = "";
        description = "Lambdabot script";
      };

    };

  };

  ### implementation

  config = mkIf cfg.enable {

    systemd.services.lambdabot = {
      description = "Lambdabot daemon";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];
      # Workaround for https://github.com/lambdabot/lambdabot/issues/117
      script = ''
        mkdir -p ~/.lambdabot
        cd ~/.lambdabot
        mkfifo /run/lambdabot/offline
        (
          echo 'rc ${rc}'
          while true; do
            cat /run/lambdabot/offline
          done
        ) | ${cfg.package}/bin/lambdabot
      '';
      serviceConfig = {
        User = "lambdabot";
        RuntimeDirectory = [ "lambdabot" ];
      };
    };

    users.users.lambdabot = {
      group = "lambdabot";
      description = "Lambdabot daemon user";
      home = "/var/lib/lambdabot";
      createHome = true;
      uid = config.ids.uids.lambdabot;
    };

    users.groups.lambdabot.gid = config.ids.gids.lambdabot;

  };

}