nixos/gitlab: Add a second database connection

GitLab deprecated single database connections in 15.9. [1]
From GitLab 17.0 onward it will be mandatory to define both `main` and
`ci` sections in the `database.yml`. [2]

This commit updates the module to address the upcoming breaking change.

[1]: https://gitlab.com/gitlab-org/gitlab/-/issues/387898
[2]: https://docs.gitlab.com/16.10/ee/install/installation.html#configure-gitlab-db-settings

Yaya c743d6d6 df9bc1f9

Changed files
+30 -14
nixos
modules
services
misc
+30 -14
nixos/modules/services/misc/gitlab.nix
···
gitalySocket = "${cfg.statePath}/tmp/sockets/gitaly.socket";
pathUrlQuote = url: replaceStrings ["/"] ["%2F"] url;
databaseConfig = let
val = {
adapter = "postgresql";
···
encoding = "utf8";
pool = cfg.databasePool;
} // cfg.extraDatabaseConfig;
-
in if lib.versionAtLeast (lib.getVersion cfg.packages.gitlab) "15.0" then {
-
production.main = val;
-
} else {
-
production = val;
};
# We only want to create a database if we're actually going to connect to it.
···
rm -f '${cfg.statePath}/config/database.yml'
-
${if cfg.databasePasswordFile != null then ''
db_password="$(<'${cfg.databasePasswordFile}')"
export db_password
···
>&2 echo "Database password was an empty string!"
exit 1
fi
-
jq <${pkgs.writeText "database.yml" (builtins.toJSON databaseConfig)} \
-
'.${if lib.versionAtLeast (lib.getVersion cfg.packages.gitlab) "15.0" then "production.main" else "production"}.password = $ENV.db_password' \
-
>'${cfg.statePath}/config/database.yml'
-
''
-
else ''
-
jq <${pkgs.writeText "database.yml" (builtins.toJSON databaseConfig)} \
-
>'${cfg.statePath}/config/database.yml'
-
''
-
}
${utils.genJqSecretsReplacementSnippet
gitlabConfig
···
gitalySocket = "${cfg.statePath}/tmp/sockets/gitaly.socket";
pathUrlQuote = url: replaceStrings ["/"] ["%2F"] url;
+
gitlabVersionAtLeast = version: lib.versionAtLeast (lib.getVersion cfg.packages.gitlab) version;
+
databaseConfig = let
val = {
adapter = "postgresql";
···
encoding = "utf8";
pool = cfg.databasePool;
} // cfg.extraDatabaseConfig;
+
in {
+
production = (
+
if (gitlabVersionAtLeast "15.0")
+
then { main = val; }
+
else val
+
) // lib.optionalAttrs (gitlabVersionAtLeast "15.9") {
+
ci = val // {
+
database_tasks = false;
+
};
+
};
};
# We only want to create a database if we're actually going to connect to it.
···
rm -f '${cfg.statePath}/config/database.yml'
+
${lib.optionalString (cfg.databasePasswordFile != null) ''
db_password="$(<'${cfg.databasePasswordFile}')"
export db_password
···
>&2 echo "Database password was an empty string!"
exit 1
fi
+
''}
+
# GitLab expects the `production.main` section to be the first entry in the file.
+
jq <${pkgs.writeText "database.yml" (builtins.toJSON databaseConfig)} '{
+
production: [
+
${lib.optionalString (cfg.databasePasswordFile != null) (
+
builtins.concatStringsSep "\n " (
+
[ ".production${lib.optionalString (gitlabVersionAtLeast "15.0") ".main"}.password = $ENV.db_password" ]
+
++ lib.optional (gitlabVersionAtLeast "15.9") "| .production.ci.password = $ENV.db_password"
+
++ [ "|" ]
+
)
+
)} .production
+
| to_entries[]
+
]
+
| sort_by(.key)
+
| reverse
+
| from_entries
+
}' >'${cfg.statePath}/config/database.yml'
${utils.genJqSecretsReplacementSnippet
gitlabConfig