2021-12-19 01:06:50 +00:00
|
|
|
{ config, lib, options, pkgs, utils, ... }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.gitlab;
|
2021-12-19 01:06:50 +00:00
|
|
|
opt = options.services.gitlab;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-10-21 18:38:19 +00:00
|
|
|
toml = pkgs.formats.toml {};
|
|
|
|
yaml = pkgs.formats.yaml {};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
ruby = cfg.packages.gitlab.ruby;
|
|
|
|
|
|
|
|
postgresqlPackage = if config.services.postgresql.enable then
|
|
|
|
config.services.postgresql.package
|
|
|
|
else
|
2021-06-28 23:13:55 +00:00
|
|
|
pkgs.postgresql_12;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-06-26 10:26:21 +00:00
|
|
|
# Git 2.36.1 seemingly contains a commit-graph related bug which is
|
|
|
|
# easily triggered through GitLab, so we downgrade it to 2.35.x
|
|
|
|
# until this issue is solved. See
|
|
|
|
# https://gitlab.com/gitlab-org/gitlab/-/issues/360783#note_992870101.
|
|
|
|
gitPackage =
|
|
|
|
let
|
2022-07-18 16:21:45 +00:00
|
|
|
version = "2.35.4";
|
2022-06-26 10:26:21 +00:00
|
|
|
in
|
|
|
|
pkgs.git.overrideAttrs (oldAttrs: rec {
|
|
|
|
inherit version;
|
|
|
|
src = pkgs.fetchurl {
|
|
|
|
url = "https://www.kernel.org/pub/software/scm/git/git-${version}.tar.xz";
|
2022-07-18 16:21:45 +00:00
|
|
|
sha256 = "sha256-mv13OdNkXggeKQkJ+47QcJ6lYmcw6Qjri1ZJ2ETCTOk=";
|
2022-06-26 10:26:21 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
gitlabSocket = "${cfg.statePath}/tmp/sockets/gitlab.socket";
|
|
|
|
gitalySocket = "${cfg.statePath}/tmp/sockets/gitaly.socket";
|
|
|
|
pathUrlQuote = url: replaceStrings ["/"] ["%2F"] url;
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
databaseConfig = let
|
|
|
|
val = {
|
2020-04-24 23:36:52 +00:00
|
|
|
adapter = "postgresql";
|
|
|
|
database = cfg.databaseName;
|
|
|
|
host = cfg.databaseHost;
|
|
|
|
username = cfg.databaseUsername;
|
|
|
|
encoding = "utf8";
|
|
|
|
pool = cfg.databasePool;
|
|
|
|
} // cfg.extraDatabaseConfig;
|
2022-06-16 17:23:12 +00:00
|
|
|
in if lib.versionAtLeast (lib.getVersion cfg.packages.gitlab) "15.0" then {
|
|
|
|
production.main = val;
|
|
|
|
} else {
|
|
|
|
production = val;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
# We only want to create a database if we're actually going to connect to it.
|
|
|
|
databaseActuallyCreateLocally = cfg.databaseCreateLocally && cfg.databaseHost == "";
|
|
|
|
|
|
|
|
gitalyToml = pkgs.writeText "gitaly.toml" ''
|
|
|
|
socket_path = "${lib.escape ["\""] gitalySocket}"
|
|
|
|
bin_dir = "${cfg.packages.gitaly}/bin"
|
|
|
|
prometheus_listen_addr = "localhost:9236"
|
|
|
|
|
|
|
|
[git]
|
2022-06-26 10:26:21 +00:00
|
|
|
bin_path = "${gitPackage}/bin/git"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
[gitaly-ruby]
|
|
|
|
dir = "${cfg.packages.gitaly.ruby}"
|
|
|
|
|
|
|
|
[gitlab-shell]
|
|
|
|
dir = "${cfg.packages.gitlab-shell}"
|
2020-11-24 20:58:05 +00:00
|
|
|
|
2020-12-27 14:24:52 +00:00
|
|
|
[hooks]
|
|
|
|
custom_hooks_dir = "${cfg.statePath}/custom_hooks"
|
|
|
|
|
2020-11-24 20:58:05 +00:00
|
|
|
[gitlab]
|
2020-06-18 07:06:33 +00:00
|
|
|
secret_file = "${cfg.statePath}/gitlab_shell_secret"
|
2020-11-24 20:58:05 +00:00
|
|
|
url = "http+unix://${pathUrlQuote gitlabSocket}"
|
|
|
|
|
|
|
|
[gitlab.http-settings]
|
|
|
|
self_signed_cert = false
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
${concatStringsSep "\n" (attrValues (mapAttrs (k: v: ''
|
|
|
|
[[storage]]
|
|
|
|
name = "${lib.escape ["\""] k}"
|
|
|
|
path = "${lib.escape ["\""] v.path}"
|
|
|
|
'') gitlabConfig.production.repositories.storages))}
|
|
|
|
'';
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
gitlabShellConfig = flip recursiveUpdate cfg.extraShellConfig {
|
2020-04-24 23:36:52 +00:00
|
|
|
user = cfg.user;
|
|
|
|
gitlab_url = "http+unix://${pathUrlQuote gitlabSocket}";
|
|
|
|
http_settings.self_signed_cert = false;
|
|
|
|
repos_path = "${cfg.statePath}/repositories";
|
|
|
|
secret_file = "${cfg.statePath}/gitlab_shell_secret";
|
|
|
|
log_file = "${cfg.statePath}/log/gitlab-shell.log";
|
|
|
|
};
|
|
|
|
|
2020-08-20 17:08:02 +00:00
|
|
|
redisConfig.production.url = cfg.redisUrl;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-10-21 18:38:19 +00:00
|
|
|
cableYml = yaml.generate "cable.yml" {
|
|
|
|
production = {
|
|
|
|
adapter = "redis";
|
|
|
|
url = cfg.redisUrl;
|
|
|
|
channel_prefix = "gitlab_production";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-10-16 20:44:37 +00:00
|
|
|
pagesArgs = [
|
|
|
|
"-pages-domain" gitlabConfig.production.pages.host
|
|
|
|
"-pages-root" "${gitlabConfig.production.shared.path}/pages"
|
|
|
|
] ++ cfg.pagesExtraArgs;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
gitlabConfig = {
|
|
|
|
# These are the default settings from config/gitlab.example.yml
|
|
|
|
production = flip recursiveUpdate cfg.extraConfig {
|
|
|
|
gitlab = {
|
|
|
|
host = cfg.host;
|
|
|
|
port = cfg.port;
|
|
|
|
https = cfg.https;
|
|
|
|
user = cfg.user;
|
|
|
|
email_enabled = true;
|
|
|
|
email_display_name = "GitLab";
|
|
|
|
email_reply_to = "noreply@localhost";
|
|
|
|
default_theme = 2;
|
|
|
|
default_projects_features = {
|
|
|
|
issues = true;
|
|
|
|
merge_requests = true;
|
|
|
|
wiki = true;
|
|
|
|
snippets = true;
|
|
|
|
builds = true;
|
|
|
|
container_registry = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
repositories.storages.default.path = "${cfg.statePath}/repositories";
|
|
|
|
repositories.storages.default.gitaly_address = "unix:${gitalySocket}";
|
|
|
|
artifacts.enabled = true;
|
|
|
|
lfs.enabled = true;
|
|
|
|
gravatar.enabled = true;
|
|
|
|
cron_jobs = { };
|
|
|
|
gitlab_ci.builds_path = "${cfg.statePath}/builds";
|
|
|
|
ldap.enabled = false;
|
|
|
|
omniauth.enabled = false;
|
|
|
|
shared.path = "${cfg.statePath}/shared";
|
|
|
|
gitaly.client_path = "${cfg.packages.gitaly}/bin";
|
2021-04-05 15:23:46 +00:00
|
|
|
backup = {
|
2021-09-18 10:52:07 +00:00
|
|
|
gitaly_backup_path = "${cfg.packages.gitaly}/bin/gitaly-backup";
|
2021-04-05 15:23:46 +00:00
|
|
|
path = cfg.backup.path;
|
|
|
|
keep_time = cfg.backup.keepTime;
|
2021-04-08 16:26:57 +00:00
|
|
|
} // (optionalAttrs (cfg.backup.uploadOptions != {}) {
|
2021-04-05 15:23:46 +00:00
|
|
|
upload = cfg.backup.uploadOptions;
|
2021-04-08 16:26:57 +00:00
|
|
|
});
|
2020-04-24 23:36:52 +00:00
|
|
|
gitlab_shell = {
|
|
|
|
path = "${cfg.packages.gitlab-shell}";
|
|
|
|
hooks_path = "${cfg.statePath}/shell/hooks";
|
|
|
|
secret_file = "${cfg.statePath}/gitlab_shell_secret";
|
|
|
|
upload_pack = true;
|
|
|
|
receive_pack = true;
|
|
|
|
};
|
|
|
|
workhorse.secret_file = "${cfg.statePath}/.gitlab_workhorse_secret";
|
2020-11-24 20:58:05 +00:00
|
|
|
gitlab_kas.secret_file = "${cfg.statePath}/.gitlab_kas_secret";
|
2022-06-26 10:26:21 +00:00
|
|
|
git.bin_path = "${gitPackage}/bin/git";
|
2020-04-24 23:36:52 +00:00
|
|
|
monitoring = {
|
|
|
|
ip_whitelist = [ "127.0.0.0/8" "::1/128" ];
|
|
|
|
sidekiq_exporter = {
|
|
|
|
enable = true;
|
|
|
|
address = "localhost";
|
|
|
|
port = 3807;
|
|
|
|
};
|
|
|
|
};
|
2021-07-14 22:03:04 +00:00
|
|
|
registry = lib.optionalAttrs cfg.registry.enable {
|
|
|
|
enabled = true;
|
|
|
|
host = cfg.registry.externalAddress;
|
|
|
|
port = cfg.registry.externalPort;
|
|
|
|
key = cfg.registry.keyFile;
|
|
|
|
api_url = "http://${config.services.dockerRegistry.listenAddress}:${toString config.services.dockerRegistry.port}/";
|
2022-09-09 14:08:57 +00:00
|
|
|
issuer = cfg.registry.issuer;
|
2021-07-14 22:03:04 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
extra = {};
|
|
|
|
uploads.storage_path = cfg.statePath;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
gitlabEnv = cfg.packages.gitlab.gitlabEnv // {
|
2020-04-24 23:36:52 +00:00
|
|
|
HOME = "${cfg.statePath}/home";
|
2021-03-09 03:18:52 +00:00
|
|
|
PUMA_PATH = "${cfg.statePath}/";
|
2020-04-24 23:36:52 +00:00
|
|
|
GITLAB_PATH = "${cfg.packages.gitlab}/share/gitlab/";
|
2020-06-02 18:00:15 +00:00
|
|
|
SCHEMA = "${cfg.statePath}/db/structure.sql";
|
2020-04-24 23:36:52 +00:00
|
|
|
GITLAB_UPLOADS_PATH = "${cfg.statePath}/uploads";
|
|
|
|
GITLAB_LOG_PATH = "${cfg.statePath}/log";
|
|
|
|
GITLAB_REDIS_CONFIG_FILE = pkgs.writeText "redis.yml" (builtins.toJSON redisConfig);
|
|
|
|
prometheus_multiproc_dir = "/run/gitlab";
|
|
|
|
RAILS_ENV = "production";
|
2021-05-03 20:48:10 +00:00
|
|
|
MALLOC_ARENA_MAX = "2";
|
2021-07-14 22:03:04 +00:00
|
|
|
} // cfg.extraEnv;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-10-21 18:38:19 +00:00
|
|
|
runtimeDeps = with pkgs; [
|
|
|
|
nodejs
|
|
|
|
gzip
|
|
|
|
git
|
|
|
|
gnutar
|
|
|
|
postgresqlPackage
|
|
|
|
coreutils
|
|
|
|
procps
|
|
|
|
findutils # Needed for gitlab:cleanup:orphan_job_artifact_files
|
|
|
|
];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
gitlab-rake = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "gitlab-rake";
|
2022-10-21 18:38:19 +00:00
|
|
|
nativeBuildInputs = [ pkgs.makeWrapper ];
|
2020-04-24 23:36:52 +00:00
|
|
|
dontBuild = true;
|
|
|
|
dontUnpack = true;
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
makeWrapper ${cfg.packages.gitlab.rubyEnv}/bin/rake $out/bin/gitlab-rake \
|
|
|
|
${concatStrings (mapAttrsToList (name: value: "--set ${name} '${value}' ") gitlabEnv)} \
|
2022-10-21 18:38:19 +00:00
|
|
|
--set PATH '${lib.makeBinPath runtimeDeps}:$PATH' \
|
2020-04-24 23:36:52 +00:00
|
|
|
--set RAKEOPT '-f ${cfg.packages.gitlab}/share/gitlab/Rakefile' \
|
2022-04-27 09:35:20 +00:00
|
|
|
--chdir '${cfg.packages.gitlab}/share/gitlab'
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
gitlab-rails = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "gitlab-rails";
|
2022-10-21 18:38:19 +00:00
|
|
|
nativeBuildInputs = [ pkgs.makeWrapper ];
|
2020-04-24 23:36:52 +00:00
|
|
|
dontBuild = true;
|
|
|
|
dontUnpack = true;
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
makeWrapper ${cfg.packages.gitlab.rubyEnv}/bin/rails $out/bin/gitlab-rails \
|
|
|
|
${concatStrings (mapAttrsToList (name: value: "--set ${name} '${value}' ") gitlabEnv)} \
|
2022-10-21 18:38:19 +00:00
|
|
|
--set PATH '${lib.makeBinPath runtimeDeps}:$PATH' \
|
2022-04-27 09:35:20 +00:00
|
|
|
--chdir '${cfg.packages.gitlab}/share/gitlab'
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraGitlabRb = pkgs.writeText "extra-gitlab.rb" cfg.extraGitlabRb;
|
|
|
|
|
|
|
|
smtpSettings = pkgs.writeText "gitlab-smtp-settings.rb" ''
|
|
|
|
if Rails.env.production?
|
|
|
|
Rails.application.config.action_mailer.delivery_method = :smtp
|
|
|
|
|
|
|
|
ActionMailer::Base.delivery_method = :smtp
|
|
|
|
ActionMailer::Base.smtp_settings = {
|
|
|
|
address: "${cfg.smtp.address}",
|
|
|
|
port: ${toString cfg.smtp.port},
|
|
|
|
${optionalString (cfg.smtp.username != null) ''user_name: "${cfg.smtp.username}",''}
|
|
|
|
${optionalString (cfg.smtp.passwordFile != null) ''password: "@smtpPassword@",''}
|
|
|
|
domain: "${cfg.smtp.domain}",
|
|
|
|
${optionalString (cfg.smtp.authentication != null) "authentication: :${cfg.smtp.authentication},"}
|
2020-05-03 17:38:23 +00:00
|
|
|
enable_starttls_auto: ${boolToString cfg.smtp.enableStartTLSAuto},
|
2021-03-23 19:22:30 +00:00
|
|
|
tls: ${boolToString cfg.smtp.tls},
|
2020-04-24 23:36:52 +00:00
|
|
|
ca_file: "/etc/ssl/certs/ca-certificates.crt",
|
|
|
|
openssl_verify_mode: '${cfg.smtp.opensslVerifyMode}'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule [ "services" "gitlab" "stateDir" ] [ "services" "gitlab" "statePath" ])
|
2021-04-05 15:23:46 +00:00
|
|
|
(mkRenamedOptionModule [ "services" "gitlab" "backupPath" ] [ "services" "gitlab" "backup" "path" ])
|
2020-04-24 23:36:52 +00:00
|
|
|
(mkRemovedOptionModule [ "services" "gitlab" "satelliteDir" ] "")
|
|
|
|
];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.gitlab = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Enable the gitlab service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
packages.gitlab = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.gitlab;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.gitlab";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Reference to the gitlab package";
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression "pkgs.gitlab-ee";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
packages.gitlab-shell = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.gitlab-shell;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.gitlab-shell";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Reference to the gitlab-shell package";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
packages.gitlab-workhorse = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.gitlab-workhorse;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.gitlab-workhorse";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Reference to the gitlab-workhorse package";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
packages.gitaly = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.gitaly;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.gitaly";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Reference to the gitaly package";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2020-10-16 20:44:37 +00:00
|
|
|
packages.pages = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.gitlab-pages;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression "pkgs.gitlab-pages";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Reference to the gitlab-pages package";
|
2020-10-16 20:44:37 +00:00
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
statePath = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/gitlab/state";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-04-05 15:23:46 +00:00
|
|
|
GitLab state directory. Configuration, repositories and
|
2020-04-24 23:36:52 +00:00
|
|
|
logs, among other things, are stored here.
|
|
|
|
|
|
|
|
The directory will be created automatically if it doesn't
|
|
|
|
exist already. Its parent directories must be owned by
|
2022-08-12 12:06:08 +00:00
|
|
|
either `root` or the user set in
|
|
|
|
{option}`services.gitlab.user`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-07-14 22:03:04 +00:00
|
|
|
extraEnv = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = {};
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-07-14 22:03:04 +00:00
|
|
|
Additional environment variables for the GitLab environment.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-04-05 15:23:46 +00:00
|
|
|
backup.startAt = mkOption {
|
|
|
|
type = with types; either str (listOf str);
|
|
|
|
default = [];
|
|
|
|
example = "03:00";
|
2022-08-21 13:32:41 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-04-05 15:23:46 +00:00
|
|
|
The time(s) to run automatic backup of GitLab
|
|
|
|
state. Specified in systemd's time format; see
|
2022-08-21 13:32:41 +00:00
|
|
|
{manpage}`systemd.time(7)`.
|
2021-04-05 15:23:46 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
backup.path = mkOption {
|
2020-04-24 23:36:52 +00:00
|
|
|
type = types.str;
|
|
|
|
default = cfg.statePath + "/backup";
|
2021-12-19 01:06:50 +00:00
|
|
|
defaultText = literalExpression ''config.${opt.statePath} + "/backup"'';
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "GitLab path for backups.";
|
2021-04-05 15:23:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
backup.keepTime = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 0;
|
|
|
|
example = 48;
|
|
|
|
apply = x: x * 60 * 60;
|
2022-08-21 13:32:41 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-04-05 15:23:46 +00:00
|
|
|
How long to keep the backups around, in
|
2022-08-21 13:32:41 +00:00
|
|
|
hours. `0` means “keep forever”.
|
2021-04-05 15:23:46 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
backup.skip = mkOption {
|
|
|
|
type = with types;
|
|
|
|
let value = enum [
|
|
|
|
"db"
|
|
|
|
"uploads"
|
|
|
|
"builds"
|
|
|
|
"artifacts"
|
|
|
|
"lfs"
|
|
|
|
"registry"
|
|
|
|
"pages"
|
|
|
|
"repositories"
|
|
|
|
"tar"
|
|
|
|
];
|
|
|
|
in
|
|
|
|
either value (listOf value);
|
|
|
|
default = [];
|
|
|
|
example = [ "artifacts" "lfs" ];
|
|
|
|
apply = x: if isString x then x else concatStringsSep "," x;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-04-05 15:23:46 +00:00
|
|
|
Directories to exclude from the backup. The example excludes
|
|
|
|
CI artifacts and LFS objects from the backups. The
|
2022-08-12 12:06:08 +00:00
|
|
|
`tar` option skips the creation of a tar
|
2021-04-05 15:23:46 +00:00
|
|
|
file.
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
Refer to <https://docs.gitlab.com/ee/raketasks/backup_restore.html#excluding-specific-directories-from-the-backup>
|
2021-04-05 15:23:46 +00:00
|
|
|
for more information.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
backup.uploadOptions = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = {};
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
2021-04-05 15:23:46 +00:00
|
|
|
{
|
|
|
|
# Fog storage connection settings, see http://fog.io/storage/
|
|
|
|
connection = {
|
|
|
|
provider = "AWS";
|
|
|
|
region = "eu-north-1";
|
|
|
|
aws_access_key_id = "AKIAXXXXXXXXXXXXXXXX";
|
|
|
|
aws_secret_access_key = { _secret = config.deployment.keys.aws_access_key.path; };
|
|
|
|
};
|
|
|
|
|
|
|
|
# The remote 'directory' to store your backups in.
|
|
|
|
# For S3, this would be the bucket name.
|
|
|
|
remote_directory = "my-gitlab-backups";
|
|
|
|
|
|
|
|
# Use multipart uploads when file size reaches 100MB, see
|
|
|
|
# http://docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu.html
|
|
|
|
multipart_chunk_size = 104857600;
|
|
|
|
|
|
|
|
# Turns on AWS Server-Side Encryption with Amazon S3-Managed Keys for backups, this is optional
|
|
|
|
encryption = "AES256";
|
|
|
|
|
|
|
|
# Specifies Amazon S3 storage class to use for backups, this is optional
|
|
|
|
storage_class = "STANDARD";
|
|
|
|
};
|
|
|
|
'';
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-04-05 15:23:46 +00:00
|
|
|
GitLab automatic upload specification. Tells GitLab to
|
|
|
|
upload the backup to a remote location when done.
|
|
|
|
|
|
|
|
Attributes specified here are added under
|
2022-08-12 12:06:08 +00:00
|
|
|
`production -> backup -> upload` in
|
|
|
|
{file}`config/gitlab.yml`.
|
2021-04-05 15:23:46 +00:00
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
databaseHost = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2022-08-21 13:32:41 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
GitLab database hostname. An empty string means
|
|
|
|
“use local unix socket connection”.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
databasePasswordFile = mkOption {
|
|
|
|
type = with types; nullOr path;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-04-05 15:23:46 +00:00
|
|
|
File containing the GitLab database user password.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
This should be a string, not a nix path, since nix paths are
|
|
|
|
copied into the world-readable nix store.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
databaseCreateLocally = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Whether a database should be automatically created on the
|
2022-08-12 12:06:08 +00:00
|
|
|
local host. Set this to `false` if you plan
|
2020-04-24 23:36:52 +00:00
|
|
|
on provisioning a local database yourself. This has no effect
|
2022-08-12 12:06:08 +00:00
|
|
|
if {option}`services.gitlab.databaseHost` is customized.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
databaseName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "gitlab";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "GitLab database name.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
databaseUsername = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "gitlab";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "GitLab database user.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
databasePool = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 5;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Database connection pool size.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraDatabaseConfig = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = {};
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Extra configuration in config/database.yml.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2020-08-20 17:08:02 +00:00
|
|
|
redisUrl = mkOption {
|
|
|
|
type = types.str;
|
2022-10-21 18:38:19 +00:00
|
|
|
default = "unix:/run/gitlab/redis.sock";
|
|
|
|
example = "redis://localhost:6379/";
|
|
|
|
description = lib.mdDoc "Redis URL for all GitLab services.";
|
2020-08-20 17:08:02 +00:00
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
extraGitlabRb = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
if Rails.env.production?
|
|
|
|
Rails.application.config.action_mailer.delivery_method = :sendmail
|
|
|
|
ActionMailer::Base.delivery_method = :sendmail
|
|
|
|
ActionMailer::Base.sendmail_settings = {
|
|
|
|
location: "/run/wrappers/bin/sendmail",
|
|
|
|
arguments: "-i -t"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
'';
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Extra configuration to be placed in config/extra-gitlab.rb. This can
|
|
|
|
be used to add configuration not otherwise exposed through this module's
|
|
|
|
options.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = config.networking.hostName;
|
2021-12-06 16:07:01 +00:00
|
|
|
defaultText = literalExpression "config.networking.hostName";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "GitLab host name. Used e.g. for copy-paste URLs.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2021-06-28 23:13:55 +00:00
|
|
|
type = types.port;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 8080;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-04-05 15:23:46 +00:00
|
|
|
GitLab server port for copy-paste URLs, e.g. 80 or 443 if you're
|
2020-04-24 23:36:52 +00:00
|
|
|
service over https.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
https = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether gitlab prints URLs with https as scheme.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "gitlab";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "User to run gitlab and all related services.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "gitlab";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Group to run gitlab and all related services.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
initialRootEmail = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "admin@local.host";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Initial email address of the root account if this is a new install.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
initialRootPasswordFile = mkOption {
|
|
|
|
type = with types; nullOr path;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
File containing the initial password of the root account if
|
|
|
|
this is a new install.
|
|
|
|
|
|
|
|
This should be a string, not a nix path, since nix paths are
|
|
|
|
copied into the world-readable nix store.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-07-14 22:03:04 +00:00
|
|
|
registry = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Enable GitLab container registry.";
|
2021-07-14 22:03:04 +00:00
|
|
|
};
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = config.services.gitlab.host;
|
2021-12-06 16:07:01 +00:00
|
|
|
defaultText = literalExpression "config.services.gitlab.host";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "GitLab container registry host name.";
|
2021-07-14 22:03:04 +00:00
|
|
|
};
|
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 4567;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "GitLab container registry port.";
|
2021-07-14 22:03:04 +00:00
|
|
|
};
|
|
|
|
certFile = mkOption {
|
|
|
|
type = types.path;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Path to GitLab container registry certificate.";
|
2021-07-14 22:03:04 +00:00
|
|
|
};
|
|
|
|
keyFile = mkOption {
|
|
|
|
type = types.path;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Path to GitLab container registry certificate-key.";
|
2021-07-14 22:03:04 +00:00
|
|
|
};
|
|
|
|
defaultForProjects = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = cfg.registry.enable;
|
2021-12-19 01:06:50 +00:00
|
|
|
defaultText = literalExpression "config.${opt.registry.enable}";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "If GitLab container registry should be enabled by default for projects.";
|
2021-07-14 22:03:04 +00:00
|
|
|
};
|
|
|
|
issuer = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "gitlab-issuer";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "GitLab container registry issuer.";
|
2021-07-14 22:03:04 +00:00
|
|
|
};
|
|
|
|
serviceName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "container_registry";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "GitLab container registry service name.";
|
2021-07-14 22:03:04 +00:00
|
|
|
};
|
|
|
|
externalAddress = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "External address used to access registry from the internet";
|
2021-07-14 22:03:04 +00:00
|
|
|
};
|
|
|
|
externalPort = mkOption {
|
|
|
|
type = types.int;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "External port used to access registry from the internet";
|
2021-07-14 22:03:04 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
smtp = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Enable gitlab mail delivery over SMTP.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
address = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Address of the SMTP server for GitLab.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
2021-03-09 03:18:52 +00:00
|
|
|
default = 25;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Port of the SMTP server for GitLab.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
username = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Username of the SMTP server for GitLab.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
passwordFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-04-05 15:23:46 +00:00
|
|
|
File containing the password of the SMTP server for GitLab.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
This should be a string, not a nix path, since nix paths
|
|
|
|
are copied into the world-readable nix store.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
domain = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "HELO domain to use for outgoing mail.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
authentication = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Authentication type to use, see http://api.rubyonrails.org/classes/ActionMailer/Base.html";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enableStartTLSAuto = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to try to use StartTLS.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-03-23 19:22:30 +00:00
|
|
|
tls = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to use TLS wrapper-mode.";
|
2021-03-23 19:22:30 +00:00
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
opensslVerifyMode = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "peer";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "How OpenSSL checks the certificate, see http://api.rubyonrails.org/classes/ActionMailer/Base.html";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-10-16 20:44:37 +00:00
|
|
|
pagesExtraArgs = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ "-listen-proxy" "127.0.0.1:8090" ];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Arguments to pass to the gitlab-pages daemon";
|
2020-10-16 20:44:37 +00:00
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
secrets.secretFile = mkOption {
|
|
|
|
type = with types; nullOr path;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
A file containing the secret used to encrypt variables in
|
|
|
|
the DB. If you change or lose this key you will be unable to
|
|
|
|
access variables stored in database.
|
|
|
|
|
2021-05-03 20:48:10 +00:00
|
|
|
Make sure the secret is at least 32 characters and all random,
|
2020-04-24 23:36:52 +00:00
|
|
|
no regular words or you'll be exposed to dictionary attacks.
|
|
|
|
|
|
|
|
This should be a string, not a nix path, since nix paths are
|
|
|
|
copied into the world-readable nix store.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
secrets.dbFile = mkOption {
|
|
|
|
type = with types; nullOr path;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
A file containing the secret used to encrypt variables in
|
|
|
|
the DB. If you change or lose this key you will be unable to
|
|
|
|
access variables stored in database.
|
|
|
|
|
2021-05-03 20:48:10 +00:00
|
|
|
Make sure the secret is at least 32 characters and all random,
|
2020-04-24 23:36:52 +00:00
|
|
|
no regular words or you'll be exposed to dictionary attacks.
|
|
|
|
|
|
|
|
This should be a string, not a nix path, since nix paths are
|
|
|
|
copied into the world-readable nix store.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
secrets.otpFile = mkOption {
|
|
|
|
type = with types; nullOr path;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
A file containing the secret used to encrypt secrets for OTP
|
|
|
|
tokens. If you change or lose this key, users which have 2FA
|
|
|
|
enabled for login won't be able to login anymore.
|
|
|
|
|
2021-05-03 20:48:10 +00:00
|
|
|
Make sure the secret is at least 32 characters and all random,
|
2020-04-24 23:36:52 +00:00
|
|
|
no regular words or you'll be exposed to dictionary attacks.
|
|
|
|
|
|
|
|
This should be a string, not a nix path, since nix paths are
|
|
|
|
copied into the world-readable nix store.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
secrets.jwsFile = mkOption {
|
|
|
|
type = with types; nullOr path;
|
|
|
|
default = null;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
A file containing the secret used to encrypt session
|
|
|
|
keys. If you change or lose this key, users will be
|
|
|
|
disconnected.
|
|
|
|
|
|
|
|
Make sure the secret is an RSA private key in PEM format. You can
|
|
|
|
generate one with
|
|
|
|
|
|
|
|
openssl genrsa 2048
|
|
|
|
|
|
|
|
This should be a string, not a nix path, since nix paths are
|
|
|
|
copied into the world-readable nix store.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
extraShellConfig = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = {};
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Extra configuration to merge into shell-config.yml";
|
2020-09-25 04:45:31 +00:00
|
|
|
};
|
|
|
|
|
2021-05-03 20:48:10 +00:00
|
|
|
puma.workers = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 2;
|
|
|
|
apply = x: builtins.toString x;
|
2022-09-09 14:08:57 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-03 20:48:10 +00:00
|
|
|
The number of worker processes Puma should spawn. This
|
|
|
|
controls the amount of parallel Ruby code can be
|
2022-09-09 14:08:57 +00:00
|
|
|
executed. GitLab recommends `Number of CPU cores - 1`, but at least two.
|
|
|
|
|
|
|
|
::: {.note}
|
|
|
|
Each worker consumes quite a bit of memory, so
|
|
|
|
be careful when increasing this.
|
|
|
|
:::
|
2021-05-03 20:48:10 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
puma.threadsMin = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 0;
|
|
|
|
apply = x: builtins.toString x;
|
2022-09-09 14:08:57 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-03 20:48:10 +00:00
|
|
|
The minimum number of threads Puma should use per
|
|
|
|
worker.
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
::: {.note}
|
|
|
|
Each thread consumes memory and contributes to Global VM
|
|
|
|
Lock contention, so be careful when increasing this.
|
|
|
|
:::
|
2021-05-03 20:48:10 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
puma.threadsMax = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 4;
|
|
|
|
apply = x: builtins.toString x;
|
2022-09-09 14:08:57 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-03 20:48:10 +00:00
|
|
|
The maximum number of threads Puma should use per
|
|
|
|
worker. This limits how many threads Puma will automatically
|
|
|
|
spawn in response to requests. In contrast to workers,
|
|
|
|
threads will never be able to run Ruby code in parallel, but
|
|
|
|
give higher IO parallelism.
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
::: {.note}
|
|
|
|
Each thread consumes memory and contributes to Global VM
|
|
|
|
Lock contention, so be careful when increasing this.
|
|
|
|
:::
|
2021-05-03 20:48:10 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
sidekiq.memoryKiller.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-03 20:48:10 +00:00
|
|
|
Whether the Sidekiq MemoryKiller should be turned
|
|
|
|
on. MemoryKiller kills Sidekiq when its memory consumption
|
|
|
|
exceeds a certain limit.
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
See <https://docs.gitlab.com/ee/administration/operations/sidekiq_memory_killer.html>
|
2021-05-03 20:48:10 +00:00
|
|
|
for details.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
sidekiq.memoryKiller.maxMemory = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 2000;
|
|
|
|
apply = x: builtins.toString (x * 1024);
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-03 20:48:10 +00:00
|
|
|
The maximum amount of memory, in MiB, a Sidekiq worker is
|
|
|
|
allowed to consume before being killed.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
sidekiq.memoryKiller.graceTime = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 900;
|
|
|
|
apply = x: builtins.toString x;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-03 20:48:10 +00:00
|
|
|
The time MemoryKiller waits after noticing excessive memory
|
|
|
|
consumption before killing Sidekiq.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
sidekiq.memoryKiller.shutdownWait = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 30;
|
|
|
|
apply = x: builtins.toString x;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-05-03 20:48:10 +00:00
|
|
|
The time allowed for all jobs to finish before Sidekiq is
|
|
|
|
killed forcefully.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
logrotate = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-09-18 10:52:07 +00:00
|
|
|
Enable rotation of log files.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
frequency = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "daily";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "How often to rotate the logs.";
|
2021-09-18 10:52:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
keep = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 30;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "How many rotations to keep.";
|
2021-09-18 10:52:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
2022-04-03 18:54:34 +00:00
|
|
|
default = "";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-09-18 10:52:07 +00:00
|
|
|
Extra logrotate config options for this path. Refer to
|
2022-08-12 12:06:08 +00:00
|
|
|
<https://linux.die.net/man/8/logrotate> for details.
|
2021-09-18 10:52:07 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-10-21 18:38:19 +00:00
|
|
|
workhorse.config = mkOption {
|
|
|
|
type = toml.type;
|
|
|
|
default = {};
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
object_storage.provider = "AWS";
|
|
|
|
object_storage.s3 = {
|
|
|
|
aws_access_key_id = "AKIAXXXXXXXXXXXXXXXX";
|
|
|
|
aws_secret_access_key = { _secret = "/var/keys/aws_secret_access_key"; };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Configuration options to add to Workhorse's configuration
|
|
|
|
file.
|
|
|
|
|
|
|
|
See
|
|
|
|
<https://gitlab.com/gitlab-org/gitlab/-/blob/master/workhorse/config.toml.example>
|
|
|
|
and
|
|
|
|
<https://docs.gitlab.com/ee/development/workhorse/configuration.html>
|
|
|
|
for examples and option documentation.
|
|
|
|
|
|
|
|
Options containing secret data should be set to an attribute
|
|
|
|
set containing the attribute `_secret` - a string pointing
|
|
|
|
to a file containing the value the option should be set
|
|
|
|
to. See the example to get a better picture of this: in the
|
|
|
|
resulting configuration file, the
|
|
|
|
`object_storage.s3.aws_secret_access_key` key will be set to
|
|
|
|
the contents of the {file}`/var/keys/aws_secret_access_key`
|
|
|
|
file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
extraConfig = mkOption {
|
2022-10-21 18:38:19 +00:00
|
|
|
type = yaml.type;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = {};
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
2020-04-24 23:36:52 +00:00
|
|
|
{
|
|
|
|
gitlab = {
|
|
|
|
default_projects_features = {
|
|
|
|
builds = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
omniauth = {
|
|
|
|
enabled = true;
|
|
|
|
auto_sign_in_with_provider = "openid_connect";
|
|
|
|
allow_single_sign_on = ["openid_connect"];
|
|
|
|
block_auto_created_users = false;
|
|
|
|
providers = [
|
|
|
|
{
|
|
|
|
name = "openid_connect";
|
|
|
|
label = "OpenID Connect";
|
|
|
|
args = {
|
|
|
|
name = "openid_connect";
|
|
|
|
scope = ["openid" "profile"];
|
|
|
|
response_type = "code";
|
|
|
|
issuer = "https://keycloak.example.com/auth/realms/My%20Realm";
|
|
|
|
discovery = true;
|
|
|
|
client_auth_method = "query";
|
|
|
|
uid_field = "preferred_username";
|
|
|
|
client_options = {
|
|
|
|
identifier = "gitlab";
|
|
|
|
secret = { _secret = "/var/keys/gitlab_oidc_secret"; };
|
|
|
|
redirect_uri = "https://git.example.com/users/auth/openid_connect/callback";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
'';
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Extra options to be added under
|
2022-08-12 12:06:08 +00:00
|
|
|
`production` in
|
|
|
|
{file}`config/gitlab.yml`, as a nix attribute
|
2020-04-24 23:36:52 +00:00
|
|
|
set.
|
|
|
|
|
|
|
|
Options containing secret data should be set to an attribute
|
2022-08-12 12:06:08 +00:00
|
|
|
set containing the attribute `_secret` - a
|
2020-04-24 23:36:52 +00:00
|
|
|
string pointing to a file containing the value the option
|
|
|
|
should be set to. See the example to get a better picture of
|
|
|
|
this: in the resulting
|
2022-08-12 12:06:08 +00:00
|
|
|
{file}`config/gitlab.yml` file, the
|
|
|
|
`production.omniauth.providers[0].args.client_options.secret`
|
2020-04-24 23:36:52 +00:00
|
|
|
key will be set to the contents of the
|
2022-08-12 12:06:08 +00:00
|
|
|
{file}`/var/keys/gitlab_oidc_secret` file.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = databaseActuallyCreateLocally -> (cfg.user == cfg.databaseUsername);
|
|
|
|
message = ''For local automatic database provisioning (services.gitlab.databaseCreateLocally == true) with peer authentication (services.gitlab.databaseHost == "") to work services.gitlab.user and services.gitlab.databaseUsername must be identical.'';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = (cfg.databaseHost != "") -> (cfg.databasePasswordFile != null);
|
|
|
|
message = "When services.gitlab.databaseHost is customized, services.gitlab.databasePasswordFile must be set!";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = cfg.initialRootPasswordFile != null;
|
|
|
|
message = "services.gitlab.initialRootPasswordFile must be set!";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = cfg.secrets.secretFile != null;
|
|
|
|
message = "services.gitlab.secrets.secretFile must be set!";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = cfg.secrets.dbFile != null;
|
|
|
|
message = "services.gitlab.secrets.dbFile must be set!";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = cfg.secrets.otpFile != null;
|
|
|
|
message = "services.gitlab.secrets.otpFile must be set!";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = cfg.secrets.jwsFile != null;
|
|
|
|
message = "services.gitlab.secrets.jwsFile must be set!";
|
|
|
|
}
|
2021-06-28 23:13:55 +00:00
|
|
|
{
|
|
|
|
assertion = versionAtLeast postgresqlPackage.version "12.0.0";
|
2021-07-14 22:03:04 +00:00
|
|
|
message = "PostgreSQL >=12 is required to run GitLab 14. Follow the instructions in the manual section for upgrading PostgreSQL here: https://nixos.org/manual/nixos/stable/index.html#module-services-postgres-upgrading";
|
2021-06-28 23:13:55 +00:00
|
|
|
}
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.git gitlab-rake gitlab-rails cfg.packages.gitlab-shell ];
|
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
systemd.targets.gitlab = {
|
|
|
|
description = "Common target for all GitLab services.";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
# Redis is required for the sidekiq queue runner.
|
2022-02-20 05:27:41 +00:00
|
|
|
services.redis.servers.gitlab = {
|
|
|
|
enable = mkDefault true;
|
2022-10-21 18:38:19 +00:00
|
|
|
user = mkDefault cfg.user;
|
|
|
|
unixSocket = mkDefault "/run/gitlab/redis.sock";
|
|
|
|
unixSocketPerm = mkDefault 770;
|
2022-02-20 05:27:41 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# We use postgres as the main data store.
|
|
|
|
services.postgresql = optionalAttrs databaseActuallyCreateLocally {
|
|
|
|
enable = true;
|
|
|
|
ensureUsers = singleton { name = cfg.databaseUsername; };
|
|
|
|
};
|
2020-08-20 17:08:02 +00:00
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
# Enable rotation of log files
|
|
|
|
services.logrotate = {
|
|
|
|
enable = cfg.logrotate.enable;
|
2022-04-03 18:54:34 +00:00
|
|
|
settings = {
|
2021-09-18 10:52:07 +00:00
|
|
|
gitlab = {
|
2022-04-03 18:54:34 +00:00
|
|
|
files = "${cfg.statePath}/log/*.log";
|
|
|
|
su = "${cfg.user} ${cfg.group}";
|
2021-09-18 10:52:07 +00:00
|
|
|
frequency = cfg.logrotate.frequency;
|
2022-04-03 18:54:34 +00:00
|
|
|
rotate = cfg.logrotate.keep;
|
|
|
|
copytruncate = true;
|
|
|
|
compress = true;
|
2021-09-18 10:52:07 +00:00
|
|
|
extraConfig = cfg.logrotate.extraConfig;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
# The postgresql module doesn't currently support concepts like
|
|
|
|
# objects owners and extensions; for now we tack on what's needed
|
|
|
|
# here.
|
2020-08-20 17:08:02 +00:00
|
|
|
systemd.services.gitlab-postgresql = let pgsql = config.services.postgresql; in mkIf databaseActuallyCreateLocally {
|
|
|
|
after = [ "postgresql.service" ];
|
2021-03-09 03:18:52 +00:00
|
|
|
bindsTo = [ "postgresql.service" ];
|
|
|
|
wantedBy = [ "gitlab.target" ];
|
|
|
|
partOf = [ "gitlab.target" ];
|
|
|
|
path = [
|
|
|
|
pgsql.package
|
|
|
|
pkgs.util-linux
|
|
|
|
];
|
2020-08-20 17:08:02 +00:00
|
|
|
script = ''
|
|
|
|
set -eu
|
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
PSQL() {
|
|
|
|
psql --port=${toString pgsql.port} "$@"
|
|
|
|
}
|
2020-08-20 17:08:02 +00:00
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
PSQL -tAc "SELECT 1 FROM pg_database WHERE datname = '${cfg.databaseName}'" | grep -q 1 || PSQL -tAc 'CREATE DATABASE "${cfg.databaseName}" OWNER "${cfg.databaseUsername}"'
|
|
|
|
current_owner=$(PSQL -tAc "SELECT pg_catalog.pg_get_userbyid(datdba) FROM pg_catalog.pg_database WHERE datname = '${cfg.databaseName}'")
|
2020-08-20 17:08:02 +00:00
|
|
|
if [[ "$current_owner" != "${cfg.databaseUsername}" ]]; then
|
2021-03-09 03:18:52 +00:00
|
|
|
PSQL -tAc 'ALTER DATABASE "${cfg.databaseName}" OWNER TO "${cfg.databaseUsername}"'
|
2020-08-20 17:08:02 +00:00
|
|
|
if [[ -e "${config.services.postgresql.dataDir}/.reassigning_${cfg.databaseName}" ]]; then
|
|
|
|
echo "Reassigning ownership of database ${cfg.databaseName} to user ${cfg.databaseUsername} failed on last boot. Failing..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
touch "${config.services.postgresql.dataDir}/.reassigning_${cfg.databaseName}"
|
2021-03-09 03:18:52 +00:00
|
|
|
PSQL "${cfg.databaseName}" -tAc "REASSIGN OWNED BY \"$current_owner\" TO \"${cfg.databaseUsername}\""
|
2020-08-20 17:08:02 +00:00
|
|
|
rm "${config.services.postgresql.dataDir}/.reassigning_${cfg.databaseName}"
|
|
|
|
fi
|
2021-03-09 03:18:52 +00:00
|
|
|
PSQL '${cfg.databaseName}' -tAc "CREATE EXTENSION IF NOT EXISTS pg_trgm"
|
|
|
|
PSQL '${cfg.databaseName}' -tAc "CREATE EXTENSION IF NOT EXISTS btree_gist;"
|
2020-08-20 17:08:02 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
2021-03-09 03:18:52 +00:00
|
|
|
User = pgsql.superUser;
|
2020-08-20 17:08:02 +00:00
|
|
|
Type = "oneshot";
|
2021-03-09 03:18:52 +00:00
|
|
|
RemainAfterExit = true;
|
2020-08-20 17:08:02 +00:00
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-07-14 22:03:04 +00:00
|
|
|
systemd.services.gitlab-registry-cert = optionalAttrs cfg.registry.enable {
|
|
|
|
path = with pkgs; [ openssl ];
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
mkdir -p $(dirname ${cfg.registry.keyFile})
|
|
|
|
mkdir -p $(dirname ${cfg.registry.certFile})
|
|
|
|
openssl req -nodes -newkey rsa:4096 -keyout ${cfg.registry.keyFile} -out /tmp/registry-auth.csr -subj "/CN=${cfg.registry.issuer}"
|
|
|
|
openssl x509 -in /tmp/registry-auth.csr -out ${cfg.registry.certFile} -req -signkey ${cfg.registry.keyFile} -days 3650
|
|
|
|
chown ${cfg.user}:${cfg.group} $(dirname ${cfg.registry.keyFile})
|
|
|
|
chown ${cfg.user}:${cfg.group} $(dirname ${cfg.registry.certFile})
|
|
|
|
chown ${cfg.user}:${cfg.group} ${cfg.registry.keyFile}
|
|
|
|
chown ${cfg.user}:${cfg.group} ${cfg.registry.certFile}
|
|
|
|
'';
|
|
|
|
|
2022-07-14 12:49:19 +00:00
|
|
|
unitConfig = {
|
2021-07-14 22:03:04 +00:00
|
|
|
ConditionPathExists = "!${cfg.registry.certFile}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# Ensure Docker Registry launches after the certificate generation job
|
|
|
|
systemd.services.docker-registry = optionalAttrs cfg.registry.enable {
|
|
|
|
wants = [ "gitlab-registry-cert.service" ];
|
2022-10-21 18:38:19 +00:00
|
|
|
after = [ "gitlab-registry-cert.service" ];
|
2021-07-14 22:03:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
# Enable Docker Registry, if GitLab-Container Registry is enabled
|
|
|
|
services.dockerRegistry = optionalAttrs cfg.registry.enable {
|
|
|
|
enable = true;
|
|
|
|
enableDelete = true; # This must be true, otherwise GitLab won't manage it correctly
|
|
|
|
extraConfig = {
|
|
|
|
auth.token = {
|
|
|
|
realm = "http${if cfg.https == true then "s" else ""}://${cfg.host}/jwt/auth";
|
|
|
|
service = cfg.registry.serviceName;
|
|
|
|
issuer = cfg.registry.issuer;
|
|
|
|
rootcertbundle = cfg.registry.certFile;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
# Use postfix to send out mails.
|
2021-03-09 03:18:52 +00:00
|
|
|
services.postfix.enable = mkDefault (cfg.smtp.enable && cfg.smtp.address == "localhost");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
users.users.${cfg.user} =
|
|
|
|
{ group = cfg.group;
|
|
|
|
home = "${cfg.statePath}/home";
|
|
|
|
shell = "${pkgs.bash}/bin/bash";
|
|
|
|
uid = config.ids.uids.gitlab;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.${cfg.group}.gid = config.ids.gids.gitlab;
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d /run/gitlab 0755 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${gitlabEnv.HOME} 0750 ${cfg.user} ${cfg.group} -"
|
|
|
|
"z ${gitlabEnv.HOME}/.ssh/authorized_keys 0600 ${cfg.user} ${cfg.group} -"
|
2021-04-05 15:23:46 +00:00
|
|
|
"d ${cfg.backup.path} 0750 ${cfg.user} ${cfg.group} -"
|
2020-04-24 23:36:52 +00:00
|
|
|
"d ${cfg.statePath} 0750 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${cfg.statePath}/builds 0750 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${cfg.statePath}/config 0750 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${cfg.statePath}/db 0750 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${cfg.statePath}/log 0750 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${cfg.statePath}/repositories 2770 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${cfg.statePath}/shell 0750 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${cfg.statePath}/tmp 0750 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${cfg.statePath}/tmp/pids 0750 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${cfg.statePath}/tmp/sockets 0750 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${cfg.statePath}/uploads 0700 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${cfg.statePath}/custom_hooks 0700 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${cfg.statePath}/custom_hooks/pre-receive.d 0700 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${cfg.statePath}/custom_hooks/post-receive.d 0700 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${cfg.statePath}/custom_hooks/update.d 0700 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${gitlabConfig.production.shared.path} 0750 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${gitlabConfig.production.shared.path}/artifacts 0750 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${gitlabConfig.production.shared.path}/lfs-objects 0750 ${cfg.user} ${cfg.group} -"
|
2022-01-26 04:04:25 +00:00
|
|
|
"d ${gitlabConfig.production.shared.path}/packages 0750 ${cfg.user} ${cfg.group} -"
|
2020-04-24 23:36:52 +00:00
|
|
|
"d ${gitlabConfig.production.shared.path}/pages 0750 ${cfg.user} ${cfg.group} -"
|
2022-10-21 18:38:19 +00:00
|
|
|
"d ${gitlabConfig.production.shared.path}/registry 0750 ${cfg.user} ${cfg.group} -"
|
2022-01-26 04:04:25 +00:00
|
|
|
"d ${gitlabConfig.production.shared.path}/terraform_state 0750 ${cfg.user} ${cfg.group} -"
|
2020-04-24 23:36:52 +00:00
|
|
|
"L+ /run/gitlab/config - - - - ${cfg.statePath}/config"
|
|
|
|
"L+ /run/gitlab/log - - - - ${cfg.statePath}/log"
|
|
|
|
"L+ /run/gitlab/tmp - - - - ${cfg.statePath}/tmp"
|
|
|
|
"L+ /run/gitlab/uploads - - - - ${cfg.statePath}/uploads"
|
|
|
|
|
|
|
|
"L+ /run/gitlab/shell-config.yml - - - - ${pkgs.writeText "config.yml" (builtins.toJSON gitlabShellConfig)}"
|
|
|
|
];
|
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
|
|
|
|
systemd.services.gitlab-config = {
|
|
|
|
wantedBy = [ "gitlab.target" ];
|
|
|
|
partOf = [ "gitlab.target" ];
|
|
|
|
path = with pkgs; [
|
|
|
|
jq
|
|
|
|
openssl
|
2021-05-20 23:08:51 +00:00
|
|
|
replace-secret
|
2021-03-09 03:18:52 +00:00
|
|
|
git
|
|
|
|
];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
TimeoutSec = "infinity";
|
|
|
|
Restart = "on-failure";
|
|
|
|
WorkingDirectory = "${cfg.packages.gitlab}/share/gitlab";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
|
|
|
|
ExecStartPre = let
|
|
|
|
preStartFullPrivileges = ''
|
2022-02-10 20:34:41 +00:00
|
|
|
set -o errexit -o pipefail -o nounset
|
|
|
|
shopt -s dotglob nullglob inherit_errexit
|
2021-03-09 03:18:52 +00:00
|
|
|
|
|
|
|
chown --no-dereference '${cfg.user}':'${cfg.group}' '${cfg.statePath}'/*
|
|
|
|
if [[ -n "$(ls -A '${cfg.statePath}'/config/)" ]]; then
|
|
|
|
chown --no-dereference '${cfg.user}':'${cfg.group}' '${cfg.statePath}'/config/*
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
in "+${pkgs.writeShellScript "gitlab-pre-start-full-privileges" preStartFullPrivileges}";
|
|
|
|
|
|
|
|
ExecStart = pkgs.writeShellScript "gitlab-config" ''
|
2022-02-10 20:34:41 +00:00
|
|
|
set -o errexit -o pipefail -o nounset
|
|
|
|
shopt -s inherit_errexit
|
2021-03-09 03:18:52 +00:00
|
|
|
|
|
|
|
umask u=rwx,g=rx,o=
|
|
|
|
|
|
|
|
cp -f ${cfg.packages.gitlab}/share/gitlab/VERSION ${cfg.statePath}/VERSION
|
|
|
|
rm -rf ${cfg.statePath}/db/*
|
|
|
|
rm -f ${cfg.statePath}/lib
|
|
|
|
find '${cfg.statePath}/config/' -maxdepth 1 -mindepth 1 -type d -execdir rm -rf {} \;
|
|
|
|
cp -rf --no-preserve=mode ${cfg.packages.gitlab}/share/gitlab/config.dist/* ${cfg.statePath}/config
|
|
|
|
cp -rf --no-preserve=mode ${cfg.packages.gitlab}/share/gitlab/db/* ${cfg.statePath}/db
|
|
|
|
ln -sf ${extraGitlabRb} ${cfg.statePath}/config/initializers/extra-gitlab.rb
|
2022-10-21 18:38:19 +00:00
|
|
|
ln -sf ${cableYml} ${cfg.statePath}/config/cable.yml
|
2021-03-09 03:18:52 +00:00
|
|
|
|
|
|
|
${cfg.packages.gitlab-shell}/bin/install
|
|
|
|
|
|
|
|
${optionalString cfg.smtp.enable ''
|
|
|
|
install -m u=rw ${smtpSettings} ${cfg.statePath}/config/initializers/smtp_settings.rb
|
|
|
|
${optionalString (cfg.smtp.passwordFile != null) ''
|
2021-05-20 23:08:51 +00:00
|
|
|
replace-secret '@smtpPassword@' '${cfg.smtp.passwordFile}' '${cfg.statePath}/config/initializers/smtp_settings.rb'
|
2021-03-09 03:18:52 +00:00
|
|
|
''}
|
|
|
|
''}
|
|
|
|
|
|
|
|
(
|
|
|
|
umask u=rwx,g=,o=
|
|
|
|
|
|
|
|
openssl rand -hex 32 > ${cfg.statePath}/gitlab_shell_secret
|
|
|
|
|
|
|
|
rm -f '${cfg.statePath}/config/database.yml'
|
|
|
|
|
|
|
|
${if cfg.databasePasswordFile != null then ''
|
2022-02-10 20:34:41 +00:00
|
|
|
db_password="$(<'${cfg.databasePasswordFile}')"
|
|
|
|
export db_password
|
2021-03-09 03:18:52 +00:00
|
|
|
|
|
|
|
if [[ -z "$db_password" ]]; then
|
|
|
|
>&2 echo "Database password was an empty string!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
jq <${pkgs.writeText "database.yml" (builtins.toJSON databaseConfig)} \
|
2022-06-16 17:23:12 +00:00
|
|
|
'.${if lib.versionAtLeast (lib.getVersion cfg.packages.gitlab) "15.0" then "production.main" else "production"}.password = $ENV.db_password' \
|
2021-03-09 03:18:52 +00:00
|
|
|
>'${cfg.statePath}/config/database.yml'
|
|
|
|
''
|
|
|
|
else ''
|
|
|
|
jq <${pkgs.writeText "database.yml" (builtins.toJSON databaseConfig)} \
|
|
|
|
>'${cfg.statePath}/config/database.yml'
|
|
|
|
''
|
|
|
|
}
|
|
|
|
|
|
|
|
${utils.genJqSecretsReplacementSnippet
|
|
|
|
gitlabConfig
|
|
|
|
"${cfg.statePath}/config/gitlab.yml"
|
|
|
|
}
|
|
|
|
|
|
|
|
rm -f '${cfg.statePath}/config/secrets.yml'
|
|
|
|
|
2022-02-10 20:34:41 +00:00
|
|
|
secret="$(<'${cfg.secrets.secretFile}')"
|
|
|
|
db="$(<'${cfg.secrets.dbFile}')"
|
|
|
|
otp="$(<'${cfg.secrets.otpFile}')"
|
|
|
|
jws="$(<'${cfg.secrets.jwsFile}')"
|
|
|
|
export secret db otp jws
|
2021-03-09 03:18:52 +00:00
|
|
|
jq -n '{production: {secret_key_base: $ENV.secret,
|
|
|
|
otp_key_base: $ENV.otp,
|
|
|
|
db_key_base: $ENV.db,
|
|
|
|
openid_connect_signing_key: $ENV.jws}}' \
|
|
|
|
> '${cfg.statePath}/config/secrets.yml'
|
|
|
|
)
|
|
|
|
|
|
|
|
# We remove potentially broken links to old gitlab-shell versions
|
|
|
|
rm -Rf ${cfg.statePath}/repositories/**/*.git/hooks
|
|
|
|
|
|
|
|
git config --global core.autocrlf "input"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.gitlab-db-config = {
|
|
|
|
after = [ "gitlab-config.service" "gitlab-postgresql.service" "postgresql.service" ];
|
|
|
|
bindsTo = [
|
|
|
|
"gitlab-config.service"
|
|
|
|
] ++ optional (cfg.databaseHost == "") "postgresql.service"
|
|
|
|
++ optional databaseActuallyCreateLocally "gitlab-postgresql.service";
|
|
|
|
wantedBy = [ "gitlab.target" ];
|
|
|
|
partOf = [ "gitlab.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
TimeoutSec = "infinity";
|
|
|
|
Restart = "on-failure";
|
|
|
|
WorkingDirectory = "${cfg.packages.gitlab}/share/gitlab";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
|
|
|
|
ExecStart = pkgs.writeShellScript "gitlab-db-config" ''
|
2022-02-10 20:34:41 +00:00
|
|
|
set -o errexit -o pipefail -o nounset
|
|
|
|
shopt -s inherit_errexit
|
2021-03-09 03:18:52 +00:00
|
|
|
umask u=rwx,g=rx,o=
|
|
|
|
|
|
|
|
initial_root_password="$(<'${cfg.initialRootPasswordFile}')"
|
|
|
|
${gitlab-rake}/bin/gitlab-rake gitlab:db:configure GITLAB_ROOT_PASSWORD="$initial_root_password" \
|
|
|
|
GITLAB_ROOT_EMAIL='${cfg.initialRootEmail}' > /dev/null
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.services.gitlab-sidekiq = {
|
2021-03-09 03:18:52 +00:00
|
|
|
after = [
|
|
|
|
"network.target"
|
2022-02-20 05:27:41 +00:00
|
|
|
"redis-gitlab.service"
|
2021-03-09 03:18:52 +00:00
|
|
|
"postgresql.service"
|
|
|
|
"gitlab-config.service"
|
|
|
|
"gitlab-db-config.service"
|
|
|
|
];
|
|
|
|
bindsTo = [
|
2022-02-20 05:27:41 +00:00
|
|
|
"redis-gitlab.service"
|
2021-03-09 03:18:52 +00:00
|
|
|
"gitlab-config.service"
|
|
|
|
"gitlab-db-config.service"
|
|
|
|
] ++ optional (cfg.databaseHost == "") "postgresql.service";
|
|
|
|
wantedBy = [ "gitlab.target" ];
|
|
|
|
partOf = [ "gitlab.target" ];
|
2021-05-03 20:48:10 +00:00
|
|
|
environment = gitlabEnv // (optionalAttrs cfg.sidekiq.memoryKiller.enable {
|
|
|
|
SIDEKIQ_MEMORY_KILLER_MAX_RSS = cfg.sidekiq.memoryKiller.maxMemory;
|
|
|
|
SIDEKIQ_MEMORY_KILLER_GRACE_TIME = cfg.sidekiq.memoryKiller.graceTime;
|
|
|
|
SIDEKIQ_MEMORY_KILLER_SHUTDOWN_WAIT = cfg.sidekiq.memoryKiller.shutdownWait;
|
|
|
|
});
|
2020-04-24 23:36:52 +00:00
|
|
|
path = with pkgs; [
|
|
|
|
postgresqlPackage
|
2022-06-26 10:26:21 +00:00
|
|
|
gitPackage
|
2020-04-24 23:36:52 +00:00
|
|
|
ruby
|
|
|
|
openssh
|
|
|
|
nodejs
|
|
|
|
gnupg
|
|
|
|
|
|
|
|
# Needed for GitLab project imports
|
|
|
|
gnutar
|
|
|
|
gzip
|
2021-05-03 20:48:10 +00:00
|
|
|
|
|
|
|
procps # Sidekiq MemoryKiller
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
TimeoutSec = "infinity";
|
2021-05-03 20:48:10 +00:00
|
|
|
Restart = "always";
|
2020-04-24 23:36:52 +00:00
|
|
|
WorkingDirectory = "${cfg.packages.gitlab}/share/gitlab";
|
2020-08-20 17:08:02 +00:00
|
|
|
ExecStart="${cfg.packages.gitlab.rubyEnv}/bin/sidekiq -C \"${cfg.packages.gitlab}/share/gitlab/config/sidekiq_queues.yml\" -e production";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.gitaly = {
|
2021-03-09 03:18:52 +00:00
|
|
|
after = [ "network.target" "gitlab-config.service" ];
|
|
|
|
bindsTo = [ "gitlab-config.service" ];
|
|
|
|
wantedBy = [ "gitlab.target" ];
|
|
|
|
partOf = [ "gitlab.target" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
path = with pkgs; [
|
|
|
|
openssh
|
|
|
|
procps # See https://gitlab.com/gitlab-org/gitaly/issues/1562
|
2022-06-26 10:26:21 +00:00
|
|
|
gitPackage
|
2020-04-24 23:36:52 +00:00
|
|
|
cfg.packages.gitaly.rubyEnv
|
|
|
|
cfg.packages.gitaly.rubyEnv.wrappedRuby
|
|
|
|
gzip
|
|
|
|
bzip2
|
|
|
|
];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
TimeoutSec = "infinity";
|
|
|
|
Restart = "on-failure";
|
|
|
|
WorkingDirectory = gitlabEnv.HOME;
|
|
|
|
ExecStart = "${cfg.packages.gitaly}/bin/gitaly ${gitalyToml}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-10-16 20:44:37 +00:00
|
|
|
systemd.services.gitlab-pages = mkIf (gitlabConfig.production.pages.enabled or false) {
|
|
|
|
description = "GitLab static pages daemon";
|
2021-03-09 03:18:52 +00:00
|
|
|
after = [ "network.target" "gitlab-config.service" ];
|
|
|
|
bindsTo = [ "gitlab-config.service" ];
|
|
|
|
wantedBy = [ "gitlab.target" ];
|
|
|
|
partOf = [ "gitlab.target" ];
|
2020-10-16 20:44:37 +00:00
|
|
|
|
|
|
|
path = [ pkgs.unzip ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
TimeoutSec = "infinity";
|
|
|
|
Restart = "on-failure";
|
|
|
|
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
|
|
|
|
ExecStart = "${cfg.packages.pages}/bin/gitlab-pages ${escapeShellArgs pagesArgs}";
|
|
|
|
WorkingDirectory = gitlabEnv.HOME;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.services.gitlab-workhorse = {
|
|
|
|
after = [ "network.target" ];
|
2021-03-09 03:18:52 +00:00
|
|
|
wantedBy = [ "gitlab.target" ];
|
|
|
|
partOf = [ "gitlab.target" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
path = with pkgs; [
|
2022-10-21 18:38:19 +00:00
|
|
|
remarshal
|
2020-04-24 23:36:52 +00:00
|
|
|
exiftool
|
2022-06-26 10:26:21 +00:00
|
|
|
gitPackage
|
2020-04-24 23:36:52 +00:00
|
|
|
gnutar
|
|
|
|
gzip
|
|
|
|
openssh
|
|
|
|
gitlab-workhorse
|
|
|
|
];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
TimeoutSec = "infinity";
|
|
|
|
Restart = "on-failure";
|
|
|
|
WorkingDirectory = gitlabEnv.HOME;
|
2022-10-21 18:38:19 +00:00
|
|
|
ExecStartPre = pkgs.writeShellScript "gitlab-workhorse-pre-start" ''
|
|
|
|
set -o errexit -o pipefail -o nounset
|
|
|
|
shopt -s dotglob nullglob inherit_errexit
|
|
|
|
|
|
|
|
${utils.genJqSecretsReplacementSnippet
|
|
|
|
cfg.workhorse.config
|
|
|
|
"${cfg.statePath}/config/gitlab-workhorse.json"}
|
|
|
|
|
|
|
|
json2toml "${cfg.statePath}/config/gitlab-workhorse.json" "${cfg.statePath}/config/gitlab-workhorse.toml"
|
|
|
|
rm "${cfg.statePath}/config/gitlab-workhorse.json"
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
ExecStart =
|
2021-09-18 10:52:07 +00:00
|
|
|
"${cfg.packages.gitlab-workhorse}/bin/workhorse "
|
2020-04-24 23:36:52 +00:00
|
|
|
+ "-listenUmask 0 "
|
|
|
|
+ "-listenNetwork unix "
|
|
|
|
+ "-listenAddr /run/gitlab/gitlab-workhorse.socket "
|
|
|
|
+ "-authSocket ${gitlabSocket} "
|
|
|
|
+ "-documentRoot ${cfg.packages.gitlab}/share/gitlab/public "
|
2022-10-21 18:38:19 +00:00
|
|
|
+ "-config ${cfg.statePath}/config/gitlab-workhorse.toml "
|
2020-04-24 23:36:52 +00:00
|
|
|
+ "-secretPath ${cfg.statePath}/.gitlab_workhorse_secret";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
systemd.services.gitlab-mailroom = mkIf (gitlabConfig.production.incoming_email.enabled or false) {
|
|
|
|
description = "GitLab incoming mail daemon";
|
2022-02-20 05:27:41 +00:00
|
|
|
after = [ "network.target" "redis-gitlab.service" "gitlab-config.service" ];
|
2021-03-09 03:18:52 +00:00
|
|
|
bindsTo = [ "gitlab-config.service" ];
|
|
|
|
wantedBy = [ "gitlab.target" ];
|
|
|
|
partOf = [ "gitlab.target" ];
|
2020-09-25 04:45:31 +00:00
|
|
|
environment = gitlabEnv;
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
TimeoutSec = "infinity";
|
|
|
|
Restart = "on-failure";
|
|
|
|
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2021-03-09 03:18:52 +00:00
|
|
|
ExecStart = "${cfg.packages.gitlab.rubyEnv}/bin/bundle exec mail_room -c ${cfg.statePath}/config/mail_room.yml";
|
2020-09-25 04:45:31 +00:00
|
|
|
WorkingDirectory = gitlabEnv.HOME;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.services.gitlab = {
|
2021-03-09 03:18:52 +00:00
|
|
|
after = [
|
|
|
|
"gitlab-workhorse.service"
|
|
|
|
"network.target"
|
2022-02-20 05:27:41 +00:00
|
|
|
"redis-gitlab.service"
|
2021-03-09 03:18:52 +00:00
|
|
|
"gitlab-config.service"
|
|
|
|
"gitlab-db-config.service"
|
|
|
|
];
|
|
|
|
bindsTo = [
|
2022-02-20 05:27:41 +00:00
|
|
|
"redis-gitlab.service"
|
2021-03-09 03:18:52 +00:00
|
|
|
"gitlab-config.service"
|
|
|
|
"gitlab-db-config.service"
|
|
|
|
] ++ optional (cfg.databaseHost == "") "postgresql.service";
|
|
|
|
wantedBy = [ "gitlab.target" ];
|
|
|
|
partOf = [ "gitlab.target" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
environment = gitlabEnv;
|
|
|
|
path = with pkgs; [
|
|
|
|
postgresqlPackage
|
2022-06-26 10:26:21 +00:00
|
|
|
gitPackage
|
2020-04-24 23:36:52 +00:00
|
|
|
openssh
|
|
|
|
nodejs
|
|
|
|
procps
|
|
|
|
gnupg
|
|
|
|
];
|
|
|
|
serviceConfig = {
|
2021-09-18 10:52:07 +00:00
|
|
|
Type = "notify";
|
2020-04-24 23:36:52 +00:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
TimeoutSec = "infinity";
|
|
|
|
Restart = "on-failure";
|
|
|
|
WorkingDirectory = "${cfg.packages.gitlab}/share/gitlab";
|
2021-05-03 20:48:10 +00:00
|
|
|
ExecStart = concatStringsSep " " [
|
|
|
|
"${cfg.packages.gitlab.rubyEnv}/bin/puma"
|
|
|
|
"-e production"
|
|
|
|
"-C ${cfg.statePath}/config/puma.rb"
|
|
|
|
"-w ${cfg.puma.workers}"
|
|
|
|
"-t ${cfg.puma.threadsMin}:${cfg.puma.threadsMax}"
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-04-05 15:23:46 +00:00
|
|
|
systemd.services.gitlab-backup = {
|
|
|
|
after = [ "gitlab.service" ];
|
|
|
|
bindsTo = [ "gitlab.service" ];
|
|
|
|
startAt = cfg.backup.startAt;
|
|
|
|
environment = {
|
|
|
|
RAILS_ENV = "production";
|
|
|
|
CRON = "1";
|
|
|
|
} // optionalAttrs (stringLength cfg.backup.skip > 0) {
|
|
|
|
SKIP = cfg.backup.skip;
|
|
|
|
};
|
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
ExecStart = "${gitlab-rake}/bin/gitlab-rake gitlab:backup:create";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
meta.doc = ./gitlab.xml;
|
|
|
|
|
|
|
|
}
|