about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/networking/lambdabot.nix
blob: 01914097ad72696095fced8d2cad09f816dc50d8 (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
{ 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 = lib.mdDoc "Enable the Lambdabot IRC bot";
      };

      package = mkPackageOption pkgs "lambdabot" { };

      script = mkOption {
        type = types.str;
        default = "";
        description = lib.mdDoc "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;

  };

}