1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.quassel-webserver;
7 quassel-webserver = cfg.pkg;
8 settings = ''
9 module.exports = {
10 default: {
11 host: '${cfg.quasselCoreHost}', // quasselcore host
12 port: ${toString cfg.quasselCorePort}, // quasselcore port
13 initialBacklogLimit: ${toString cfg.initialBacklogLimit}, // Amount of backlogs to fetch per buffer on connection
14 backlogLimit: ${toString cfg.backlogLimit}, // Amount of backlogs to fetch per buffer after first retrieval
15 securecore: ${boolToString cfg.secureCore}, // Connect to the core using SSL
16 theme: '${cfg.theme}' // Default UI theme
17 },
18 themes: ['default', 'darksolarized'], // Available themes
19 forcedefault: ${boolToString cfg.forceHostAndPort}, // Will force default host and port to be used, and will hide the corresponding fields in the UI
20 prefixpath: '${cfg.prefixPath}' // Configure this if you use a reverse proxy
21 };
22 '';
23 settingsFile = pkgs.writeText "settings-user.js" settings;
24in {
25 options = {
26 services.quassel-webserver = {
27 enable = mkOption {
28 default = false;
29 type = types.bool;
30 description = "Whether to enable the quassel webclient service";
31 };
32 pkg = mkOption {
33 default = pkgs.quassel-webserver;
34 defaultText = "pkgs.quassel-webserver";
35 type = types.package;
36 description = "The quassel-webserver package";
37 };
38 quasselCoreHost = mkOption {
39 default = "";
40 type = types.str;
41 description = "The default host of the quassel core";
42 };
43 quasselCorePort = mkOption {
44 default = 4242;
45 type = types.int;
46 description = "The default quassel core port";
47 };
48 initialBacklogLimit = mkOption {
49 default = 20;
50 type = types.int;
51 description = "Amount of backlogs to fetch per buffer on connection";
52 };
53 backlogLimit = mkOption {
54 default = 100;
55 type = types.int;
56 description = "Amount of backlogs to fetch per buffer after first retrieval";
57 };
58 secureCore = mkOption {
59 default = true;
60 type = types.bool;
61 description = "Connect to the core using SSL";
62 };
63 theme = mkOption {
64 default = "default";
65 type = types.str;
66 description = "default or darksolarized";
67 };
68 prefixPath = mkOption {
69 default = "";
70 type = types.str;
71 description = "Configure this if you use a reverse proxy. Must start with a '/'";
72 example = "/quassel";
73 };
74 port = mkOption {
75 default = 60443;
76 type = types.int;
77 description = "The port the quassel webserver should listen on";
78 };
79 useHttps = mkOption {
80 default = true;
81 type = types.bool;
82 description = "Whether the quassel webserver connection should be a https connection";
83 };
84 forceHostAndPort = mkOption {
85 default = false;
86 type = types.bool;
87 description = "Force the users to use the quasselCoreHost and quasselCorePort defaults";
88 };
89 };
90 };
91
92 config = mkIf cfg.enable {
93 systemd.services.quassel-webserver = {
94 description = "A web server/client for Quassel";
95 wantedBy = [ "multi-user.target" ];
96 serviceConfig = {
97 ExecStart = "${quassel-webserver}/lib/node_modules/quassel-webserver/bin/www -p ${toString cfg.port} -m ${if cfg.useHttps == true then "https" else "http"} -c ${settingsFile}";
98 };
99 };
100 };
101}