Skip to content

Commit

Permalink
nixos/codimd: rename to hedgedoc
Browse files Browse the repository at this point in the history
CodiMD was renamed to HedgeDoc. The user, group and state directory,
will be named hedgedoc instead of codimd, starting with stateVersion
"21.03".
  • Loading branch information
WilliButz committed Dec 22, 2020
1 parent e19995e commit 1c55621
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 112 deletions.
2 changes: 1 addition & 1 deletion nixos/modules/module-list.nix
Expand Up @@ -856,7 +856,6 @@
./services/web-apps/atlassian/confluence.nix
./services/web-apps/atlassian/crowd.nix
./services/web-apps/atlassian/jira.nix
./services/web-apps/codimd.nix
./services/web-apps/convos.nix
./services/web-apps/cryptpad.nix
./services/web-apps/documize.nix
Expand All @@ -865,6 +864,7 @@
./services/web-apps/gerrit.nix
./services/web-apps/gotify-server.nix
./services/web-apps/grocy.nix
./services/web-apps/hedgedoc.nix
./services/web-apps/icingaweb2/icingaweb2.nix
./services/web-apps/icingaweb2/module-monitoring.nix
./services/web-apps/ihatemoney
Expand Down
Expand Up @@ -3,33 +3,41 @@
with lib;

let
cfg = config.services.codimd;
cfg = config.services.hedgedoc;

name = if versionAtLeast config.system.stateVersion "21.03"
then "hedgedoc"
else "codimd";

prettyJSON = conf:
pkgs.runCommandLocal "codimd-config.json" {
pkgs.runCommandLocal "hedgedoc-config.json" {
nativeBuildInputs = [ pkgs.jq ];
} ''
echo '${builtins.toJSON conf}' | jq \
'{production:del(.[]|nulls)|del(.[][]?|nulls)}' > $out
'';
in
{
options.services.codimd = {
enable = mkEnableOption "the CodiMD Markdown Editor";
imports = [
(mkRenamedOptionModule [ "services" "codimd" ] [ "services" "hedgedoc" ])
];

options.services.hedgedoc = {
enable = mkEnableOption "the HedgeDoc Markdown Editor";

groups = mkOption {
type = types.listOf types.str;
default = [];
description = ''
Groups to which the codimd user should be added.
Groups to which the user ${name} should be added.
'';
};

workDir = mkOption {
type = types.path;
default = "/var/lib/codimd";
default = "/var/lib/${name}";
description = ''
Working directory for the CodiMD service.
Working directory for the HedgeDoc service.
'';
};

Expand All @@ -38,17 +46,17 @@ in
domain = mkOption {
type = types.nullOr types.str;
default = null;
example = "codimd.org";
example = "hedgedoc.org";
description = ''
Domain name for the CodiMD instance.
Domain name for the HedgeDoc instance.
'';
};
urlPath = mkOption {
type = types.nullOr types.str;
default = null;
example = "/url/path/to/codimd";
example = "/url/path/to/hedgedoc";
description = ''
Path under which CodiMD is accessible.
Path under which HedgeDoc is accessible.
'';
};
host = mkOption {
Expand All @@ -69,15 +77,15 @@ in
path = mkOption {
type = types.nullOr types.str;
default = null;
example = "/run/codimd.sock";
example = "/run/hedgedoc.sock";
description = ''
Specify where a UNIX domain socket should be placed.
'';
};
allowOrigin = mkOption {
type = types.listOf types.str;
default = [];
example = [ "localhost" "codimd.org" ];
example = [ "localhost" "hedgedoc.org" ];
description = ''
List of domains to whitelist.
'';
Expand Down Expand Up @@ -201,7 +209,7 @@ in
'';
description = ''
Specify which database to use.
CodiMD supports mysql, postgres, sqlite and mssql.
HedgeDoc supports mysql, postgres, sqlite and mssql.
See <link xlink:href="https://sequelize.readthedocs.io/en/v3/">
https://sequelize.readthedocs.io/en/v3/</link> for more information.
Note: This option overrides <option>db</option>.
Expand All @@ -213,12 +221,12 @@ in
example = literalExample ''
{
dialect = "sqlite";
storage = "/var/lib/codimd/db.codimd.sqlite";
storage = "/var/lib/${name}/db.${name}.sqlite";
}
'';
description = ''
Specify the configuration for sequelize.
CodiMD supports mysql, postgres, sqlite and mssql.
HedgeDoc supports mysql, postgres, sqlite and mssql.
See <link xlink:href="https://sequelize.readthedocs.io/en/v3/">
https://sequelize.readthedocs.io/en/v3/</link> for more information.
Note: This option overrides <option>db</option>.
Expand All @@ -227,31 +235,31 @@ in
sslKeyPath= mkOption {
type = types.nullOr types.str;
default = null;
example = "/var/lib/codimd/codimd.key";
example = "/var/lib/hedgedoc/hedgedoc.key";
description = ''
Path to the SSL key. Needed when <option>useSSL</option> is enabled.
'';
};
sslCertPath = mkOption {
type = types.nullOr types.str;
default = null;
example = "/var/lib/codimd/codimd.crt";
example = "/var/lib/hedgedoc/hedgedoc.crt";
description = ''
Path to the SSL cert. Needed when <option>useSSL</option> is enabled.
'';
};
sslCAPath = mkOption {
type = types.listOf types.str;
default = [];
example = [ "/var/lib/codimd/ca.crt" ];
example = [ "/var/lib/hedgedoc/ca.crt" ];
description = ''
SSL ca chain. Needed when <option>useSSL</option> is enabled.
'';
};
dhParamPath = mkOption {
type = types.nullOr types.str;
default = null;
example = "/var/lib/codimd/dhparam.pem";
example = "/var/lib/hedgedoc/dhparam.pem";
description = ''
Path to the SSL dh params. Needed when <option>useSSL</option> is enabled.
'';
Expand All @@ -260,42 +268,42 @@ in
type = types.str;
default = "/tmp";
description = ''
Path to the temp directory CodiMD should use.
Path to the temp directory HedgeDoc should use.
Note that <option>serviceConfig.PrivateTmp</option> is enabled for
the CodiMD systemd service by default.
(Non-canonical paths are relative to CodiMD's base directory)
the HedgeDoc systemd service by default.
(Non-canonical paths are relative to HedgeDoc's base directory)
'';
};
defaultNotePath = mkOption {
type = types.nullOr types.str;
default = "./public/default.md";
description = ''
Path to the default Note file.
(Non-canonical paths are relative to CodiMD's base directory)
(Non-canonical paths are relative to HedgeDoc's base directory)
'';
};
docsPath = mkOption {
type = types.nullOr types.str;
default = "./public/docs";
description = ''
Path to the docs directory.
(Non-canonical paths are relative to CodiMD's base directory)
(Non-canonical paths are relative to HedgeDoc's base directory)
'';
};
indexPath = mkOption {
type = types.nullOr types.str;
default = "./public/views/index.ejs";
description = ''
Path to the index template file.
(Non-canonical paths are relative to CodiMD's base directory)
(Non-canonical paths are relative to HedgeDoc's base directory)
'';
};
hackmdPath = mkOption {
type = types.nullOr types.str;
default = "./public/views/hackmd.ejs";
description = ''
Path to the hackmd template file.
(Non-canonical paths are relative to CodiMD's base directory)
(Non-canonical paths are relative to HedgeDoc's base directory)
'';
};
errorPath = mkOption {
Expand All @@ -304,7 +312,7 @@ in
defaultText = "./public/views/error.ejs";
description = ''
Path to the error template file.
(Non-canonical paths are relative to CodiMD's base directory)
(Non-canonical paths are relative to HedgeDoc's base directory)
'';
};
prettyPath = mkOption {
Expand All @@ -313,7 +321,7 @@ in
defaultText = "./public/views/pretty.ejs";
description = ''
Path to the pretty template file.
(Non-canonical paths are relative to CodiMD's base directory)
(Non-canonical paths are relative to HedgeDoc's base directory)
'';
};
slidePath = mkOption {
Expand All @@ -322,13 +330,13 @@ in
defaultText = "./public/views/slide.hbs";
description = ''
Path to the slide template file.
(Non-canonical paths are relative to CodiMD's base directory)
(Non-canonical paths are relative to HedgeDoc's base directory)
'';
};
uploadsPath = mkOption {
type = types.str;
default = "${cfg.workDir}/uploads";
defaultText = "/var/lib/codimd/uploads";
defaultText = "/var/lib/${name}/uploads";
description = ''
Path under which uploaded files are saved.
'';
Expand Down Expand Up @@ -766,15 +774,15 @@ in
type = types.str;
default = "";
description = ''
LDAP field which is used as the username on CodiMD.
LDAP field which is used as the username on HedgeDoc.
By default <option>useridField</option> is used.
'';
};
useridField = mkOption {
type = types.str;
example = "uid";
description = ''
LDAP field which is a unique identifier for users on CodiMD.
LDAP field which is a unique identifier for users on HedgeDoc.
'';
};
tlsca = mkOption {
Expand Down Expand Up @@ -840,7 +848,7 @@ in
requiredGroups = mkOption {
type = types.listOf types.str;
default = [];
example = [ "Hackmd-users" "Codimd-users" ];
example = [ "Hedgedoc-Users" ];
description = ''
Required group names.
'';
Expand Down Expand Up @@ -883,7 +891,7 @@ in
environmentFile = mkOption {
type = with types; nullOr path;
default = null;
example = "/var/lib/codimd/codimd.env";
example = "/var/lib/hedgedoc/hedgedoc.env";
description = ''
Environment file as defined in <citerefentry>
<refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum>
Expand All @@ -894,9 +902,9 @@ in
setting these variables accordingly in the environment file.
<programlisting>
# snippet of CodiMD-related config
services.codimd.configuration.dbURL = "postgres://codimd:\''${DB_PASSWORD}@db-host:5432/codimddb";
services.codimd.configuration.minio.secretKey = "$MINIO_SECRET_KEY";
# snippet of HedgeDoc-related config
services.hedgedoc.configuration.dbURL = "postgres://hedgedoc:\''${DB_PASSWORD}@db-host:5432/hedgedocdb";
services.hedgedoc.configuration.minio.secretKey = "$MINIO_SECRET_KEY";
</programlisting>
<programlisting>
Expand All @@ -906,15 +914,15 @@ in
</programlisting>
Note that this file needs to be available on the host on which
<literal>CodiMD</literal> is running.
<literal>HedgeDoc</literal> is running.
'';
};

package = mkOption {
type = types.package;
default = pkgs.codimd;
default = pkgs.hedgedoc;
description = ''
Package that provides CodiMD.
Package that provides HedgeDoc.
'';
};
};
Expand All @@ -924,20 +932,20 @@ in
{ assertion = cfg.configuration.db == {} -> (
cfg.configuration.dbURL != "" && cfg.configuration.dbURL != null
);
message = "Database configuration for CodiMD missing."; }
message = "Database configuration for HedgeDoc missing."; }
];
users.groups.codimd = {};
users.users.codimd = {
description = "CodiMD service user";
group = "codimd";
users.groups.${name} = {};
users.users.${name} = {
description = "HedgeDoc service user";
group = name;
extraGroups = cfg.groups;
home = cfg.workDir;
createHome = true;
isSystemUser = true;
};

systemd.services.codimd = {
description = "CodiMD Service";
systemd.services.hedgedoc = {
description = "HedgeDoc Service";
wantedBy = [ "multi-user.target" ];
after = [ "networking.target" ];
preStart = ''
Expand All @@ -947,14 +955,14 @@ in
'';
serviceConfig = {
WorkingDirectory = cfg.workDir;
ExecStart = "${cfg.package}/bin/codimd";
ExecStart = "${cfg.package}/bin/hedgedoc";
EnvironmentFile = mkIf (cfg.environmentFile != null) [ cfg.environmentFile ];
Environment = [
"CMD_CONFIG_FILE=${cfg.workDir}/config.json"
"NODE_ENV=production"
];
Restart = "always";
User = "codimd";
User = name;
PrivateTmp = true;
};
};
Expand Down
2 changes: 1 addition & 1 deletion nixos/tests/all-tests.nix
Expand Up @@ -63,7 +63,6 @@ in
clickhouse = handleTest ./clickhouse.nix {};
cloud-init = handleTest ./cloud-init.nix {};
cockroachdb = handleTestOn ["x86_64-linux"] ./cockroachdb.nix {};
codimd = handleTest ./codimd.nix {};
consul = handleTest ./consul.nix {};
containers-bridge = handleTest ./containers-bridge.nix {};
containers-custom-pkgs.nix = handleTest ./containers-custom-pkgs.nix {};
Expand Down Expand Up @@ -147,6 +146,7 @@ in
handbrake = handleTestOn ["x86_64-linux"] ./handbrake.nix {};
haproxy = handleTest ./haproxy.nix {};
hardened = handleTest ./hardened.nix {};
hedgedoc = handleTest ./hedgedoc.nix {};
installed-tests = pkgs.recurseIntoAttrs (handleTest ./installed-tests {});
oci-containers = handleTestOn ["x86_64-linux"] ./oci-containers.nix {};
# 9pnet_virtio used to mount /nix partition doesn't support
Expand Down

0 comments on commit 1c55621

Please sign in to comment.