9 inherit (lib) mkOption types literalExpression;
11 cfg = config.services.hedgedoc;
13 # 21.03 will not be an official release - it was instead 21.05. This
14 # versionAtLeast statement remains set to 21.03 for backwards compatibility.
15 # See https://github.com/NixOS/nixpkgs/pull/108899 and
16 # https://github.com/NixOS/rfcs/blob/master/rfcs/0080-nixos-release-schedule.md.
17 name = if lib.versionAtLeast config.system.stateVersion "21.03" then "hedgedoc" else "codimd";
19 settingsFormat = pkgs.formats.json { };
22 meta.maintainers = with lib.maintainers; [
28 (lib.mkRenamedOptionModule [ "services" "codimd" ] [ "services" "hedgedoc" ])
29 (lib.mkRenamedOptionModule
30 [ "services" "hedgedoc" "configuration" ]
31 [ "services" "hedgedoc" "settings" ]
33 (lib.mkRenamedOptionModule
34 [ "services" "hedgedoc" "groups" ]
35 [ "users" "users" "hedgedoc" "extraGroups" ]
37 (lib.mkRemovedOptionModule [ "services" "hedgedoc" "workDir" ] ''
38 This option has been removed in favor of systemd managing the state directory.
40 If you have set this option without specifying `services.hedgedoc.settings.uploadsPath`,
41 please move these files to `/var/lib/hedgedoc/uploads`, or set the option to point
42 at the correct location.
46 options.services.hedgedoc = {
47 package = lib.mkPackageOption pkgs "hedgedoc" { };
48 enable = lib.mkEnableOption "the HedgeDoc Markdown Editor";
51 type = types.submodule {
52 freeformType = settingsFormat.type;
55 type = with types; nullOr str;
57 example = "hedgedoc.org";
59 Domain to use for website.
61 This is useful if you are trying to run hedgedoc behind
66 type = with types; nullOr str;
70 URL path for the website.
72 This is useful if you are hosting hedgedoc on a path like
73 `www.example.com/hedgedoc`
77 type = with types; nullOr str;
78 default = "localhost";
92 type = with types; nullOr path;
94 example = "/run/hedgedoc/hedgedoc.sock";
96 Path to UNIX domain socket to listen on
99 If specified, {option}`host` and {option}`port` will be ignored.
103 protocolUseSSL = mkOption {
108 Use `https://` for all links.
110 This is useful if you are trying to run hedgedoc behind
114 Only applied if {option}`domain` is set.
118 allowOrigin = mkOption {
119 type = with types; listOf str;
120 default = with cfg.settings; [ host ] ++ lib.optionals (domain != null) [ domain ];
121 defaultText = literalExpression ''
122 with config.services.hedgedoc.settings; [ host ] ++ lib.optionals (domain != null) [ domain ]
129 List of domains to whitelist.
136 storage = "/var/lib/${name}/db.sqlite";
138 defaultText = literalExpression ''
141 storage = "/var/lib/hedgedoc/db.sqlite";
144 example = literalExpression ''
146 username = "hedgedoc";
147 database = "hedgedoc";
148 host = "localhost:5432";
150 # host = "/run/postgresql";
151 dialect = "postgresql";
155 Specify the configuration for sequelize.
156 HedgeDoc supports `mysql`, `postgres`, `sqlite` and `mssql`.
157 See <https://sequelize.readthedocs.io/en/v3/>
158 for more information.
161 The relevant parts will be overriden if you set {option}`dbURL`.
169 Enable to use SSL server.
172 This will also enable {option}`protocolUseSSL`.
174 It will also require you to set the following:
176 - {option}`sslKeyPath`
177 - {option}`sslCertPath`
178 - {option}`sslCAPath`
179 - {option}`dhParamPath`
183 uploadsPath = mkOption {
185 default = "/var/lib/${name}/uploads";
186 defaultText = "/var/lib/hedgedoc/uploads";
188 Directory for storing uploaded images.
192 # Declared because we change the default to false.
193 allowGravatar = mkOption {
198 Whether to enable [Libravatar](https://wiki.libravatar.org/) as
199 profile picture source on your instance.
201 Despite the naming of the setting, Hedgedoc replaced Gravatar
202 with Libravatar in [CodiMD 1.4.0](https://hedgedoc.org/releases/1.4.0/)
209 HedgeDoc configuration, see
210 <https://docs.hedgedoc.org/configuration/>
215 environmentFile = mkOption {
216 type = with types; nullOr path;
218 example = "/var/lib/hedgedoc/hedgedoc.env";
220 Environment file as defined in {manpage}`systemd.exec(5)`.
222 Secrets may be passed to the service without adding them to the world-readable
223 Nix store, by specifying placeholder variables as the option value in Nix and
224 setting these variables accordingly in the environment file.
227 # snippet of HedgeDoc-related config
228 services.hedgedoc.settings.dbURL = "postgres://hedgedoc:\''${DB_PASSWORD}@db-host:5432/hedgedocdb";
229 services.hedgedoc.settings.minio.secretKey = "$MINIO_SECRET_KEY";
233 # content of the environment file
234 DB_PASSWORD=verysecretdbpassword
235 MINIO_SECRET_KEY=verysecretminiokey
238 Note that this file needs to be available on the host on which
239 `HedgeDoc` is running.
244 config = lib.mkIf cfg.enable {
245 users.groups.${name} = { };
246 users.users.${name} = {
247 description = "HedgeDoc service user";
252 services.hedgedoc.settings = {
253 defaultNotePath = lib.mkDefault "${cfg.package}/share/hedgedoc/public/default.md";
254 docsPath = lib.mkDefault "${cfg.package}/share/hedgedoc/public/docs";
255 viewPath = lib.mkDefault "${cfg.package}/share/hedgedoc/public/views";
258 systemd.services.hedgedoc = {
259 description = "HedgeDoc Service";
260 documentation = [ "https://docs.hedgedoc.org/" ];
261 wantedBy = [ "multi-user.target" ];
262 after = [ "networking.target" ];
265 configFile = settingsFormat.generate "hedgedoc-config.json" {
266 production = cfg.settings;
270 ${pkgs.envsubst}/bin/envsubst \
271 -o /run/${name}/config.json \
273 ${pkgs.coreutils}/bin/mkdir -p ${cfg.settings.uploadsPath}
280 ExecStart = lib.getExe cfg.package;
281 RuntimeDirectory = [ name ];
282 StateDirectory = [ name ];
283 WorkingDirectory = "/run/${name}";
285 "-${cfg.settings.uploadsPath}"
286 ] ++ lib.optionals (cfg.settings.db ? "storage") [ "-${cfg.settings.db.storage}" ];
287 EnvironmentFile = lib.mkIf (cfg.environmentFile != null) [ cfg.environmentFile ];
289 "CMD_CONFIG_FILE=/run/${name}/config.json"
290 "NODE_ENV=production"
294 AmbientCapabilities = "";
295 CapabilityBoundingSet = "";
296 LockPersonality = true;
297 NoNewPrivileges = true;
298 PrivateDevices = true;
299 PrivateMounts = true;
304 ProtectControlGroups = true;
306 ProtectHostname = true;
307 ProtectKernelLogs = true;
308 ProtectKernelModules = true;
309 ProtectKernelTunables = true;
310 ProtectProc = "invisible";
311 ProtectSystem = "strict";
313 RestrictAddressFamilies = [
316 # Required for connecting to database sockets,
317 # and listening to unix socket at `cfg.settings.path`
320 RestrictNamespaces = true;
321 RestrictRealtime = true;
322 RestrictSUIDSGID = true;
323 SocketBindAllow = lib.mkIf (cfg.settings.path == null) cfg.settings.port;
324 SocketBindDeny = "any";
325 SystemCallArchitectures = "native";
328 "~@privileged @obsolete"