2014-10-25 18:22:49 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
# TODO: support non-postgresql
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.gitlab;
|
|
|
|
|
2016-02-26 08:55:25 +01:00
|
|
|
ruby = cfg.packages.gitlab.ruby;
|
2015-01-25 22:01:48 +01:00
|
|
|
bundler = pkgs.bundler;
|
|
|
|
|
2017-07-05 23:53:31 +02:00
|
|
|
gemHome = "${cfg.packages.gitlab.ruby-env}/${ruby.gemPath}";
|
2014-10-25 18:22:49 +02:00
|
|
|
|
2016-02-26 07:06:07 +01:00
|
|
|
gitlabSocket = "${cfg.statePath}/tmp/sockets/gitlab.socket";
|
2017-07-05 23:53:31 +02:00
|
|
|
gitalySocket = "${cfg.statePath}/tmp/sockets/gitaly.socket";
|
2016-02-26 07:06:07 +01:00
|
|
|
pathUrlQuote = url: replaceStrings ["/"] ["%2F"] url;
|
2017-09-02 23:16:02 +02:00
|
|
|
pgSuperUser = config.services.postgresql.superUser;
|
2016-02-26 07:06:07 +01:00
|
|
|
|
2014-10-25 18:22:49 +02:00
|
|
|
databaseYml = ''
|
|
|
|
production:
|
|
|
|
adapter: postgresql
|
|
|
|
database: ${cfg.databaseName}
|
|
|
|
host: ${cfg.databaseHost}
|
|
|
|
password: ${cfg.databasePassword}
|
|
|
|
username: ${cfg.databaseUsername}
|
|
|
|
encoding: utf8
|
|
|
|
'';
|
2016-01-30 14:47:04 +01:00
|
|
|
|
2017-07-05 23:53:31 +02:00
|
|
|
gitalyToml = pkgs.writeText "gitaly.toml" ''
|
|
|
|
socket_path = "${lib.escape ["\""] gitalySocket}"
|
|
|
|
# prometheus metrics
|
|
|
|
|
|
|
|
${concatStringsSep "\n" (attrValues (mapAttrs (k: v: ''
|
|
|
|
[[storage]]
|
|
|
|
name = "${lib.escape ["\""] k}"
|
|
|
|
path = "${lib.escape ["\""] v.path}"
|
|
|
|
'') gitlabConfig.production.repositories.storages))}
|
|
|
|
'';
|
|
|
|
|
2014-10-25 18:22:49 +02:00
|
|
|
gitlabShellYml = ''
|
2016-01-30 14:47:04 +01:00
|
|
|
user: ${cfg.user}
|
2016-02-26 07:06:07 +01:00
|
|
|
gitlab_url: "http+unix://${pathUrlQuote gitlabSocket}"
|
2014-10-25 18:22:49 +02:00
|
|
|
http_settings:
|
|
|
|
self_signed_cert: false
|
2016-01-30 14:47:04 +01:00
|
|
|
repos_path: "${cfg.statePath}/repositories"
|
|
|
|
secret_file: "${cfg.statePath}/config/gitlab_shell_secret"
|
|
|
|
log_file: "${cfg.statePath}/log/gitlab-shell.log"
|
2014-10-25 18:22:49 +02:00
|
|
|
redis:
|
|
|
|
bin: ${pkgs.redis}/bin/redis-cli
|
|
|
|
host: 127.0.0.1
|
|
|
|
port: 6379
|
|
|
|
database: 0
|
|
|
|
namespace: resque:gitlab
|
|
|
|
'';
|
|
|
|
|
2016-08-17 13:16:32 +02:00
|
|
|
secretsYml = ''
|
|
|
|
production:
|
2016-08-26 14:08:53 +02:00
|
|
|
secret_key_base: ${cfg.secrets.secret}
|
|
|
|
otp_key_base: ${cfg.secrets.otp}
|
|
|
|
db_key_base: ${cfg.secrets.db}
|
2017-07-05 23:53:31 +02:00
|
|
|
jws_private_key: ${builtins.toJSON cfg.secrets.jws}
|
2016-08-17 13:16:32 +02:00
|
|
|
'';
|
|
|
|
|
2016-01-30 14:47:04 +01:00
|
|
|
gitlabConfig = {
|
2016-02-23 22:55:35 +01:00
|
|
|
# These are the default settings from config/gitlab.example.yml
|
2016-01-30 14:47:04 +01: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 22:55:35 +01:00
|
|
|
wiki = true;
|
2016-08-03 18:49:18 +02:00
|
|
|
snippets = true;
|
2016-01-30 14:47:04 +01:00
|
|
|
builds = true;
|
2016-08-03 18:49:18 +02:00
|
|
|
container_registry = true;
|
2016-01-30 14:47:04 +01:00
|
|
|
};
|
|
|
|
};
|
2017-07-05 23:53:31 +02:00
|
|
|
repositories.storages.default.path = "${cfg.statePath}/repositories";
|
|
|
|
repositories.storages.default.gitaly_address = "unix:${gitalySocket}";
|
2016-08-03 18:49:18 +02: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";
|
|
|
|
backup.path = "${cfg.backupPath}";
|
2016-01-30 14:47:04 +01:00
|
|
|
gitlab_shell = {
|
2016-02-26 08:55:25 +01:00
|
|
|
path = "${cfg.packages.gitlab-shell}";
|
2016-01-30 14:47:04 +01:00
|
|
|
hooks_path = "${cfg.statePath}/shell/hooks";
|
|
|
|
secret_file = "${cfg.statePath}/config/gitlab_shell_secret";
|
|
|
|
upload_pack = true;
|
|
|
|
receive_pack = true;
|
|
|
|
};
|
|
|
|
git = {
|
|
|
|
bin_path = "git";
|
|
|
|
max_size = 20971520; # 20MB
|
|
|
|
timeout = 10;
|
|
|
|
};
|
|
|
|
extra = {};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
gitlabEnv = {
|
|
|
|
HOME = "${cfg.statePath}/home";
|
|
|
|
GEM_HOME = gemHome;
|
2016-02-26 08:55:25 +01:00
|
|
|
BUNDLE_GEMFILE = "${cfg.packages.gitlab}/share/gitlab/Gemfile";
|
2016-01-30 14:47:04 +01:00
|
|
|
UNICORN_PATH = "${cfg.statePath}/";
|
2016-02-26 08:55:25 +01:00
|
|
|
GITLAB_PATH = "${cfg.packages.gitlab}/share/gitlab/";
|
2016-01-30 14:47:04 +01:00
|
|
|
GITLAB_STATE_PATH = "${cfg.statePath}";
|
|
|
|
GITLAB_UPLOADS_PATH = "${cfg.statePath}/uploads";
|
|
|
|
GITLAB_LOG_PATH = "${cfg.statePath}/log";
|
2016-02-26 08:55:25 +01:00
|
|
|
GITLAB_SHELL_PATH = "${cfg.packages.gitlab-shell}";
|
2017-07-05 23:53:31 +02:00
|
|
|
GITLAB_SHELL_CONFIG_PATH = "${cfg.statePath}/home/config.yml";
|
2016-01-30 14:47:04 +01:00
|
|
|
GITLAB_SHELL_SECRET_PATH = "${cfg.statePath}/config/gitlab_shell_secret";
|
2017-07-05 23:53:31 +02:00
|
|
|
GITLAB_SHELL_HOOKS_PATH = "${cfg.statePath}/home/hooks";
|
2016-01-30 14:47:04 +01:00
|
|
|
RAILS_ENV = "production";
|
|
|
|
};
|
|
|
|
|
2014-10-25 18:22:49 +02:00
|
|
|
unicornConfig = builtins.readFile ./defaultUnicornConfig.rb;
|
|
|
|
|
2016-08-04 02:08:26 +02:00
|
|
|
gitlab-rake = pkgs.stdenv.mkDerivation rec {
|
|
|
|
name = "gitlab-rake";
|
2017-07-05 23:53:31 +02:00
|
|
|
buildInputs = [ cfg.packages.gitlab cfg.packages.gitlab.ruby-env pkgs.makeWrapper ];
|
2014-10-25 18:22:49 +02:00
|
|
|
phases = "installPhase fixupPhase";
|
|
|
|
buildPhase = "";
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
2017-07-05 23:53:31 +02:00
|
|
|
makeWrapper ${cfg.packages.gitlab.ruby-env}/bin/bundle $out/bin/gitlab-bundle \
|
2016-08-03 18:49:18 +02:00
|
|
|
${concatStrings (mapAttrsToList (name: value: "--set ${name} '${value}' ") gitlabEnv)} \
|
|
|
|
--set GITLAB_CONFIG_PATH '${cfg.statePath}/config' \
|
2016-08-26 14:08:53 +02:00
|
|
|
--set PATH '${lib.makeBinPath [ pkgs.nodejs pkgs.gzip config.services.postgresql.package ]}:$PATH' \
|
2016-08-03 18:49:18 +02:00
|
|
|
--set RAKEOPT '-f ${cfg.packages.gitlab}/share/gitlab/Rakefile' \
|
|
|
|
--run 'cd ${cfg.packages.gitlab}/share/gitlab'
|
2016-08-04 02:08:26 +02:00
|
|
|
makeWrapper $out/bin/gitlab-bundle $out/bin/gitlab-rake \
|
|
|
|
--add-flags "exec rake"
|
|
|
|
'';
|
2014-10-25 18:22:49 +02:00
|
|
|
};
|
|
|
|
|
2016-08-03 18:49:18 +02: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 18:22:49 +02:00
|
|
|
in {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.gitlab = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable the gitlab service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-02-26 08:55:25 +01:00
|
|
|
packages.gitlab = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.gitlab;
|
2016-11-21 16:26:03 +01:00
|
|
|
defaultText = "pkgs.gitlab";
|
2016-02-26 08:55:25 +01:00
|
|
|
description = "Reference to the gitlab package";
|
|
|
|
};
|
|
|
|
|
|
|
|
packages.gitlab-shell = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.gitlab-shell;
|
2016-11-21 16:26:03 +01:00
|
|
|
defaultText = "pkgs.gitlab-shell";
|
2016-02-26 08:55:25 +01:00
|
|
|
description = "Reference to the gitlab-shell package";
|
|
|
|
};
|
|
|
|
|
|
|
|
packages.gitlab-workhorse = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.gitlab-workhorse;
|
2016-11-21 16:26:03 +01:00
|
|
|
defaultText = "pkgs.gitlab-workhorse";
|
2016-02-26 08:55:25 +01:00
|
|
|
description = "Reference to the gitlab-workhorse package";
|
|
|
|
};
|
|
|
|
|
2017-07-05 23:53:31 +02:00
|
|
|
packages.gitaly = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.gitaly;
|
|
|
|
defaultText = "pkgs.gitaly";
|
|
|
|
description = "Reference to the gitaly package";
|
|
|
|
};
|
|
|
|
|
2016-01-30 14:47:04 +01:00
|
|
|
statePath = mkOption {
|
2014-10-25 18:22:49 +02:00
|
|
|
type = types.str;
|
|
|
|
default = "/var/gitlab/state";
|
2014-11-30 00:56:22 +01:00
|
|
|
description = "Gitlab state directory, logs are stored here.";
|
2014-10-25 18:22:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
backupPath = mkOption {
|
|
|
|
type = types.str;
|
2016-01-30 14:47:04 +01:00
|
|
|
default = cfg.statePath + "/backup";
|
2014-11-30 00:56:22 +01:00
|
|
|
description = "Gitlab path for backups.";
|
2014-10-25 18:22:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
databaseHost = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
2014-11-30 00:56:22 +01:00
|
|
|
description = "Gitlab database hostname.";
|
2014-10-25 18:22:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
databasePassword = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2014-11-30 00:56:22 +01:00
|
|
|
description = "Gitlab database user password.";
|
2014-10-25 18:22:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
databaseName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "gitlab";
|
2014-11-30 00:56:22 +01:00
|
|
|
description = "Gitlab database name.";
|
2014-10-25 18:22:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
databaseUsername = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "gitlab";
|
2014-11-30 00:56:22 +01:00
|
|
|
description = "Gitlab database user.";
|
2014-10-25 18:22:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = config.networking.hostName;
|
2014-11-30 00:56:22 +01:00
|
|
|
description = "Gitlab host name. Used e.g. for copy-paste URLs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 8080;
|
2016-01-30 14:47:04 +01: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;
|
|
|
|
default = "UseNixOS!";
|
|
|
|
description = ''
|
|
|
|
Initial password of the root account if this is a new install.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-08-03 18:49:18 +02: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 14:08:53 +02:00
|
|
|
secrets.secret = mkOption {
|
2016-08-17 13:16:32 +02:00
|
|
|
type = types.str;
|
|
|
|
description = ''
|
2016-08-26 14:08:53 +02:00
|
|
|
The secret is used to encrypt variables in the DB. If
|
2016-08-17 13:16:32 +02: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 14:08:53 +02: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 23:53:31 +02: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
|
|
|
|
|
|
|
|
openssl genrsa 2048openssl genpkey -algorithm RSA -out - -pkeyopt rsa_keygen_bits:2048
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-01-30 14:47:04 +01:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.attrs;
|
2016-02-23 22:55:35 +01:00
|
|
|
default = {};
|
2016-01-30 14:47:04 +01: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 18:22:49 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2016-08-04 02:08:26 +02:00
|
|
|
environment.systemPackages = [ pkgs.git gitlab-rake cfg.packages.gitlab-shell ];
|
2014-10-25 18:22:49 +02:00
|
|
|
|
|
|
|
assertions = [
|
|
|
|
{ assertion = cfg.databasePassword != "";
|
|
|
|
message = "databasePassword must be set";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
# 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;
|
|
|
|
|
|
|
|
users.extraUsers = [
|
2016-01-30 14:47:04 +01:00
|
|
|
{ name = cfg.user;
|
|
|
|
group = cfg.group;
|
|
|
|
home = "${cfg.statePath}/home";
|
2014-10-25 18:22:49 +02:00
|
|
|
shell = "${pkgs.bash}/bin/bash";
|
|
|
|
uid = config.ids.uids.gitlab;
|
2016-01-30 14:47:04 +01:00
|
|
|
}
|
|
|
|
];
|
2014-10-25 18:22:49 +02:00
|
|
|
|
|
|
|
users.extraGroups = [
|
2016-01-30 14:47:04 +01:00
|
|
|
{ name = cfg.group;
|
2014-10-25 18:22:49 +02:00
|
|
|
gid = config.ids.gids.gitlab;
|
2016-01-30 14:47:04 +01:00
|
|
|
}
|
|
|
|
];
|
2014-10-25 18:22:49 +02:00
|
|
|
|
|
|
|
systemd.services.gitlab-sidekiq = {
|
|
|
|
after = [ "network.target" "redis.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-08-03 18:49:18 +02:00
|
|
|
partOf = [ "gitlab.service" ];
|
2016-01-30 14:47:04 +01:00
|
|
|
environment = gitlabEnv;
|
2014-10-25 18:22:49 +02:00
|
|
|
path = with pkgs; [
|
|
|
|
config.services.postgresql.package
|
|
|
|
gitAndTools.git
|
|
|
|
ruby
|
|
|
|
openssh
|
2014-12-14 02:24:12 +01:00
|
|
|
nodejs
|
2014-10-25 18:22:49 +02:00
|
|
|
];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
2016-01-30 14:47:04 +01:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2014-10-25 18:22:49 +02:00
|
|
|
TimeoutSec = "300";
|
2016-08-12 19:17:43 +02:00
|
|
|
Restart = "on-failure";
|
2016-02-26 08:55:25 +01:00
|
|
|
WorkingDirectory = "${cfg.packages.gitlab}/share/gitlab";
|
2017-07-05 23:53:31 +02:00
|
|
|
ExecStart="${cfg.packages.gitlab.ruby-env}/bin/bundle exec \"sidekiq -C \"${cfg.packages.gitlab}/share/gitlab/config/sidekiq_queues.yml\" -e production -P ${cfg.statePath}/tmp/sidekiq.pid\"";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.gitaly = {
|
|
|
|
after = [ "network.target" "gitlab.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
environment.HOME = gitlabEnv.HOME;
|
|
|
|
path = with pkgs; [ gitAndTools.git ];
|
|
|
|
serviceConfig = {
|
|
|
|
#PermissionsStartOnly = true; # preStart must be run as root
|
|
|
|
Type = "simple";
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
TimeoutSec = "300";
|
|
|
|
Restart = "on-failure";
|
|
|
|
WorkingDirectory = gitlabEnv.HOME;
|
|
|
|
ExecStart = "${cfg.packages.gitaly}/bin/gitaly ${gitalyToml}";
|
2014-10-25 18:22:49 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-01-30 14:47:04 +01:00
|
|
|
systemd.services.gitlab-workhorse = {
|
2015-10-21 19:48:56 +02:00
|
|
|
after = [ "network.target" "gitlab.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-01-30 14:47:04 +01:00
|
|
|
environment.HOME = gitlabEnv.HOME;
|
|
|
|
environment.GITLAB_SHELL_CONFIG_PATH = gitlabEnv.GITLAB_SHELL_CONFIG_PATH;
|
2015-10-21 19:48:56 +02:00
|
|
|
path = with pkgs; [
|
|
|
|
gitAndTools.git
|
2017-07-19 21:34:17 +02:00
|
|
|
gnutar
|
|
|
|
gzip
|
2015-10-21 19:48:56 +02:00
|
|
|
openssh
|
2017-05-12 08:52:33 +02:00
|
|
|
gitlab-workhorse
|
2015-10-21 19:48:56 +02:00
|
|
|
];
|
2016-01-30 14:47:04 +01:00
|
|
|
preStart = ''
|
|
|
|
mkdir -p /run/gitlab
|
|
|
|
chown ${cfg.user}:${cfg.group} /run/gitlab
|
|
|
|
'';
|
2015-10-21 19:48:56 +02:00
|
|
|
serviceConfig = {
|
2016-01-30 14:47:04 +01:00
|
|
|
PermissionsStartOnly = true; # preStart must be run as root
|
2015-10-21 19:48:56 +02:00
|
|
|
Type = "simple";
|
2016-01-30 14:47:04 +01:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2015-10-21 19:48:56 +02:00
|
|
|
TimeoutSec = "300";
|
2016-08-12 19:17:43 +02:00
|
|
|
Restart = "on-failure";
|
2016-09-27 15:49:21 +02:00
|
|
|
WorkingDirectory = gitlabEnv.HOME;
|
2016-01-30 14:47:04 +01:00
|
|
|
ExecStart =
|
2016-02-26 08:55:25 +01:00
|
|
|
"${cfg.packages.gitlab-workhorse}/bin/gitlab-workhorse "
|
2016-01-30 14:47:04 +01:00
|
|
|
+ "-listenUmask 0 "
|
|
|
|
+ "-listenNetwork unix "
|
|
|
|
+ "-listenAddr /run/gitlab/gitlab-workhorse.socket "
|
2016-02-26 07:06:07 +01:00
|
|
|
+ "-authSocket ${gitlabSocket} "
|
2016-09-27 15:49:21 +02:00
|
|
|
+ "-documentRoot ${cfg.packages.gitlab}/share/gitlab/public "
|
|
|
|
+ "-secretPath ${cfg.packages.gitlab}/share/gitlab/.gitlab_workhorse_secret";
|
2015-10-21 19:48:56 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-10-25 18:22:49 +02:00
|
|
|
systemd.services.gitlab = {
|
|
|
|
after = [ "network.target" "postgresql.service" "redis.service" ];
|
2016-10-20 11:01:59 +02:00
|
|
|
requires = [ "gitlab-sidekiq.service" ];
|
2014-10-25 18:22:49 +02:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-01-30 14:47:04 +01:00
|
|
|
environment = gitlabEnv;
|
2014-10-25 18:22:49 +02:00
|
|
|
path = with pkgs; [
|
|
|
|
config.services.postgresql.package
|
|
|
|
gitAndTools.git
|
|
|
|
openssh
|
2014-12-14 02:24:12 +01:00
|
|
|
nodejs
|
2017-07-05 23:53:31 +02:00
|
|
|
procps
|
2014-10-25 18:22:49 +02:00
|
|
|
];
|
|
|
|
preStart = ''
|
2016-01-30 14:47:04 +01:00
|
|
|
mkdir -p ${cfg.backupPath}
|
|
|
|
mkdir -p ${cfg.statePath}/builds
|
|
|
|
mkdir -p ${cfg.statePath}/repositories
|
|
|
|
mkdir -p ${gitlabConfig.production.shared.path}/artifacts
|
|
|
|
mkdir -p ${gitlabConfig.production.shared.path}/lfs-objects
|
2017-03-06 15:57:49 +01:00
|
|
|
mkdir -p ${gitlabConfig.production.shared.path}/pages
|
2016-01-30 14:47:04 +01:00
|
|
|
mkdir -p ${cfg.statePath}/log
|
|
|
|
mkdir -p ${cfg.statePath}/tmp/pids
|
|
|
|
mkdir -p ${cfg.statePath}/tmp/sockets
|
|
|
|
|
2017-07-05 23:53:31 +02:00
|
|
|
rm -rf ${cfg.statePath}/config ${cfg.statePath}/home/hooks
|
|
|
|
mkdir -p ${cfg.statePath}/config
|
2014-10-25 18:22:49 +02:00
|
|
|
|
2016-08-26 14:08:53 +02:00
|
|
|
tr -dc A-Za-z0-9 < /dev/urandom | head -c 32 > ${cfg.statePath}/config/gitlab_shell_secret
|
2016-01-30 14:47:04 +01:00
|
|
|
|
|
|
|
# The uploads directory is hardcoded somewhere deep in rails. It is
|
|
|
|
# symlinked in the gitlab package to /run/gitlab/uploads to make it
|
|
|
|
# configurable
|
|
|
|
mkdir -p /run/gitlab
|
|
|
|
mkdir -p ${cfg.statePath}/uploads
|
|
|
|
ln -sf ${cfg.statePath}/uploads /run/gitlab/uploads
|
|
|
|
chown -R ${cfg.user}:${cfg.group} /run/gitlab
|
|
|
|
|
|
|
|
# Prepare home directory
|
|
|
|
mkdir -p ${gitlabEnv.HOME}/.ssh
|
|
|
|
touch ${gitlabEnv.HOME}/.ssh/authorized_keys
|
|
|
|
chown -R ${cfg.user}:${cfg.group} ${gitlabEnv.HOME}/
|
|
|
|
chmod -R u+rwX,go-rwx+X ${gitlabEnv.HOME}/
|
|
|
|
|
2016-02-26 08:55:25 +01:00
|
|
|
cp -rf ${cfg.packages.gitlab}/share/gitlab/config.dist/* ${cfg.statePath}/config
|
2016-08-03 18:49:18 +02:00
|
|
|
${optionalString cfg.smtp.enable ''
|
|
|
|
ln -sf ${smtpSettings} ${cfg.statePath}/config/initializers/smtp_settings.rb
|
|
|
|
''}
|
2016-01-30 14:47:04 +01:00
|
|
|
ln -sf ${cfg.statePath}/config /run/gitlab/config
|
2016-02-26 08:55:25 +01:00
|
|
|
cp ${cfg.packages.gitlab}/share/gitlab/VERSION ${cfg.statePath}/VERSION
|
2016-01-30 14:47:04 +01:00
|
|
|
|
|
|
|
# JSON is a subset of YAML
|
|
|
|
ln -fs ${pkgs.writeText "gitlab.yml" (builtins.toJSON gitlabConfig)} ${cfg.statePath}/config/gitlab.yml
|
|
|
|
ln -fs ${pkgs.writeText "database.yml" databaseYml} ${cfg.statePath}/config/database.yml
|
2016-08-17 13:16:32 +02:00
|
|
|
ln -fs ${pkgs.writeText "secrets.yml" secretsYml} ${cfg.statePath}/config/secrets.yml
|
2016-01-30 14:47:04 +01:00
|
|
|
ln -fs ${pkgs.writeText "unicorn.rb" unicornConfig} ${cfg.statePath}/config/unicorn.rb
|
|
|
|
|
|
|
|
chown -R ${cfg.user}:${cfg.group} ${cfg.statePath}/
|
|
|
|
chmod -R ug+rwX,o-rwx+X ${cfg.statePath}/
|
|
|
|
|
|
|
|
# Install the shell required to push repositories
|
|
|
|
ln -fs ${pkgs.writeText "config.yml" gitlabShellYml} "$GITLAB_SHELL_CONFIG_PATH"
|
2016-02-26 08:55:25 +01:00
|
|
|
ln -fs ${cfg.packages.gitlab-shell}/hooks "$GITLAB_SHELL_HOOKS_PATH"
|
|
|
|
${cfg.packages.gitlab-shell}/bin/install
|
2014-10-25 18:22:49 +02:00
|
|
|
|
2017-05-23 00:06:00 +02:00
|
|
|
if [ "${cfg.databaseHost}" = "127.0.0.1" ]; then
|
2016-01-30 14:47:04 +01:00
|
|
|
if ! test -e "${cfg.statePath}/db-created"; then
|
2017-09-02 23:16:02 +02: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}
|
2016-01-30 14:47:04 +01:00
|
|
|
touch "${cfg.statePath}/db-created"
|
2014-10-25 18:22:49 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-09-20 17:44:31 +02:00
|
|
|
# enable required pg_trgm extension for gitlab
|
2017-09-02 23:16:02 +02:00
|
|
|
${pkgs.sudo}/bin/sudo -u ${pgSuperUser} psql gitlab -c "CREATE EXTENSION IF NOT EXISTS pg_trgm"
|
2016-01-30 14:47:04 +01:00
|
|
|
# Always do the db migrations just to be sure the database is up-to-date
|
2016-08-04 02:08:26 +02:00
|
|
|
${gitlab-rake}/bin/gitlab-rake db:migrate RAILS_ENV=production
|
2014-10-25 18:22:49 +02:00
|
|
|
|
2016-09-27 15:49:21 +02:00
|
|
|
# The gitlab:setup task is horribly broken somehow, the db:migrate
|
|
|
|
# task above and the db:seed_fu below will do the same for setting
|
|
|
|
# up the initial database
|
|
|
|
if ! test -e "${cfg.statePath}/db-seeded"; then
|
|
|
|
${gitlab-rake}/bin/gitlab-rake db:seed_fu RAILS_ENV=production \
|
|
|
|
GITLAB_ROOT_PASSWORD="${cfg.initialRootPassword}" GITLAB_ROOT_EMAIL="${cfg.initialRootEmail}"
|
|
|
|
touch "${cfg.statePath}/db-seeded"
|
|
|
|
fi
|
|
|
|
|
2016-01-30 14:47:04 +01:00
|
|
|
# Change permissions in the last step because some of the
|
|
|
|
# intermediary scripts like to create directories as root.
|
|
|
|
chown -R ${cfg.user}:${cfg.group} ${cfg.statePath}
|
|
|
|
chmod -R u+rwX,go-rwx+X ${cfg.statePath}
|
2014-10-25 18:22:49 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
PermissionsStartOnly = true; # preStart must be run as root
|
|
|
|
Type = "simple";
|
2016-01-30 14:47:04 +01:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2014-10-25 18:22:49 +02:00
|
|
|
TimeoutSec = "300";
|
2016-08-03 18:49:18 +02:00
|
|
|
Restart = "on-failure";
|
2016-02-26 08:55:25 +01:00
|
|
|
WorkingDirectory = "${cfg.packages.gitlab}/share/gitlab";
|
2017-07-05 23:53:31 +02:00
|
|
|
ExecStart = "${cfg.packages.gitlab.ruby-env}/bin/bundle exec \"unicorn -c ${cfg.statePath}/config/unicorn.rb -E production\"";
|
2014-10-25 18:22:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
2016-05-09 07:53:27 +02:00
|
|
|
|
|
|
|
meta.doc = ./gitlab.xml;
|
|
|
|
|
2014-10-25 18:22:49 +02:00
|
|
|
}
|