2014-10-25 16:22:49 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
# TODO: support non-postgresql
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.gitlab;
|
|
|
|
|
2016-02-26 07:55:25 +00:00
|
|
|
ruby = cfg.packages.gitlab.ruby;
|
2014-10-25 16:22:49 +00:00
|
|
|
|
2016-02-26 06:06:07 +00:00
|
|
|
gitlabSocket = "${cfg.statePath}/tmp/sockets/gitlab.socket";
|
2017-07-05 21:53:31 +00:00
|
|
|
gitalySocket = "${cfg.statePath}/tmp/sockets/gitaly.socket";
|
2016-02-26 06:06:07 +00:00
|
|
|
pathUrlQuote = url: replaceStrings ["/"] ["%2F"] url;
|
2017-09-02 21:16:02 +00:00
|
|
|
pgSuperUser = config.services.postgresql.superUser;
|
2016-02-26 06:06:07 +00:00
|
|
|
|
2018-11-02 20:22:51 +00:00
|
|
|
databaseConfig = {
|
|
|
|
production = {
|
|
|
|
adapter = "postgresql";
|
|
|
|
database = cfg.databaseName;
|
|
|
|
host = cfg.databaseHost;
|
|
|
|
password = cfg.databasePassword;
|
|
|
|
username = cfg.databaseUsername;
|
|
|
|
encoding = "utf8";
|
2019-02-06 23:45:28 +00:00
|
|
|
pool = cfg.databasePool;
|
|
|
|
} // cfg.extraDatabaseConfig;
|
2018-11-02 20:22:51 +00:00
|
|
|
};
|
2016-01-30 13:47:04 +00:00
|
|
|
|
2017-07-05 21:53:31 +00:00
|
|
|
gitalyToml = pkgs.writeText "gitaly.toml" ''
|
|
|
|
socket_path = "${lib.escape ["\""] gitalySocket}"
|
2018-01-07 01:04:49 +00:00
|
|
|
bin_dir = "${cfg.packages.gitaly}/bin"
|
2017-09-03 13:38:28 +00:00
|
|
|
prometheus_listen_addr = "localhost:9236"
|
|
|
|
|
2018-01-07 01:04:49 +00:00
|
|
|
[git]
|
|
|
|
bin_path = "${pkgs.git}/bin/git"
|
|
|
|
|
2017-09-03 13:38:28 +00:00
|
|
|
[gitaly-ruby]
|
|
|
|
dir = "${cfg.packages.gitaly.ruby}"
|
|
|
|
|
|
|
|
[gitlab-shell]
|
|
|
|
dir = "${cfg.packages.gitlab-shell}"
|
2017-07-05 21:53:31 +00:00
|
|
|
|
|
|
|
${concatStringsSep "\n" (attrValues (mapAttrs (k: v: ''
|
|
|
|
[[storage]]
|
|
|
|
name = "${lib.escape ["\""] k}"
|
|
|
|
path = "${lib.escape ["\""] v.path}"
|
|
|
|
'') gitlabConfig.production.repositories.storages))}
|
|
|
|
'';
|
|
|
|
|
2018-11-02 20:22:51 +00:00
|
|
|
gitlabShellConfig = {
|
|
|
|
user = cfg.user;
|
|
|
|
gitlab_url = "http+unix://${pathUrlQuote gitlabSocket}";
|
|
|
|
http_settings.self_signed_cert = false;
|
|
|
|
repos_path = "${cfg.statePath}/repositories";
|
2019-07-16 01:42:45 +00:00
|
|
|
secret_file = "${cfg.statePath}/gitlab_shell_secret";
|
2018-11-02 20:22:51 +00:00
|
|
|
log_file = "${cfg.statePath}/log/gitlab-shell.log";
|
|
|
|
custom_hooks_dir = "${cfg.statePath}/custom_hooks";
|
|
|
|
redis = {
|
|
|
|
bin = "${pkgs.redis}/bin/redis-cli";
|
|
|
|
host = "127.0.0.1";
|
|
|
|
port = 6379;
|
|
|
|
database = 0;
|
|
|
|
namespace = "resque:gitlab";
|
|
|
|
};
|
|
|
|
};
|
2014-10-25 16:22:49 +00:00
|
|
|
|
2018-11-02 20:22:51 +00:00
|
|
|
redisConfig.production.url = "redis://localhost:6379/";
|
2017-09-03 13:38:28 +00:00
|
|
|
|
2018-11-02 20:22:51 +00:00
|
|
|
secretsConfig.production = {
|
|
|
|
secret_key_base = cfg.secrets.secret;
|
|
|
|
otp_key_base = cfg.secrets.otp;
|
|
|
|
db_key_base = cfg.secrets.db;
|
|
|
|
openid_connect_signing_key = cfg.secrets.jws;
|
|
|
|
};
|
2016-08-17 11:16:32 +00:00
|
|
|
|
2016-01-30 13:47:04 +00:00
|
|
|
gitlabConfig = {
|
2016-02-23 21:55:35 +00:00
|
|
|
# These are the default settings from config/gitlab.example.yml
|
2016-01-30 13:47:04 +00:00
|
|
|
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;
|
2016-02-23 21:55:35 +00:00
|
|
|
wiki = true;
|
2016-08-03 16:49:18 +00:00
|
|
|
snippets = true;
|
2016-01-30 13:47:04 +00:00
|
|
|
builds = true;
|
2016-08-03 16:49:18 +00:00
|
|
|
container_registry = true;
|
2016-01-30 13:47:04 +00:00
|
|
|
};
|
|
|
|
};
|
2017-07-05 21:53:31 +00:00
|
|
|
repositories.storages.default.path = "${cfg.statePath}/repositories";
|
|
|
|
repositories.storages.default.gitaly_address = "unix:${gitalySocket}";
|
2016-08-03 16:49:18 +00:00
|
|
|
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";
|
2018-01-07 03:59:56 +00:00
|
|
|
gitaly.client_path = "${cfg.packages.gitaly}/bin";
|
2016-08-03 16:49:18 +00:00
|
|
|
backup.path = "${cfg.backupPath}";
|
2016-01-30 13:47:04 +00:00
|
|
|
gitlab_shell = {
|
2016-02-26 07:55:25 +00:00
|
|
|
path = "${cfg.packages.gitlab-shell}";
|
2016-01-30 13:47:04 +00:00
|
|
|
hooks_path = "${cfg.statePath}/shell/hooks";
|
2019-07-16 01:42:45 +00:00
|
|
|
secret_file = "${cfg.statePath}/gitlab_shell_secret";
|
2016-01-30 13:47:04 +00:00
|
|
|
upload_pack = true;
|
|
|
|
receive_pack = true;
|
|
|
|
};
|
2018-11-02 20:22:51 +00:00
|
|
|
workhorse.secret_file = "${cfg.statePath}/.gitlab_workhorse_secret";
|
|
|
|
git.bin_path = "git";
|
2017-09-03 13:38:28 +00:00
|
|
|
monitoring = {
|
|
|
|
ip_whitelist = [ "127.0.0.0/8" "::1/128" ];
|
|
|
|
sidekiq_exporter = {
|
|
|
|
enable = true;
|
|
|
|
address = "localhost";
|
|
|
|
port = 3807;
|
|
|
|
};
|
|
|
|
};
|
2016-01-30 13:47:04 +00:00
|
|
|
extra = {};
|
2018-05-23 20:24:24 +00:00
|
|
|
uploads.storage_path = cfg.statePath;
|
2016-01-30 13:47:04 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
gitlabEnv = {
|
|
|
|
HOME = "${cfg.statePath}/home";
|
|
|
|
UNICORN_PATH = "${cfg.statePath}/";
|
2016-02-26 07:55:25 +00:00
|
|
|
GITLAB_PATH = "${cfg.packages.gitlab}/share/gitlab/";
|
2018-03-14 13:14:03 +00:00
|
|
|
SCHEMA = "${cfg.statePath}/db/schema.rb";
|
2019-07-16 01:42:45 +00:00
|
|
|
GITLAB_UPLOADS_PATH = "${cfg.statePath}/uploads";
|
2016-01-30 13:47:04 +00:00
|
|
|
GITLAB_LOG_PATH = "${cfg.statePath}/log";
|
2018-11-02 20:22:51 +00:00
|
|
|
GITLAB_REDIS_CONFIG_FILE = pkgs.writeText "redis.yml" (builtins.toJSON redisConfig);
|
2017-09-03 13:38:28 +00:00
|
|
|
prometheus_multiproc_dir = "/run/gitlab";
|
2016-01-30 13:47:04 +00:00
|
|
|
RAILS_ENV = "production";
|
|
|
|
};
|
|
|
|
|
2016-08-04 00:08:26 +00:00
|
|
|
gitlab-rake = pkgs.stdenv.mkDerivation rec {
|
|
|
|
name = "gitlab-rake";
|
2018-04-25 17:58:05 +00:00
|
|
|
buildInputs = [ pkgs.makeWrapper ];
|
|
|
|
dontBuild = true;
|
2019-06-19 15:45:34 +00:00
|
|
|
dontUnpack = true;
|
2014-10-25 16:22:49 +00:00
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
2018-04-25 17:58:05 +00:00
|
|
|
makeWrapper ${cfg.packages.gitlab.rubyEnv}/bin/rake $out/bin/gitlab-rake \
|
2016-08-03 16:49:18 +00:00
|
|
|
${concatStrings (mapAttrsToList (name: value: "--set ${name} '${value}' ") gitlabEnv)} \
|
2018-09-21 07:41:38 +00:00
|
|
|
--set PATH '${lib.makeBinPath [ pkgs.nodejs pkgs.gzip pkgs.git pkgs.gnutar config.services.postgresql.package pkgs.coreutils pkgs.procps ]}:$PATH' \
|
2016-08-03 16:49:18 +00:00
|
|
|
--set RAKEOPT '-f ${cfg.packages.gitlab}/share/gitlab/Rakefile' \
|
|
|
|
--run 'cd ${cfg.packages.gitlab}/share/gitlab'
|
2016-08-04 00:08:26 +00:00
|
|
|
'';
|
2014-10-25 16:22:49 +00:00
|
|
|
};
|
|
|
|
|
2019-03-25 16:17:56 +00:00
|
|
|
gitlab-rails = pkgs.stdenv.mkDerivation rec {
|
|
|
|
name = "gitlab-rails";
|
|
|
|
buildInputs = [ pkgs.makeWrapper ];
|
|
|
|
dontBuild = true;
|
2019-06-19 15:45:34 +00:00
|
|
|
dontUnpack = true;
|
2019-03-25 16:17:56 +00:00
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
makeWrapper ${cfg.packages.gitlab.rubyEnv}/bin/rails $out/bin/gitlab-rails \
|
|
|
|
${concatStrings (mapAttrsToList (name: value: "--set ${name} '${value}' ") gitlabEnv)} \
|
|
|
|
--set PATH '${lib.makeBinPath [ pkgs.nodejs pkgs.gzip pkgs.git pkgs.gnutar config.services.postgresql.package pkgs.coreutils pkgs.procps ]}:$PATH' \
|
|
|
|
--run 'cd ${cfg.packages.gitlab}/share/gitlab'
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-03-13 11:57:20 +00:00
|
|
|
extraGitlabRb = pkgs.writeText "extra-gitlab.rb" cfg.extraGitlabRb;
|
|
|
|
|
2016-08-03 16:49:18 +00:00
|
|
|
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.password != null) ''password: "${cfg.smtp.password}",''}
|
|
|
|
domain: "${cfg.smtp.domain}",
|
|
|
|
${optionalString (cfg.smtp.authentication != null) "authentication: :${cfg.smtp.authentication},"}
|
|
|
|
enable_starttls_auto: ${toString cfg.smtp.enableStartTLSAuto},
|
|
|
|
openssl_verify_mode: '${cfg.smtp.opensslVerifyMode}'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
|
2014-10-25 16:22:49 +00:00
|
|
|
in {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.gitlab = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable the gitlab service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-02-26 07:55:25 +00:00
|
|
|
packages.gitlab = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.gitlab;
|
2016-11-21 15:26:03 +00:00
|
|
|
defaultText = "pkgs.gitlab";
|
2016-02-26 07:55:25 +00:00
|
|
|
description = "Reference to the gitlab package";
|
2018-09-21 07:41:38 +00:00
|
|
|
example = "pkgs.gitlab-ee";
|
2016-02-26 07:55:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
packages.gitlab-shell = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.gitlab-shell;
|
2016-11-21 15:26:03 +00:00
|
|
|
defaultText = "pkgs.gitlab-shell";
|
2016-02-26 07:55:25 +00:00
|
|
|
description = "Reference to the gitlab-shell package";
|
|
|
|
};
|
|
|
|
|
|
|
|
packages.gitlab-workhorse = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.gitlab-workhorse;
|
2016-11-21 15:26:03 +00:00
|
|
|
defaultText = "pkgs.gitlab-workhorse";
|
2016-02-26 07:55:25 +00:00
|
|
|
description = "Reference to the gitlab-workhorse package";
|
|
|
|
};
|
|
|
|
|
2017-07-05 21:53:31 +00:00
|
|
|
packages.gitaly = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.gitaly;
|
|
|
|
defaultText = "pkgs.gitaly";
|
|
|
|
description = "Reference to the gitaly package";
|
|
|
|
};
|
|
|
|
|
2016-01-30 13:47:04 +00:00
|
|
|
statePath = mkOption {
|
2014-10-25 16:22:49 +00:00
|
|
|
type = types.str;
|
|
|
|
default = "/var/gitlab/state";
|
2014-11-29 23:56:22 +00:00
|
|
|
description = "Gitlab state directory, logs are stored here.";
|
2014-10-25 16:22:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
backupPath = mkOption {
|
|
|
|
type = types.str;
|
2016-01-30 13:47:04 +00:00
|
|
|
default = cfg.statePath + "/backup";
|
2014-11-29 23:56:22 +00:00
|
|
|
description = "Gitlab path for backups.";
|
2014-10-25 16:22:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
databaseHost = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
2014-11-29 23:56:22 +00:00
|
|
|
description = "Gitlab database hostname.";
|
2014-10-25 16:22:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
databasePassword = mkOption {
|
|
|
|
type = types.str;
|
2014-11-29 23:56:22 +00:00
|
|
|
description = "Gitlab database user password.";
|
2014-10-25 16:22:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
databaseName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "gitlab";
|
2014-11-29 23:56:22 +00:00
|
|
|
description = "Gitlab database name.";
|
2014-10-25 16:22:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
databaseUsername = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "gitlab";
|
2014-11-29 23:56:22 +00:00
|
|
|
description = "Gitlab database user.";
|
2014-10-25 16:22:49 +00:00
|
|
|
};
|
|
|
|
|
2019-02-06 23:45:28 +00:00
|
|
|
databasePool = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 5;
|
|
|
|
description = "Database connection pool size.";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraDatabaseConfig = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = {};
|
|
|
|
description = "Extra configuration in config/database.yml.";
|
|
|
|
};
|
2014-10-25 16:22:49 +00:00
|
|
|
|
2019-03-13 11:57:20 +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
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-10-25 16:22:49 +00:00
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = config.networking.hostName;
|
2014-11-29 23:56:22 +00:00
|
|
|
description = "Gitlab host name. Used e.g. for copy-paste URLs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 8080;
|
2016-01-30 13:47:04 +00:00
|
|
|
description = ''
|
|
|
|
Gitlab server port for copy-paste URLs, e.g. 80 or 443 if you're
|
|
|
|
service over https.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
https = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Whether gitlab prints URLs with https as scheme.";
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "gitlab";
|
|
|
|
description = "User to run gitlab and all related services.";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "gitlab";
|
|
|
|
description = "Group to run gitlab and all related services.";
|
|
|
|
};
|
|
|
|
|
|
|
|
initialRootEmail = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "admin@local.host";
|
|
|
|
description = ''
|
|
|
|
Initial email address of the root account if this is a new install.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
initialRootPassword = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
Initial password of the root account if this is a new install.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-08-03 16:49:18 +00:00
|
|
|
smtp = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Enable gitlab mail delivery over SMTP.";
|
|
|
|
};
|
|
|
|
|
|
|
|
address = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
|
|
|
description = "Address of the SMTP server for Gitlab.";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 465;
|
|
|
|
description = "Port of the SMTP server for Gitlab.";
|
|
|
|
};
|
|
|
|
|
|
|
|
username = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = "Username of the SMTP server for Gitlab.";
|
|
|
|
};
|
|
|
|
|
|
|
|
password = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = "Password of the SMTP server for Gitlab.";
|
|
|
|
};
|
|
|
|
|
|
|
|
domain = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
|
|
|
description = "HELO domain to use for outgoing mail.";
|
|
|
|
};
|
|
|
|
|
|
|
|
authentication = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = "Authentitcation type to use, see http://api.rubyonrails.org/classes/ActionMailer/Base.html";
|
|
|
|
};
|
|
|
|
|
|
|
|
enableStartTLSAuto = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "Whether to try to use StartTLS.";
|
|
|
|
};
|
|
|
|
|
|
|
|
opensslVerifyMode = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "peer";
|
|
|
|
description = "How OpenSSL checks the certificate, see http://api.rubyonrails.org/classes/ActionMailer/Base.html";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-08-26 12:08:53 +00:00
|
|
|
secrets.secret = mkOption {
|
2016-08-17 11:16:32 +00:00
|
|
|
type = types.str;
|
|
|
|
description = ''
|
2016-08-26 12:08:53 +00:00
|
|
|
The secret is used to encrypt variables in the DB. If
|
2016-08-17 11:16:32 +00:00
|
|
|
you change or lose this key you will be unable to access variables
|
|
|
|
stored in database.
|
|
|
|
|
|
|
|
Make sure the secret is at least 30 characters and all random,
|
|
|
|
no regular words or you'll be exposed to dictionary attacks.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-08-26 12:08:53 +00:00
|
|
|
secrets.db = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
The secret is used to encrypt variables in the DB. If
|
|
|
|
you change or lose this key you will be unable to access variables
|
|
|
|
stored in database.
|
|
|
|
|
|
|
|
Make sure the secret is at least 30 characters and all random,
|
|
|
|
no regular words or you'll be exposed to dictionary attacks.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
secrets.otp = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
The secret is 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.
|
|
|
|
|
|
|
|
Make sure the secret is at least 30 characters and all random,
|
|
|
|
no regular words or you'll be exposed to dictionary attacks.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-07-05 21:53:31 +00:00
|
|
|
secrets.jws = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
The secret is 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
|
|
|
|
|
2017-10-03 14:09:30 +00:00
|
|
|
openssl genrsa 2048
|
2017-07-05 21:53:31 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-01-30 13:47:04 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.attrs;
|
2016-02-23 21:55:35 +00:00
|
|
|
default = {};
|
2016-01-30 13:47:04 +00:00
|
|
|
example = {
|
|
|
|
gitlab = {
|
|
|
|
default_projects_features = {
|
|
|
|
builds = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
description = ''
|
|
|
|
Extra options to be merged into config/gitlab.yml as nix
|
|
|
|
attribute set.
|
|
|
|
'';
|
2014-10-25 16:22:49 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2019-03-25 16:17:56 +00:00
|
|
|
environment.systemPackages = [ pkgs.git gitlab-rake gitlab-rails cfg.packages.gitlab-shell ];
|
2014-10-25 16:22:49 +00:00
|
|
|
|
|
|
|
# Redis is required for the sidekiq queue runner.
|
|
|
|
services.redis.enable = mkDefault true;
|
|
|
|
# We use postgres as the main data store.
|
|
|
|
services.postgresql.enable = mkDefault true;
|
|
|
|
# Use postfix to send out mails.
|
|
|
|
services.postfix.enable = mkDefault true;
|
|
|
|
|
2018-06-29 23:58:35 +00:00
|
|
|
users.users = [
|
2016-01-30 13:47:04 +00:00
|
|
|
{ name = cfg.user;
|
|
|
|
group = cfg.group;
|
|
|
|
home = "${cfg.statePath}/home";
|
2014-10-25 16:22:49 +00:00
|
|
|
shell = "${pkgs.bash}/bin/bash";
|
|
|
|
uid = config.ids.uids.gitlab;
|
2016-01-30 13:47:04 +00:00
|
|
|
}
|
|
|
|
];
|
2014-10-25 16:22:49 +00:00
|
|
|
|
2018-06-29 23:58:35 +00:00
|
|
|
users.groups = [
|
2016-01-30 13:47:04 +00:00
|
|
|
{ name = cfg.group;
|
2014-10-25 16:22:49 +00:00
|
|
|
gid = config.ids.gids.gitlab;
|
2016-01-30 13:47:04 +00:00
|
|
|
}
|
|
|
|
];
|
2014-10-25 16:22:49 +00:00
|
|
|
|
2018-11-02 20:22:51 +00:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d /run/gitlab 0755 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${gitlabEnv.HOME} 0750 ${cfg.user} ${cfg.group} -"
|
2019-07-16 01:48:13 +00:00
|
|
|
"z ${gitlabEnv.HOME}/.ssh/authorized_keys 0600 ${cfg.user} ${cfg.group} -"
|
2018-11-02 20:22:51 +00:00
|
|
|
"d ${cfg.backupPath} 0750 ${cfg.user} ${cfg.group} -"
|
2019-07-15 23:19:07 +00:00
|
|
|
"d ${cfg.statePath} 0750 ${cfg.user} ${cfg.group} -"
|
2018-11-02 20:22:51 +00:00
|
|
|
"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} -"
|
2019-07-15 23:19:07 +00:00
|
|
|
"d ${cfg.statePath}/tmp 0750 ${cfg.user} ${cfg.group} -"
|
2018-11-02 20:22:51 +00:00
|
|
|
"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} -"
|
2019-07-15 23:19:07 +00:00
|
|
|
"d ${cfg.statePath}/custom_hooks 0700 ${cfg.user} ${cfg.group} -"
|
2018-11-02 20:22:51 +00:00
|
|
|
"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} -"
|
2019-07-15 23:19:07 +00:00
|
|
|
"d ${gitlabConfig.production.shared.path} 0750 ${cfg.user} ${cfg.group} -"
|
2018-11-02 20:22:51 +00:00
|
|
|
"d ${gitlabConfig.production.shared.path}/artifacts 0750 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${gitlabConfig.production.shared.path}/lfs-objects 0750 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d ${gitlabConfig.production.shared.path}/pages 0750 ${cfg.user} ${cfg.group} -"
|
2019-07-15 23:19:07 +00:00
|
|
|
"L+ ${cfg.statePath}/lib - - - - ${cfg.packages.gitlab}/share/gitlab/lib"
|
|
|
|
"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)}"
|
|
|
|
|
|
|
|
"L+ ${cfg.statePath}/config/gitlab.yml - - - - ${pkgs.writeText "gitlab.yml" (builtins.toJSON gitlabConfig)}"
|
|
|
|
"L+ ${cfg.statePath}/config/database.yml - - - - ${pkgs.writeText "database.yml" (builtins.toJSON databaseConfig)}"
|
|
|
|
"L+ ${cfg.statePath}/config/secrets.yml - - - - ${pkgs.writeText "secrets.yml" (builtins.toJSON secretsConfig)}"
|
|
|
|
"L+ ${cfg.statePath}/config/unicorn.rb - - - - ${./defaultUnicornConfig.rb}"
|
|
|
|
|
|
|
|
"L+ ${cfg.statePath}/config/initializers/extra-gitlab.rb - - - - ${extraGitlabRb}"
|
|
|
|
] ++ optional cfg.smtp.enable
|
|
|
|
"L+ ${cfg.statePath}/config/initializers/smtp_settings.rb - - - - ${smtpSettings}" ;
|
2018-11-02 20:22:51 +00:00
|
|
|
|
2014-10-25 16:22:49 +00:00
|
|
|
systemd.services.gitlab-sidekiq = {
|
2018-11-02 20:22:51 +00:00
|
|
|
after = [ "network.target" "redis.service" "gitlab.service" ];
|
2014-10-25 16:22:49 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-01-30 13:47:04 +00:00
|
|
|
environment = gitlabEnv;
|
2014-10-25 16:22:49 +00:00
|
|
|
path = with pkgs; [
|
|
|
|
config.services.postgresql.package
|
|
|
|
gitAndTools.git
|
|
|
|
ruby
|
|
|
|
openssh
|
2014-12-14 01:24:12 +00:00
|
|
|
nodejs
|
2017-09-03 13:38:28 +00:00
|
|
|
gnupg
|
2014-10-25 16:22:49 +00:00
|
|
|
];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
2016-01-30 13:47:04 +00:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2018-04-25 17:58:05 +00:00
|
|
|
TimeoutSec = "infinity";
|
2016-08-12 17:17:43 +00:00
|
|
|
Restart = "on-failure";
|
2016-02-26 07:55:25 +00:00
|
|
|
WorkingDirectory = "${cfg.packages.gitlab}/share/gitlab";
|
2018-04-25 17:58:05 +00:00
|
|
|
ExecStart="${cfg.packages.gitlab.rubyEnv}/bin/sidekiq -C \"${cfg.packages.gitlab}/share/gitlab/config/sidekiq_queues.yml\" -e production -P ${cfg.statePath}/tmp/sidekiq.pid";
|
2017-07-05 21:53:31 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.gitaly = {
|
2018-11-02 20:22:51 +00:00
|
|
|
after = [ "network.target" ];
|
2017-07-05 21:53:31 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2019-01-30 19:29:32 +00:00
|
|
|
path = with pkgs; [
|
|
|
|
openssh
|
2019-03-28 14:46:22 +00:00
|
|
|
procps # See https://gitlab.com/gitlab-org/gitaly/issues/1562
|
2019-01-30 19:29:32 +00:00
|
|
|
gitAndTools.git
|
|
|
|
cfg.packages.gitaly.rubyEnv
|
|
|
|
cfg.packages.gitaly.rubyEnv.wrappedRuby
|
2019-03-10 22:04:27 +00:00
|
|
|
gzip
|
|
|
|
bzip2
|
2019-01-30 19:29:32 +00:00
|
|
|
];
|
2017-07-05 21:53:31 +00:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2018-03-19 20:52:36 +00:00
|
|
|
TimeoutSec = "infinity";
|
2017-07-05 21:53:31 +00:00
|
|
|
Restart = "on-failure";
|
|
|
|
WorkingDirectory = gitlabEnv.HOME;
|
|
|
|
ExecStart = "${cfg.packages.gitaly}/bin/gitaly ${gitalyToml}";
|
2014-10-25 16:22:49 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-01-30 13:47:04 +00:00
|
|
|
systemd.services.gitlab-workhorse = {
|
2018-07-30 19:49:18 +00:00
|
|
|
after = [ "network.target" ];
|
2015-10-21 17:48:56 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = with pkgs; [
|
|
|
|
gitAndTools.git
|
2017-07-19 19:34:17 +00:00
|
|
|
gnutar
|
|
|
|
gzip
|
2015-10-21 17:48:56 +00:00
|
|
|
openssh
|
2017-05-12 06:52:33 +00:00
|
|
|
gitlab-workhorse
|
2015-10-21 17:48:56 +00:00
|
|
|
];
|
|
|
|
serviceConfig = {
|
2016-01-30 13:47:04 +00:00
|
|
|
PermissionsStartOnly = true; # preStart must be run as root
|
2015-10-21 17:48:56 +00:00
|
|
|
Type = "simple";
|
2016-01-30 13:47:04 +00:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2018-04-25 17:58:05 +00:00
|
|
|
TimeoutSec = "infinity";
|
2016-08-12 17:17:43 +00:00
|
|
|
Restart = "on-failure";
|
2016-09-27 13:49:21 +00:00
|
|
|
WorkingDirectory = gitlabEnv.HOME;
|
2016-01-30 13:47:04 +00:00
|
|
|
ExecStart =
|
2016-02-26 07:55:25 +00:00
|
|
|
"${cfg.packages.gitlab-workhorse}/bin/gitlab-workhorse "
|
2016-01-30 13:47:04 +00:00
|
|
|
+ "-listenUmask 0 "
|
|
|
|
+ "-listenNetwork unix "
|
|
|
|
+ "-listenAddr /run/gitlab/gitlab-workhorse.socket "
|
2016-02-26 06:06:07 +00:00
|
|
|
+ "-authSocket ${gitlabSocket} "
|
2016-09-27 13:49:21 +00:00
|
|
|
+ "-documentRoot ${cfg.packages.gitlab}/share/gitlab/public "
|
2017-09-03 13:38:28 +00:00
|
|
|
+ "-secretPath ${cfg.statePath}/.gitlab_workhorse_secret";
|
2015-10-21 17:48:56 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-10-25 16:22:49 +00:00
|
|
|
systemd.services.gitlab = {
|
2018-11-02 20:22:51 +00:00
|
|
|
after = [ "gitlab-workhorse.service" "gitaly.service" "network.target" "postgresql.service" "redis.service" ];
|
2016-10-20 09:01:59 +00:00
|
|
|
requires = [ "gitlab-sidekiq.service" ];
|
2014-10-25 16:22:49 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-01-30 13:47:04 +00:00
|
|
|
environment = gitlabEnv;
|
2014-10-25 16:22:49 +00:00
|
|
|
path = with pkgs; [
|
|
|
|
config.services.postgresql.package
|
|
|
|
gitAndTools.git
|
|
|
|
openssh
|
2014-12-14 01:24:12 +00:00
|
|
|
nodejs
|
2017-07-05 21:53:31 +00:00
|
|
|
procps
|
2017-09-21 18:23:16 +00:00
|
|
|
gnupg
|
2014-10-25 16:22:49 +00:00
|
|
|
];
|
|
|
|
preStart = ''
|
2019-07-15 23:19:07 +00:00
|
|
|
${pkgs.sudo}/bin/sudo -u ${cfg.user} cp -f ${cfg.packages.gitlab}/share/gitlab/VERSION ${cfg.statePath}/VERSION
|
2019-07-16 01:48:13 +00:00
|
|
|
${pkgs.sudo}/bin/sudo -u ${cfg.user} rm -rf ${cfg.statePath}/db/*
|
|
|
|
${pkgs.sudo}/bin/sudo -u ${cfg.user} cp -rf --no-preserve=mode ${cfg.packages.gitlab}/share/gitlab/config.dist/* ${cfg.statePath}/config
|
|
|
|
${pkgs.sudo}/bin/sudo -u ${cfg.user} cp -rf --no-preserve=mode ${cfg.packages.gitlab}/share/gitlab/db/* ${cfg.statePath}/db
|
2018-11-02 20:22:51 +00:00
|
|
|
|
2019-07-16 01:42:45 +00:00
|
|
|
${pkgs.openssl}/bin/openssl rand -hex 32 > ${cfg.statePath}/gitlab_shell_secret
|
2016-01-30 13:47:04 +00:00
|
|
|
|
2019-07-15 23:19:07 +00:00
|
|
|
${pkgs.sudo}/bin/sudo -u ${cfg.user} ${cfg.packages.gitlab-shell}/bin/install
|
2018-11-02 20:22:51 +00:00
|
|
|
|
|
|
|
if ! test -e "${cfg.statePath}/db-created"; then
|
|
|
|
if [ "${cfg.databaseHost}" = "127.0.0.1" ]; then
|
2017-09-02 21:16:02 +00:00
|
|
|
${pkgs.sudo}/bin/sudo -u ${pgSuperUser} psql postgres -c "CREATE ROLE ${cfg.databaseUsername} WITH LOGIN NOCREATEDB NOCREATEROLE ENCRYPTED PASSWORD '${cfg.databasePassword}'"
|
|
|
|
${pkgs.sudo}/bin/sudo -u ${pgSuperUser} ${config.services.postgresql.package}/bin/createdb --owner ${cfg.databaseUsername} ${cfg.databaseName}
|
2018-11-02 20:22:51 +00:00
|
|
|
|
|
|
|
# enable required pg_trgm extension for gitlab
|
|
|
|
${pkgs.sudo}/bin/sudo -u ${pgSuperUser} psql ${cfg.databaseName} -c "CREATE EXTENSION IF NOT EXISTS pg_trgm"
|
2014-10-25 16:22:49 +00:00
|
|
|
fi
|
2018-06-05 19:27:42 +00:00
|
|
|
|
2018-11-02 20:22:51 +00:00
|
|
|
${pkgs.sudo}/bin/sudo -u ${cfg.user} -H ${gitlab-rake}/bin/gitlab-rake db:schema:load
|
|
|
|
|
2019-07-15 23:19:07 +00:00
|
|
|
${pkgs.sudo}/bin/sudo -u ${cfg.user} touch "${cfg.statePath}/db-created"
|
2014-10-25 16:22:49 +00:00
|
|
|
fi
|
|
|
|
|
2016-01-30 13:47:04 +00:00
|
|
|
# Always do the db migrations just to be sure the database is up-to-date
|
2018-11-02 20:22:51 +00:00
|
|
|
${pkgs.sudo}/bin/sudo -u ${cfg.user} -H ${gitlab-rake}/bin/gitlab-rake db:migrate
|
2014-10-25 16:22:49 +00:00
|
|
|
|
2016-09-27 13:49:21 +00:00
|
|
|
if ! test -e "${cfg.statePath}/db-seeded"; then
|
2018-11-02 20:22:51 +00:00
|
|
|
${pkgs.sudo}/bin/sudo -u ${cfg.user} ${gitlab-rake}/bin/gitlab-rake db:seed_fu \
|
2017-09-03 13:38:28 +00:00
|
|
|
GITLAB_ROOT_PASSWORD='${cfg.initialRootPassword}' GITLAB_ROOT_EMAIL='${cfg.initialRootEmail}'
|
2019-07-15 23:19:07 +00:00
|
|
|
${pkgs.sudo}/bin/sudo -u ${cfg.user} touch "${cfg.statePath}/db-seeded"
|
2016-09-27 13:49:21 +00:00
|
|
|
fi
|
|
|
|
|
2019-07-15 23:19:07 +00:00
|
|
|
# We remove potentially broken links to old gitlab-shell versions
|
2017-10-23 21:48:26 +00:00
|
|
|
rm -f ${cfg.statePath}/repositories/**/*.git/hooks
|
2018-11-02 20:22:51 +00:00
|
|
|
|
|
|
|
${pkgs.sudo}/bin/sudo -u ${cfg.user} -H ${pkgs.git}/bin/git config --global core.autocrlf "input"
|
2014-10-25 16:22:49 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
PermissionsStartOnly = true; # preStart must be run as root
|
|
|
|
Type = "simple";
|
2016-01-30 13:47:04 +00:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2018-04-25 17:58:05 +00:00
|
|
|
TimeoutSec = "infinity";
|
2016-08-03 16:49:18 +00:00
|
|
|
Restart = "on-failure";
|
2016-02-26 07:55:25 +00:00
|
|
|
WorkingDirectory = "${cfg.packages.gitlab}/share/gitlab";
|
2018-04-25 17:58:05 +00:00
|
|
|
ExecStart = "${cfg.packages.gitlab.rubyEnv}/bin/unicorn -c ${cfg.statePath}/config/unicorn.rb -E production";
|
2014-10-25 16:22:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
2016-05-09 05:53:27 +00:00
|
|
|
|
|
|
|
meta.doc = ./gitlab.xml;
|
|
|
|
|
2014-10-25 16:22:49 +00:00
|
|
|
}
|