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 user = mkOption {
96 type = types.str;
97 default = "gollum";
98 description = lib.mdDoc "Specifies the owner of the wiki directory";
99 };
100
101 group = mkOption {
102 type = types.str;
103 default = "gollum";
104 description = lib.mdDoc "Specifies the owner group of the wiki directory";
105 };
106 };
107
108 config = mkIf cfg.enable {
109
110 users.users.gollum = mkIf (cfg.user == "gollum") {
111 group = cfg.group;
112 description = "Gollum user";
113 createHome = false;
114 isSystemUser = true;
115 };
116
117 users.groups."${cfg.group}" = { };
118
119 systemd.tmpfiles.rules = [
120 "d '${cfg.stateDir}' - ${config.users.users.gollum.name} ${config.users.groups.gollum.name} - -"
121 ];
122
123 systemd.services.gollum = {
124 description = "Gollum wiki";
125 after = [ "network.target" ];
126 wantedBy = [ "multi-user.target" ];
127 path = [ pkgs.git ];
128
129 preStart = ''
130 # This is safe to be run on an existing repo
131 git init ${cfg.stateDir}
132 '';
133
134 serviceConfig = {
135 User = cfg.user;
136 Group = cfg.group;
137 WorkingDirectory = cfg.stateDir;
138 ExecStart = ''
139 ${cfg.package}/bin/gollum \
140 --port ${toString cfg.port} \
141 --host ${cfg.address} \
142 --config ${pkgs.writeText "gollum-config.rb" cfg.extraConfig} \
143 --ref ${cfg.branch} \
144 ${optionalString cfg.mathjax "--mathjax"} \
145 ${optionalString cfg.emoji "--emoji"} \
146 ${optionalString cfg.h1-title "--h1-title"} \
147 ${optionalString cfg.no-edit "--no-edit"} \
148 ${optionalString cfg.local-time "--local-time"} \
149 ${optionalString (cfg.allowUploads != null) "--allow-uploads ${cfg.allowUploads}"} \
150 ${optionalString (cfg.user-icons != null) "--user-icons ${cfg.user-icons}"} \
151 ${cfg.stateDir}
152 '';
153 };
154 };
155 };
156
157 meta.maintainers = with lib.maintainers; [ erictapen bbenno ];
158}