summaryrefslogtreecommitdiffstats
path: root/krebs/3modules/Reaktor.nix
blob: 2ca7a0ee334b5954461cae4cbd1e4ee35c6918ad (plain)
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
87
88
89
90
91
92
93
94
95
96
97
{ config, pkgs,lib, ... }:


let
  kpkgs = import ../5pkgs { inherit pkgs; inherit lib; };

  inherit (lib)
    mkIf
    mkOption
    types
    singleton
    isString
    optionalString
    concatStrings
  ;

  ReaktorConfig = mkIf ( isString cfg.extraConfig )  pkgs.writeText "config.py" cfg.extraConfig;
  cfg = config.krebs.Reaktor;

  out = {
    options.krebs.Reaktor = api;
    config = mkIf cfg.enable imp;
  };

  api = {
    enable = mkOption {
      default = false;
      description = ''
        Start Reaktor at system boot
      '';
    };

    nickname = mkOption {
      default = config.krebs.build.host.name + "|r";
      type = types.str;
      description = ''
        The nick name of the irc bot.
        Defaults to {hostname}|r
      '';
    };


    extraConfig = mkOption {
      default = null;
      type = types.nullOr types.str;
      description = ''
        configuration to be used instead of default ones.
        Reaktor default cfg can be retrieved via `reaktor get-config`
      '';
    };

    ReaktorPkg = mkOption {
      default = kpkgs.Reaktor;
      description = ''
        the Reaktor pkg to use.
      '';
    };
  };

  imp = {
    # for reaktor get-config
    environment.systemPackages = [ cfg.ReaktorPkg ];

    users.extraUsers = singleton {
      name = "Reaktor";
      # uid = config.ids.uids.Reaktor;
      uid = 2066439104; #genid Reaktor
      description = "Reaktor user";
      home = "/var/lib/Reaktor";
      createHome = true;
    };

    #users.extraGroups = singleton {
    #  name = "Reaktor";
    #  gid = config.ids.gids.Reaktor;
    #};

    systemd.services.Reaktor = {
      path = with pkgs; [
        utillinux #flock for tell_on-join
        # git # for nag
        python # for caps
        ];
      description = "Reaktor IRC Bot";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];
      serviceConfig.User = "Reaktor";
      environment = {
        GIT_SSL_CAINFO = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
        IRC_NICKNAME = cfg.nickname;
        };
      serviceConfig.ExecStart = "${cfg.ReaktorPkg}/bin/reaktor run ${if (isString cfg.extraConfig) then cfg.ReaktorConfig else ""}";
    };
  };

in
out