summary refs log tree commit diff
path: root/nixos/modules/services/networking/supybot.nix
blob: 92c84bd0e1e2f72ee9e1959034459aaf27461d6d (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
83
84
85
86
{ config, lib, pkgs, ... }:

with lib;

let

  cfg  = config.services.supybot;

in

{

  options = {

    services.supybot = {

      enable = mkOption {
        default = false;
        description = "Enable Supybot, an IRC bot";
      };

      stateDir = mkOption {
        # Setting this to /var/lib/supybot caused useradd to fail
        default = "/home/supybot";
        description = "The root directory, logs and plugins are stored here";
      };

      configFile = mkOption {
        type = types.path;
        description = ''
          Path to a supybot config file. This can be generated by
          running supybot-wizard.

          Note: all paths should include the full path to the stateDir
          directory (backup conf data logs logs/plugins plugins tmp web).
        '';
      };

    };

  };


  config = mkIf cfg.enable {

    environment.systemPackages = [ pkgs.pythonPackages.limnoria ];

    users.users.supybotrs = {
      uid = config.ids.uids.supybot;
      group = "supybot";
      description = "Supybot IRC bot user";
      home = cfg.stateDir;
      createHome = true;
    };

    users.groups.supybot = {
      gid = config.ids.gids.supybot;
    };

    systemd.services.supybot = {
      description = "Supybot, an IRC bot";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];
      path = [ pkgs.pythonPackages.limnoria ];
      preStart = ''
        cd ${cfg.stateDir}
        mkdir -p backup conf data plugins logs/plugins tmp web
        ln -sf ${cfg.configFile} supybot.cfg
        # This needs to be created afresh every time
        rm -f supybot.cfg.bak
      '';

      serviceConfig = {
        ExecStart = "${pkgs.pythonPackages.limnoria}/bin/supybot ${cfg.stateDir}/supybot.cfg";
        PIDFile = "/run/supybot.pid";
        User = "supybot";
        Group = "supybot";
        UMask = "0007";
        Restart = "on-abort";
        StartLimitInterval = "5m";
        StartLimitBurst = "1";
      };
    };

  };
}