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