nixos/mattermost: update service for 6.0+

This commit is contained in:
Morgan Jones 2021-12-31 01:54:41 -07:00 committed by Raphael Megzari
parent c37cb3b243
commit 38ee2de29d

View File

@ -78,6 +78,8 @@ let
TeamSettings.SiteName = cfg.siteName;
SqlSettings.DriverName = "postgres";
SqlSettings.DataSource = database;
PluginSettings.Directory = "${cfg.statePath}/plugins/server";
PluginSettings.ClientDirectory = "${cfg.statePath}/plugins/client";
}
cfg.extraConfig;
@ -88,9 +90,6 @@ let
else {
PluginSettings = {
Enable = true;
EnableUploads = false;
Directory = "${cfg.statePath}/plugins/server";
ClientDirectory = "${cfg.statePath}/plugins/client";
};
}
);
@ -274,7 +273,7 @@ in
# The systemd service will fail to execute the preStart hook
# if the WorkingDirectory does not exist
system.activationScripts.mattermost = ''
mkdir -p ${cfg.statePath}
mkdir -p "${cfg.statePath}"
'';
systemd.services.mattermost = {
@ -283,45 +282,41 @@ in
after = [ "network.target" "postgresql.service" ];
preStart = ''
mkdir -p ${cfg.statePath}/{data,config,logs}
ln -sf ${cfg.package}/{bin,fonts,i18n,templates,client} ${cfg.statePath}
mkdir -p "${cfg.statePath}"/{data,config,logs,plugins}
mkdir -p "${cfg.statePath}/plugins"/{client,server}
ln -sf ${cfg.package}/{bin,fonts,i18n,templates,client} "${cfg.statePath}"
'' + lib.optionalString (mattermostPlugins != null) ''
mkdir -p ${cfg.statePath}/plugins/{client,server}
rm -rf "${cfg.statePath}/data/plugins"
ln -sf ${mattermostPlugins}/data/plugins ${cfg.statePath}/data
ln -sf ${mattermostPlugins}/data/plugins "${cfg.statePath}/data"
'' + lib.optionalString (!cfg.mutableConfig) ''
rm -f ${cfg.statePath}/config/config.json
${pkgs.jq}/bin/jq -s '.[0] * .[1]' ${cfg.package}/config/config.json ${mattermostConfJSON} > ${cfg.statePath}/config/config.json
${cfg.package}/bin/mattermost config migrate ${cfg.statePath}/config/config.json ${database}
rm -f "${cfg.statePath}/config/config.json"
${pkgs.jq}/bin/jq -s '.[0] * .[1]' ${cfg.package}/config/config.json ${mattermostConfJSON} > "${cfg.statePath}/config/config.json"
'' + lib.optionalString cfg.mutableConfig ''
if ! test -e "${cfg.statePath}/config/.initial-created"; then
rm -f ${cfg.statePath}/config/config.json
${pkgs.jq}/bin/jq -s '.[0] * .[1]' ${cfg.package}/config/config.json ${mattermostConfJSON} > ${cfg.statePath}/config/config.json
touch ${cfg.statePath}/config/.initial-created
${pkgs.jq}/bin/jq -s '.[0] * .[1]' ${cfg.package}/config/config.json ${mattermostConfJSON} > "${cfg.statePath}/config/config.json"
touch "${cfg.statePath}/config/.initial-created"
fi
'' + lib.optionalString (cfg.mutableConfig && cfg.preferNixConfig) ''
new_config="$(${pkgs.jq}/bin/jq -s '.[0] * .[1]' ${cfg.statePath}/config/config.json ${mattermostConfJSON})"
new_config="$(${pkgs.jq}/bin/jq -s '.[0] * .[1]' "${cfg.statePath}/config/config.json" ${mattermostConfJSON})"
rm -f ${cfg.statePath}/config/config.json
echo "$new_config" > ${cfg.statePath}/config/config.json
rm -f "${cfg.statePath}/config/config.json"
echo "$new_config" > "${cfg.statePath}/config/config.json"
'' + lib.optionalString cfg.localDatabaseCreate (createDb {}) + ''
# Don't change permissions recursively on the data, current, and symlinked directories (see ln -sf command above).
# This dramatically increases startup times for installations with a lot of files.
# This dramatically decreases startup times for installations with a lot of files.
find . -maxdepth 1 -not -name data -not -name client -not -name templates -not -name i18n -not -name fonts -not -name bin -not -name . \
-exec chown ${cfg.user}:${cfg.group} -R {} \; -exec chmod u+rw,g+r,o-rwx -R {} \;
-exec chown "${cfg.user}:${cfg.group}" -R {} \; -exec chmod u+rw,g+r,o-rwx -R {} \;
chown ${cfg.user}:${cfg.group} ${cfg.statePath}/data .
chmod u+rw,g+r,o-rwx ${cfg.statePath}/data .
chown "${cfg.user}:${cfg.group}" "${cfg.statePath}/data" .
chmod u+rw,g+r,o-rwx "${cfg.statePath}/data" .
'';
serviceConfig = {
PermissionsStartOnly = true;
User = cfg.user;
Group = cfg.group;
ExecStart = "${cfg.package}/bin/mattermost " + (
escapeShellArgs
(lib.optionals (!cfg.mutableConfig) ["-c" database])
);
ExecStart = "${cfg.package}/bin/mattermost";
WorkingDirectory = "${cfg.statePath}";
Restart = "always";
RestartSec = "10";