1{ pkgs, lib, config, ... }:
2
3with lib;
4
5let
6 cfg = config.services.thelounge;
7 dataDir = "/var/lib/thelounge";
8 configJsData = "module.exports = " + builtins.toJSON (
9 { private = cfg.private; port = cfg.port; } // cfg.extraConfig
10 );
11in {
12 options.services.thelounge = {
13 enable = mkEnableOption "The Lounge web IRC client";
14
15 private = mkOption {
16 type = types.bool;
17 default = false;
18 description = ''
19 Make your The Lounge instance private. You will need to configure user
20 accounts by using the (<command>thelounge</command>) command or by adding
21 entries in <filename>${dataDir}/users</filename>. You might need to restart
22 The Lounge after making changes to the state directory.
23 '';
24 };
25
26 port = mkOption {
27 type = types.port;
28 default = 9000;
29 description = "TCP port to listen on for http connections.";
30 };
31
32 extraConfig = mkOption {
33 default = {};
34 type = types.attrs;
35 example = literalExample ''{
36 reverseProxy = true;
37 defaults = {
38 name = "Your Network";
39 host = "localhost";
40 port = 6697;
41 };
42 }'';
43 description = ''
44 The Lounge's <filename>config.js</filename> contents as attribute set (will be
45 converted to JSON to generate the configuration file).
46
47 The options defined here will be merged to the default configuration file.
48 Note: In case of duplicate configuration, options from <option>extraConfig</option> have priority.
49
50 Documentation: <link xlink:href="https://thelounge.chat/docs/server/configuration" />
51 '';
52 };
53 };
54
55 config = mkIf cfg.enable {
56 users.users.thelounge = {
57 description = "thelounge service user";
58 group = "thelounge";
59 isSystemUser = true;
60 };
61 users.groups.thelounge = {};
62 systemd.services.thelounge = {
63 description = "The Lounge web IRC client";
64 wantedBy = [ "multi-user.target" ];
65 preStart = "ln -sf ${pkgs.writeText "config.js" configJsData} ${dataDir}/config.js";
66 serviceConfig = {
67 User = "thelounge";
68 StateDirectory = baseNameOf dataDir;
69 ExecStart = "${pkgs.thelounge}/bin/thelounge start";
70 };
71 };
72
73 environment.systemPackages = [ pkgs.thelounge ];
74 };
75}