2014-10-07 08:53:01 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
2023-11-27 00:19:27 +00:00
|
|
|
inherit (lib) mkBefore mkDefault mkEnableOption mkPackageOption
|
|
|
|
mkIf mkOption mkRemovedOptionModule types;
|
2021-10-03 16:06:03 +00:00
|
|
|
inherit (lib) concatStringsSep literalExpression mapAttrsToList;
|
2020-08-25 15:27:30 +00:00
|
|
|
inherit (lib) optional optionalAttrs optionalString;
|
2019-06-22 20:16:24 +00:00
|
|
|
|
2014-10-07 08:53:01 +00:00
|
|
|
cfg = config.services.redmine;
|
2020-08-25 15:27:30 +00:00
|
|
|
format = pkgs.formats.yaml {};
|
2018-10-11 01:04:08 +00:00
|
|
|
bundle = "${cfg.package}/share/redmine/bin/bundle";
|
2018-08-19 20:29:44 +00:00
|
|
|
|
2024-03-24 01:40:39 +00:00
|
|
|
databaseSettings = {
|
|
|
|
production = {
|
|
|
|
adapter = cfg.database.type;
|
2024-03-23 15:47:24 +00:00
|
|
|
database = if cfg.database.type == "sqlite3" then "${cfg.stateDir}/database.sqlite3" else cfg.database.name;
|
|
|
|
} // optionalAttrs (cfg.database.type != "sqlite3") {
|
2024-03-24 01:40:39 +00:00
|
|
|
host = if (cfg.database.type == "postgresql" && cfg.database.socket != null) then cfg.database.socket else cfg.database.host;
|
|
|
|
port = cfg.database.port;
|
|
|
|
username = cfg.database.user;
|
2024-03-23 15:47:24 +00:00
|
|
|
} // optionalAttrs (cfg.database.type != "sqlite3" && cfg.database.passwordFile != null) {
|
2024-03-24 01:40:39 +00:00
|
|
|
password = "#dbpass#";
|
|
|
|
} // optionalAttrs (cfg.database.type == "mysql2" && cfg.database.socket != null) {
|
|
|
|
socket = cfg.database.socket;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
databaseYml = format.generate "database.yml" databaseSettings;
|
2014-10-07 08:53:01 +00:00
|
|
|
|
2020-08-25 15:27:30 +00:00
|
|
|
configurationYml = format.generate "configuration.yml" cfg.settings;
|
2020-08-25 15:33:25 +00:00
|
|
|
additionalEnvironment = pkgs.writeText "additional_environment.rb" cfg.extraEnv;
|
2019-02-01 14:17:05 +00:00
|
|
|
|
2018-10-11 01:04:08 +00:00
|
|
|
unpackTheme = unpack "theme";
|
|
|
|
unpackPlugin = unpack "plugin";
|
|
|
|
unpack = id: (name: source:
|
|
|
|
pkgs.stdenv.mkDerivation {
|
|
|
|
name = "redmine-${id}-${name}";
|
2021-03-05 18:11:00 +00:00
|
|
|
nativeBuildInputs = [ pkgs.unzip ];
|
2018-10-11 01:04:08 +00:00
|
|
|
buildCommand = ''
|
|
|
|
mkdir -p $out
|
|
|
|
cd $out
|
|
|
|
unpackFile ${source}
|
|
|
|
'';
|
|
|
|
});
|
|
|
|
|
2019-06-22 20:03:42 +00:00
|
|
|
mysqlLocal = cfg.database.createLocally && cfg.database.type == "mysql2";
|
|
|
|
pgsqlLocal = cfg.database.createLocally && cfg.database.type == "postgresql";
|
|
|
|
|
2018-08-19 20:29:44 +00:00
|
|
|
in
|
|
|
|
{
|
2020-08-25 15:27:30 +00:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "services" "redmine" "extraConfig" ] "Use services.redmine.settings instead.")
|
2020-08-25 15:55:06 +00:00
|
|
|
(mkRemovedOptionModule [ "services" "redmine" "database" "password" ] "Use services.redmine.database.passwordFile instead.")
|
2020-08-25 15:27:30 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
# interface
|
2014-10-07 08:53:01 +00:00
|
|
|
options = {
|
|
|
|
services.redmine = {
|
2024-04-13 12:54:15 +00:00
|
|
|
enable = mkEnableOption "Redmine, a project management web application";
|
2014-10-07 08:53:01 +00:00
|
|
|
|
2023-11-27 00:19:27 +00:00
|
|
|
package = mkPackageOption pkgs "redmine" {
|
2023-11-26 22:34:32 +00:00
|
|
|
example = "redmine.override { ruby = pkgs.ruby_3_2; }";
|
2018-10-11 01:04:08 +00:00
|
|
|
};
|
|
|
|
|
2018-08-19 20:29:44 +00:00
|
|
|
user = mkOption {
|
2014-10-07 08:53:01 +00:00
|
|
|
type = types.str;
|
2018-08-19 20:29:44 +00:00
|
|
|
default = "redmine";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "User under which Redmine is ran.";
|
2014-10-07 08:53:01 +00:00
|
|
|
};
|
|
|
|
|
2018-08-19 20:29:44 +00:00
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "redmine";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Group under which Redmine is ran.";
|
2014-10-07 08:53:01 +00:00
|
|
|
};
|
|
|
|
|
2018-10-11 01:04:08 +00:00
|
|
|
port = mkOption {
|
2021-06-18 15:29:05 +00:00
|
|
|
type = types.port;
|
2018-10-11 01:04:08 +00:00
|
|
|
default = 3000;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Port on which Redmine is ran.";
|
2018-10-11 01:04:08 +00:00
|
|
|
};
|
|
|
|
|
2018-08-19 20:29:44 +00:00
|
|
|
stateDir = mkOption {
|
2014-10-07 08:53:01 +00:00
|
|
|
type = types.str;
|
2018-08-19 20:29:44 +00:00
|
|
|
default = "/var/lib/redmine";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "The state directory, logs and plugins are stored here.";
|
2014-10-07 08:53:01 +00:00
|
|
|
};
|
|
|
|
|
2020-08-25 15:27:30 +00:00
|
|
|
settings = mkOption {
|
|
|
|
type = format.type;
|
|
|
|
default = {};
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2020-08-25 15:27:30 +00:00
|
|
|
Redmine configuration ({file}`configuration.yml`). Refer to
|
|
|
|
<https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration>
|
2019-06-22 20:16:24 +00:00
|
|
|
for details.
|
2018-08-19 20:29:44 +00:00
|
|
|
'';
|
2021-10-03 16:06:03 +00:00
|
|
|
example = literalExpression ''
|
2020-08-25 15:27:30 +00:00
|
|
|
{
|
|
|
|
email_delivery = {
|
|
|
|
delivery_method = "smtp";
|
|
|
|
smtp_settings = {
|
|
|
|
address = "mail.example.com";
|
|
|
|
port = 25;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
2018-10-11 01:04:08 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-02-01 14:17:05 +00:00
|
|
|
extraEnv = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2019-02-01 14:17:05 +00:00
|
|
|
Extra configuration in additional_environment.rb.
|
|
|
|
|
2019-06-22 20:16:24 +00:00
|
|
|
See <https://svn.redmine.org/redmine/trunk/config/additional_environment.rb.example>
|
|
|
|
for details.
|
2019-02-01 14:17:05 +00:00
|
|
|
'';
|
2021-10-03 16:06:03 +00:00
|
|
|
example = ''
|
2019-02-01 14:17:05 +00:00
|
|
|
config.logger.level = Logger::DEBUG
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-10-11 01:04:08 +00:00
|
|
|
themes = mkOption {
|
|
|
|
type = types.attrsOf types.path;
|
|
|
|
default = {};
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Set of themes.";
|
2021-10-03 16:06:03 +00:00
|
|
|
example = literalExpression ''
|
2018-10-11 01:04:08 +00:00
|
|
|
{
|
|
|
|
dkuk-redmine_alex_skin = builtins.fetchurl {
|
2020-04-18 11:43:47 +00:00
|
|
|
url = "https://bitbucket.org/dkuk/redmine_alex_skin/get/1842ef675ef3.zip";
|
2018-10-11 01:04:08 +00:00
|
|
|
sha256 = "0hrin9lzyi50k4w2bd2b30vrf1i4fi1c0gyas5801wn8i7kpm9yl";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
plugins = mkOption {
|
|
|
|
type = types.attrsOf types.path;
|
|
|
|
default = {};
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Set of plugins.";
|
2021-10-03 16:06:03 +00:00
|
|
|
example = literalExpression ''
|
2018-10-11 01:04:08 +00:00
|
|
|
{
|
|
|
|
redmine_env_auth = builtins.fetchurl {
|
2020-04-18 11:43:47 +00:00
|
|
|
url = "https://github.com/Intera/redmine_env_auth/archive/0.6.zip";
|
2018-10-11 01:04:08 +00:00
|
|
|
sha256 = "0yyr1yjd8gvvh832wdc8m3xfnhhxzk2pk3gm2psg5w9jdvd6skak";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
2014-10-07 08:53:01 +00:00
|
|
|
};
|
|
|
|
|
2018-08-19 20:29:44 +00:00
|
|
|
database = {
|
|
|
|
type = mkOption {
|
2024-03-23 15:47:24 +00:00
|
|
|
type = types.enum [ "mysql2" "postgresql" "sqlite3" ];
|
2018-08-19 20:29:44 +00:00
|
|
|
example = "postgresql";
|
|
|
|
default = "mysql2";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Database engine to use.";
|
2018-08-19 20:29:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
2019-06-22 20:03:42 +00:00
|
|
|
default = "localhost";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Database host address.";
|
2018-08-19 20:29:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2022-11-09 21:30:00 +00:00
|
|
|
type = types.port;
|
2019-06-22 20:03:42 +00:00
|
|
|
default = if cfg.database.type == "postgresql" then 5432 else 3306;
|
2021-10-03 16:06:03 +00:00
|
|
|
defaultText = literalExpression "3306";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Database host port.";
|
2018-08-19 20:29:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "redmine";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Database name.";
|
2018-08-19 20:29:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "redmine";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Database user.";
|
2018-08-19 20:29:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
passwordFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
|
|
|
example = "/run/keys/redmine-dbpassword";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2018-08-19 20:29:44 +00:00
|
|
|
A file containing the password corresponding to
|
|
|
|
{option}`database.user`.
|
|
|
|
'';
|
|
|
|
};
|
2018-10-11 01:04:08 +00:00
|
|
|
|
|
|
|
socket = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
2019-06-22 20:03:42 +00:00
|
|
|
default =
|
|
|
|
if mysqlLocal then "/run/mysqld/mysqld.sock"
|
|
|
|
else if pgsqlLocal then "/run/postgresql"
|
|
|
|
else null;
|
2021-10-03 16:06:03 +00:00
|
|
|
defaultText = literalExpression "/run/mysqld/mysqld.sock";
|
2018-10-11 01:04:08 +00:00
|
|
|
example = "/run/mysqld/mysqld.sock";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Path to the unix socket file to use for authentication.";
|
2018-10-11 01:04:08 +00:00
|
|
|
};
|
2019-06-22 20:03:42 +00:00
|
|
|
|
|
|
|
createLocally = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Create the database and database user locally.";
|
2019-06-22 20:03:42 +00:00
|
|
|
};
|
2014-10-07 08:53:01 +00:00
|
|
|
};
|
2022-05-07 05:48:08 +00:00
|
|
|
|
|
|
|
components = {
|
|
|
|
subversion = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Subversion integration.";
|
2022-05-07 05:48:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mercurial = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Mercurial integration.";
|
2022-05-07 05:48:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
git = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "git integration.";
|
2022-05-07 05:48:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
cvs = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "cvs integration.";
|
2022-05-07 05:48:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
breezy = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "bazaar integration.";
|
2022-05-07 05:48:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
imagemagick = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Allows exporting Gant diagrams as PNG.";
|
2022-05-07 05:48:08 +00:00
|
|
|
};
|
2022-05-10 22:09:09 +00:00
|
|
|
|
|
|
|
ghostscript = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Allows exporting Gant diagrams as PDF.";
|
2022-05-10 22:09:09 +00:00
|
|
|
};
|
2022-05-14 22:02:45 +00:00
|
|
|
|
|
|
|
minimagick_font_path = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "MiniMagick font path";
|
2022-05-14 22:02:45 +00:00
|
|
|
example = "/run/current-system/sw/share/X11/fonts/LiberationSans-Regular.ttf";
|
|
|
|
};
|
2022-05-07 05:48:08 +00:00
|
|
|
};
|
2014-10-07 08:53:01 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-08-25 15:27:30 +00:00
|
|
|
# implementation
|
2014-10-07 08:53:01 +00:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
assertions = [
|
2024-03-23 15:47:24 +00:00
|
|
|
{ assertion = cfg.database.type != "sqlite3" -> cfg.database.passwordFile != null || cfg.database.socket != null;
|
2020-08-25 15:55:06 +00:00
|
|
|
message = "one of services.redmine.database.socket or services.redmine.database.passwordFile must be set";
|
2018-10-11 01:04:08 +00:00
|
|
|
}
|
2023-12-03 13:31:04 +00:00
|
|
|
{ assertion = cfg.database.createLocally -> cfg.database.user == cfg.user;
|
2019-06-22 20:03:42 +00:00
|
|
|
message = "services.redmine.database.user must be set to ${cfg.user} if services.redmine.database.createLocally is set true";
|
|
|
|
}
|
2023-12-03 13:31:04 +00:00
|
|
|
{ assertion = pgsqlLocal -> cfg.database.user == cfg.database.name;
|
|
|
|
message = "services.redmine.database.user and services.redmine.database.name must be the same when using a local postgresql database";
|
|
|
|
}
|
2024-04-01 20:18:43 +00:00
|
|
|
{ assertion = (cfg.database.createLocally && cfg.database.type != "sqlite3") -> cfg.database.socket != null;
|
|
|
|
message = "services.redmine.database.socket must be set if services.redmine.database.createLocally is set to true and no sqlite database is used";
|
2019-06-22 20:03:42 +00:00
|
|
|
}
|
|
|
|
{ assertion = cfg.database.createLocally -> cfg.database.host == "localhost";
|
|
|
|
message = "services.redmine.database.host must be set to localhost if services.redmine.database.createLocally is set to true";
|
2014-10-07 08:53:01 +00:00
|
|
|
}
|
2022-05-14 22:02:45 +00:00
|
|
|
{ assertion = cfg.components.imagemagick -> cfg.components.minimagick_font_path != "";
|
|
|
|
message = "services.redmine.components.minimagick_font_path must be configured with a path to a font file if services.redmine.components.imagemagick is set to true.";
|
|
|
|
}
|
2014-10-07 08:53:01 +00:00
|
|
|
];
|
|
|
|
|
2020-08-25 15:27:30 +00:00
|
|
|
services.redmine.settings = {
|
|
|
|
production = {
|
2023-03-19 20:44:31 +00:00
|
|
|
scm_subversion_command = optionalString cfg.components.subversion "${pkgs.subversion}/bin/svn";
|
|
|
|
scm_mercurial_command = optionalString cfg.components.mercurial "${pkgs.mercurial}/bin/hg";
|
|
|
|
scm_git_command = optionalString cfg.components.git "${pkgs.git}/bin/git";
|
|
|
|
scm_cvs_command = optionalString cfg.components.cvs "${pkgs.cvs}/bin/cvs";
|
|
|
|
scm_bazaar_command = optionalString cfg.components.breezy "${pkgs.breezy}/bin/bzr";
|
|
|
|
imagemagick_convert_command = optionalString cfg.components.imagemagick "${pkgs.imagemagick}/bin/convert";
|
|
|
|
gs_command = optionalString cfg.components.ghostscript "${pkgs.ghostscript}/bin/gs";
|
2022-05-14 22:02:45 +00:00
|
|
|
minimagick_font_path = "${cfg.components.minimagick_font_path}";
|
2020-08-25 15:27:30 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-08-25 15:33:25 +00:00
|
|
|
services.redmine.extraEnv = mkBefore ''
|
|
|
|
config.logger = Logger.new("${cfg.stateDir}/log/production.log", 14, 1048576)
|
|
|
|
config.logger.level = Logger::INFO
|
|
|
|
'';
|
|
|
|
|
2019-06-22 20:03:42 +00:00
|
|
|
services.mysql = mkIf mysqlLocal {
|
|
|
|
enable = true;
|
|
|
|
package = mkDefault pkgs.mariadb;
|
|
|
|
ensureDatabases = [ cfg.database.name ];
|
|
|
|
ensureUsers = [
|
|
|
|
{ name = cfg.database.user;
|
|
|
|
ensurePermissions = { "${cfg.database.name}.*" = "ALL PRIVILEGES"; };
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
services.postgresql = mkIf pgsqlLocal {
|
|
|
|
enable = true;
|
|
|
|
ensureDatabases = [ cfg.database.name ];
|
|
|
|
ensureUsers = [
|
|
|
|
{ name = cfg.database.user;
|
nixos/postgresql: drop ensurePermissions, fix ensureUsers for postgresql15
Closes #216989
First of all, a bit of context: in PostgreSQL, newly created users don't
have the CREATE privilege on the public schema of a database even with
`ALL PRIVILEGES` granted via `ensurePermissions` which is how most of
the DB users are currently set up "declaratively"[1]. This means e.g. a
freshly deployed Nextcloud service will break early because Nextcloud
itself cannot CREATE any tables in the public schema anymore.
The other issue here is that `ensurePermissions` is a mere hack. It's
effectively a mixture of SQL code (e.g. `DATABASE foo` is relying on how
a value is substituted in a query. You'd have to parse a subset of SQL
to actually know which object are permissions granted to for a user).
After analyzing the existing modules I realized that in every case with
a single exception[2] the UNIX system user is equal to the db user is
equal to the db name and I don't see a compelling reason why people
would change that in 99% of the cases. In fact, some modules would even
break if you'd change that because the declarations of the system user &
the db user are mixed up[3].
So I decided to go with something new which restricts the ways to use
`ensure*` options rather than expanding those[4]. Effectively this means
that
* The DB user _must_ be equal to the DB name.
* Permissions are granted via `ensureDBOwnerhip` for an attribute-set in
`ensureUsers`. That way, the user is actually the owner and can
perform `CREATE`.
* For such a postgres user, a database must be declared in
`ensureDatabases`.
For anything else, a custom state management should be implemented. This
can either be `initialScript`, doing it manual, outside of the module or
by implementing proper state management for postgresql[5], but the
current state of `ensure*` isn't even declarative, but a convergent tool
which is what Nix actually claims to _not_ do.
Regarding existing setups: there are effectively two options:
* Leave everything as-is (assuming that system user == db user == db
name): then the DB user will automatically become the DB owner and
everything else stays the same.
* Drop the `createDatabase = true;` declarations: nothing will change
because a removal of `ensure*` statements is ignored, so it doesn't
matter at all whether this option is kept after the first deploy (and
later on you'd usually restore from backups anyways).
The DB user isn't the owner of the DB then, but for an existing setup
this is irrelevant because CREATE on the public schema isn't revoked
from existing users (only not granted for new users).
[1] not really declarative though because removals of these statements
are simply ignored for instance: https://github.com/NixOS/nixpkgs/issues/206467
[2] `services.invidious`: I removed the `ensure*` part temporarily
because it IMHO falls into the category "manage the state on your
own" (see the commit message). See also
https://github.com/NixOS/nixpkgs/pull/265857
[3] e.g. roundcube had `"DATABASE ${cfg.database.username}" = "ALL PRIVILEGES";`
[4] As opposed to other changes that are considered a potential fix, but
also add more things like collation for DBs or passwords that are
_never_ touched again when changing those.
[5] As suggested in e.g. https://github.com/NixOS/nixpkgs/issues/206467
2023-11-08 11:50:09 +00:00
|
|
|
ensureDBOwnership = true;
|
2019-06-22 20:03:42 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2019-02-23 03:55:21 +00:00
|
|
|
# create symlinks for the basic directory layout the redmine package expects
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.stateDir}' 0750 ${cfg.user} ${cfg.group} - -"
|
|
|
|
"d '${cfg.stateDir}/cache' 0750 ${cfg.user} ${cfg.group} - -"
|
|
|
|
"d '${cfg.stateDir}/config' 0750 ${cfg.user} ${cfg.group} - -"
|
|
|
|
"d '${cfg.stateDir}/files' 0750 ${cfg.user} ${cfg.group} - -"
|
|
|
|
"d '${cfg.stateDir}/log' 0750 ${cfg.user} ${cfg.group} - -"
|
|
|
|
"d '${cfg.stateDir}/plugins' 0750 ${cfg.user} ${cfg.group} - -"
|
|
|
|
"d '${cfg.stateDir}/public' 0750 ${cfg.user} ${cfg.group} - -"
|
|
|
|
"d '${cfg.stateDir}/public/plugin_assets' 0750 ${cfg.user} ${cfg.group} - -"
|
|
|
|
"d '${cfg.stateDir}/public/themes' 0750 ${cfg.user} ${cfg.group} - -"
|
|
|
|
"d '${cfg.stateDir}/tmp' 0750 ${cfg.user} ${cfg.group} - -"
|
|
|
|
|
|
|
|
"d /run/redmine - - - - -"
|
|
|
|
"d /run/redmine/public - - - - -"
|
|
|
|
"L+ /run/redmine/config - - - - ${cfg.stateDir}/config"
|
|
|
|
"L+ /run/redmine/files - - - - ${cfg.stateDir}/files"
|
|
|
|
"L+ /run/redmine/log - - - - ${cfg.stateDir}/log"
|
|
|
|
"L+ /run/redmine/plugins - - - - ${cfg.stateDir}/plugins"
|
|
|
|
"L+ /run/redmine/public/plugin_assets - - - - ${cfg.stateDir}/public/plugin_assets"
|
|
|
|
"L+ /run/redmine/public/themes - - - - ${cfg.stateDir}/public/themes"
|
|
|
|
"L+ /run/redmine/tmp - - - - ${cfg.stateDir}/tmp"
|
|
|
|
];
|
|
|
|
|
2014-10-07 08:53:01 +00:00
|
|
|
systemd.services.redmine = {
|
2019-06-22 20:03:42 +00:00
|
|
|
after = [ "network.target" ] ++ optional mysqlLocal "mysql.service" ++ optional pgsqlLocal "postgresql.service";
|
2014-10-07 08:53:01 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
environment.RAILS_ENV = "production";
|
|
|
|
environment.RAILS_CACHE = "${cfg.stateDir}/cache";
|
|
|
|
environment.REDMINE_LANG = "en";
|
2018-08-19 20:29:44 +00:00
|
|
|
environment.SCHEMA = "${cfg.stateDir}/cache/schema.db";
|
2014-10-07 08:53:01 +00:00
|
|
|
path = with pkgs; [
|
2022-05-07 05:48:08 +00:00
|
|
|
]
|
|
|
|
++ optional cfg.components.subversion subversion
|
|
|
|
++ optional cfg.components.mercurial mercurial
|
|
|
|
++ optional cfg.components.git git
|
|
|
|
++ optional cfg.components.cvs cvs
|
|
|
|
++ optional cfg.components.breezy breezy
|
2022-05-10 22:09:09 +00:00
|
|
|
++ optional cfg.components.imagemagick imagemagick
|
|
|
|
++ optional cfg.components.ghostscript ghostscript;
|
2022-05-07 05:48:08 +00:00
|
|
|
|
2014-10-07 08:53:01 +00:00
|
|
|
preStart = ''
|
2019-02-23 03:55:21 +00:00
|
|
|
rm -rf "${cfg.stateDir}/plugins/"*
|
|
|
|
rm -rf "${cfg.stateDir}/public/themes/"*
|
2018-10-11 01:04:08 +00:00
|
|
|
|
|
|
|
# start with a fresh config directory
|
|
|
|
# the config directory is copied instead of linked as some mutable data is stored in there
|
2019-02-23 03:55:21 +00:00
|
|
|
find "${cfg.stateDir}/config" ! -name "secret_token.rb" -type f -exec rm -f {} +
|
2018-10-11 12:04:47 +00:00
|
|
|
cp -r ${cfg.package}/share/redmine/config.dist/* "${cfg.stateDir}/config/"
|
2018-08-19 20:29:44 +00:00
|
|
|
|
2019-02-23 03:55:21 +00:00
|
|
|
chmod -R u+w "${cfg.stateDir}/config"
|
|
|
|
|
2018-08-19 20:29:44 +00:00
|
|
|
# link in the application configuration
|
2018-10-11 12:04:47 +00:00
|
|
|
ln -fs ${configurationYml} "${cfg.stateDir}/config/configuration.yml"
|
2018-08-19 12:09:38 +00:00
|
|
|
|
2019-02-01 14:17:05 +00:00
|
|
|
# link in the additional environment configuration
|
|
|
|
ln -fs ${additionalEnvironment} "${cfg.stateDir}/config/additional_environment.rb"
|
|
|
|
|
2018-10-11 01:04:08 +00:00
|
|
|
|
|
|
|
# link in all user specified themes
|
|
|
|
for theme in ${concatStringsSep " " (mapAttrsToList unpackTheme cfg.themes)}; do
|
2018-10-11 12:04:47 +00:00
|
|
|
ln -fs $theme/* "${cfg.stateDir}/public/themes"
|
2018-10-11 01:04:08 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# link in redmine provided themes
|
2018-10-11 12:04:47 +00:00
|
|
|
ln -sf ${cfg.package}/share/redmine/public/themes.dist/* "${cfg.stateDir}/public/themes/"
|
2018-10-11 01:04:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
# link in all user specified plugins
|
|
|
|
for plugin in ${concatStringsSep " " (mapAttrsToList unpackPlugin cfg.plugins)}; do
|
2018-10-11 12:04:47 +00:00
|
|
|
ln -fs $plugin/* "${cfg.stateDir}/plugins/''${plugin##*-redmine-plugin-}"
|
2018-10-11 01:04:08 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# handle database.passwordFile & permissions
|
2018-10-11 12:04:47 +00:00
|
|
|
cp -f ${databaseYml} "${cfg.stateDir}/config/database.yml"
|
2024-03-23 20:23:08 +00:00
|
|
|
|
2024-03-23 15:47:24 +00:00
|
|
|
${optionalString ((cfg.database.type != "sqlite3") && (cfg.database.passwordFile != null)) ''
|
2024-03-23 20:23:08 +00:00
|
|
|
DBPASS="$(head -n1 ${cfg.database.passwordFile})"
|
|
|
|
sed -e "s,#dbpass#,$DBPASS,g" -i "${cfg.stateDir}/config/database.yml"
|
|
|
|
''}
|
|
|
|
|
2018-10-11 12:04:47 +00:00
|
|
|
chmod 440 "${cfg.stateDir}/config/database.yml"
|
2018-08-19 20:29:44 +00:00
|
|
|
|
2018-10-11 01:04:08 +00:00
|
|
|
|
2018-08-19 20:29:44 +00:00
|
|
|
# generate a secret token if required
|
|
|
|
if ! test -e "${cfg.stateDir}/config/initializers/secret_token.rb"; then
|
|
|
|
${bundle} exec rake generate_secret_token
|
2018-10-11 12:04:47 +00:00
|
|
|
chmod 440 "${cfg.stateDir}/config/initializers/secret_token.rb"
|
2018-08-19 20:29:44 +00:00
|
|
|
fi
|
|
|
|
|
2018-10-11 01:04:08 +00:00
|
|
|
# execute redmine required commands prior to starting the application
|
2019-02-23 03:55:21 +00:00
|
|
|
${bundle} exec rake db:migrate
|
|
|
|
${bundle} exec rake redmine:plugins:migrate
|
|
|
|
${bundle} exec rake redmine:load_default_data
|
2014-10-07 08:53:01 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
2018-08-19 20:29:44 +00:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2014-10-07 08:53:01 +00:00
|
|
|
TimeoutSec = "300";
|
2018-10-11 01:04:08 +00:00
|
|
|
WorkingDirectory = "${cfg.package}/share/redmine";
|
2023-05-18 11:35:38 +00:00
|
|
|
ExecStart="${bundle} exec rails server -u webrick -e production -p ${toString cfg.port} -P '${cfg.stateDir}/redmine.pid'";
|
2014-10-07 08:53:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-09-14 17:51:29 +00:00
|
|
|
users.users = optionalAttrs (cfg.user == "redmine") {
|
|
|
|
redmine = {
|
2018-08-19 20:29:44 +00:00
|
|
|
group = cfg.group;
|
|
|
|
home = cfg.stateDir;
|
|
|
|
uid = config.ids.uids.redmine;
|
2019-09-14 17:51:29 +00:00
|
|
|
};
|
|
|
|
};
|
2018-08-19 20:29:44 +00:00
|
|
|
|
2019-09-14 17:51:29 +00:00
|
|
|
users.groups = optionalAttrs (cfg.group == "redmine") {
|
|
|
|
redmine.gid = config.ids.gids.redmine;
|
|
|
|
};
|
2018-08-19 20:29:44 +00:00
|
|
|
|
2014-10-07 08:53:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|