summary refs log tree commit diff
path: root/nixos/modules/services/web-apps/quassel-webserver.nix
blob: 2ba5698d6cb1bad11464d51c04d3637156d09e5b (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.quassel-webserver;
  quassel-webserver = cfg.pkg;
  settings = ''
    module.exports = {
      default: {
        host: '${cfg.quasselCoreHost}',  // quasselcore host
        port: ${toString cfg.quasselCorePort},  // quasselcore port
        initialBacklogLimit: ${toString cfg.initialBacklogLimit},  // Amount of backlogs to fetch per buffer on connection
        backlogLimit: ${toString cfg.backlogLimit},  // Amount of backlogs to fetch per buffer after first retrieval
        securecore: ${boolToString cfg.secureCore},  // Connect to the core using SSL
        theme: '${cfg.theme}'  // Default UI theme
      },
      themes: ['default', 'darksolarized'],  //  Available themes
      forcedefault: ${boolToString cfg.forceHostAndPort},  // Will force default host and port to be used, and will hide the corresponding fields in the UI
      prefixpath: '${cfg.prefixPath}'  // Configure this if you use a reverse proxy
    };
  '';
  settingsFile = pkgs.writeText "settings-user.js" settings;
in {
  options = {
    services.quassel-webserver = {
      enable = mkOption {
        default = false;
        type = types.bool;
        description = "Whether to enable the quassel webclient service";
      };
      pkg = mkOption {
        default = pkgs.quassel-webserver;
        defaultText = "pkgs.quassel-webserver";
        type = types.package;
        description = "The quassel-webserver package";
      };
      quasselCoreHost = mkOption {
        default = "";
        type = types.str;
        description = "The default host of the quassel core";
      };
      quasselCorePort = mkOption {
        default = 4242;
        type = types.int;
        description = "The default quassel core port";
      };
      initialBacklogLimit = mkOption {
        default = 20;
        type = types.int;
        description = "Amount of backlogs to fetch per buffer on connection";
      };
      backlogLimit = mkOption {
        default = 100;
        type = types.int;
        description = "Amount of backlogs to fetch per buffer after first retrieval";
      };
      secureCore = mkOption {
        default = true;
        type = types.bool;
        description = "Connect to the core using SSL";
      };
      theme = mkOption {
        default = "default";
        type = types.str;
        description = "default or darksolarized";
      };
      prefixPath = mkOption {
        default = "";
        type = types.str;
        description = "Configure this if you use a reverse proxy. Must start with a '/'";
        example = "/quassel";
      };
      port = mkOption {
        default = 60443;
        type = types.int;
        description = "The port the quassel webserver should listen on";
      };
      useHttps = mkOption {
        default = true;
        type = types.bool;
        description = "Whether the quassel webserver connection should be a https connection";
      };
      forceHostAndPort = mkOption {
        default = false;
        type = types.bool;
        description = "Force the users to use the quasselCoreHost and quasselCorePort defaults";
      };
    };
  };

  config = mkIf cfg.enable {
    systemd.services.quassel-webserver = {
      description = "A web server/client for Quassel";
      wantedBy = [ "multi-user.target" ];
      serviceConfig = {
        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}";
      };
    };
  };
}