1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.gollum;
7in
8
9{
10 options.services.gollum = {
11 enable = mkEnableOption (lib.mdDoc "Gollum service");
12
13 address = mkOption {
14 type = types.str;
15 default = "0.0.0.0";
16 description = lib.mdDoc "IP address on which the web server will listen.";
17 };
18
19 port = mkOption {
20 type = types.port;
21 default = 4567;
22 description = lib.mdDoc "Port on which the web server will run.";
23 };
24
25 extraConfig = mkOption {
26 type = types.lines;
27 default = "";
28 description = lib.mdDoc "Content of the configuration file";
29 };
30
31 mathjax = mkOption {
32 type = types.bool;
33 default = false;
34 description = lib.mdDoc "Enable support for math rendering using MathJax";
35 };
36
37 allowUploads = mkOption {
38 type = types.nullOr (types.enum [ "dir" "page" ]);
39 default = null;
40 description = lib.mdDoc "Enable uploads of external files";
41 };
42
43 user-icons = mkOption {
44 type = types.nullOr (types.enum [ "gravatar" "identicon" ]);
45 default = null;
46 description = lib.mdDoc "Enable specific user icons for history view";
47 };
48
49 emoji = mkOption {
50 type = types.bool;
51 default = false;
52 description = lib.mdDoc "Parse and interpret emoji tags";
53 };
54
55 h1-title = mkOption {
56 type = types.bool;
57 default = false;
58 description = lib.mdDoc "Use the first h1 as page title";
59 };
60
61 no-edit = mkOption {
62 type = types.bool;
63 default = false;
64 description = lib.mdDoc "Disable editing pages";
65 };
66
67 local-time = mkOption {
68 type = types.bool;
69 default = false;
70 description = lib.mdDoc "Use the browser's local timezone instead of the server's for displaying dates.";
71 };
72
73 branch = mkOption {
74 type = types.str;
75 default = "master";
76 example = "develop";
77 description = lib.mdDoc "Git branch to serve";
78 };
79
80 stateDir = mkOption {
81 type = types.path;
82 default = "/var/lib/gollum";
83 description = lib.mdDoc "Specifies the path of the repository directory. If it does not exist, Gollum will create it on startup.";
84 };
85
86 package = mkOption {
87 type = types.package;
88 default = pkgs.gollum;
89 defaultText = literalExpression "pkgs.gollum";
90 description = lib.mdDoc ''
91 The package used in the service
92 '';
93 };
94 };
95
96 config = mkIf cfg.enable {
97
98 users.users.gollum = {
99 group = config.users.users.gollum.name;
100 description = "Gollum user";
101 createHome = false;
102 isSystemUser = true;
103 };
104
105 users.groups.gollum = { };
106
107 systemd.tmpfiles.rules = [
108 "d '${cfg.stateDir}' - ${config.users.users.gollum.name} ${config.users.groups.gollum.name} - -"
109 ];
110
111 systemd.services.gollum = {
112 description = "Gollum wiki";
113 after = [ "network.target" ];
114 wantedBy = [ "multi-user.target" ];
115 path = [ pkgs.git ];
116
117 preStart = ''
118 # This is safe to be run on an existing repo
119 git init ${cfg.stateDir}
120 '';
121
122 serviceConfig = {
123 User = config.users.users.gollum.name;
124 Group = config.users.groups.gollum.name;
125 WorkingDirectory = cfg.stateDir;
126 ExecStart = ''
127 ${cfg.package}/bin/gollum \
128 --port ${toString cfg.port} \
129 --host ${cfg.address} \
130 --config ${pkgs.writeText "gollum-config.rb" cfg.extraConfig} \
131 --ref ${cfg.branch} \
132 ${optionalString cfg.mathjax "--mathjax"} \
133 ${optionalString cfg.emoji "--emoji"} \
134 ${optionalString cfg.h1-title "--h1-title"} \
135 ${optionalString cfg.no-edit "--no-edit"} \
136 ${optionalString cfg.local-time "--local-time"} \
137 ${optionalString (cfg.allowUploads != null) "--allow-uploads ${cfg.allowUploads}"} \
138 ${optionalString (cfg.user-icons != null) "--user-icons ${cfg.user-icons}"} \
139 ${cfg.stateDir}
140 '';
141 };
142 };
143 };
144
145 meta.maintainers = with lib.maintainers; [ erictapen bbenno ];
146}