+35
-17
nixos/modules/services/misc/gitlab.nix
+35
-17
nixos/modules/services/misc/gitlab.nix
···
7
7
let
8
8
cfg = config.services.gitlab;
9
9
10
-
ruby = pkgs.gitlab.ruby;
10
+
ruby = cfg.packages.gitlab.ruby;
11
11
bundler = pkgs.bundler;
12
12
13
-
gemHome = "${pkgs.gitlab.env}/${ruby.gemPath}";
13
+
gemHome = "${cfg.packages.gitlab.env}/${ruby.gemPath}";
14
14
15
15
gitlabSocket = "${cfg.statePath}/tmp/sockets/gitlab.socket";
16
16
pathUrlQuote = url: replaceStrings ["/"] ["%2F"] url;
···
91
91
path = "${cfg.backupPath}";
92
92
};
93
93
gitlab_shell = {
94
-
path = "${pkgs.gitlab-shell}";
94
+
path = "${cfg.packages.gitlab-shell}";
95
95
repos_path = "${cfg.statePath}/repositories";
96
96
hooks_path = "${cfg.statePath}/shell/hooks";
97
97
secret_file = "${cfg.statePath}/config/gitlab_shell_secret";
···
110
110
gitlabEnv = {
111
111
HOME = "${cfg.statePath}/home";
112
112
GEM_HOME = gemHome;
113
-
BUNDLE_GEMFILE = "${pkgs.gitlab}/share/gitlab/Gemfile";
113
+
BUNDLE_GEMFILE = "${cfg.packages.gitlab}/share/gitlab/Gemfile";
114
114
UNICORN_PATH = "${cfg.statePath}/";
115
-
GITLAB_PATH = "${pkgs.gitlab}/share/gitlab/";
115
+
GITLAB_PATH = "${cfg.packages.gitlab}/share/gitlab/";
116
116
GITLAB_STATE_PATH = "${cfg.statePath}";
117
117
GITLAB_UPLOADS_PATH = "${cfg.statePath}/uploads";
118
118
GITLAB_LOG_PATH = "${cfg.statePath}/log";
119
-
GITLAB_SHELL_PATH = "${pkgs.gitlab-shell}";
119
+
GITLAB_SHELL_PATH = "${cfg.packages.gitlab-shell}";
120
120
GITLAB_SHELL_CONFIG_PATH = "${cfg.statePath}/shell/config.yml";
121
121
GITLAB_SHELL_SECRET_PATH = "${cfg.statePath}/config/gitlab_shell_secret";
122
122
GITLAB_SHELL_HOOKS_PATH = "${cfg.statePath}/shell/hooks";
···
127
127
128
128
gitlab-runner = pkgs.stdenv.mkDerivation rec {
129
129
name = "gitlab-runner";
130
-
buildInputs = with pkgs; [ gitlab bundler makeWrapper ];
130
+
buildInputs = [ cfg.packages.gitlab bundler pkgs.makeWrapper ];
131
131
phases = "installPhase fixupPhase";
132
132
buildPhase = "";
133
133
installPhase = ''
···
136
136
${concatStrings (mapAttrsToList (name: value: "--set ${name} '\"${value}\"' ") gitlabEnv)} \
137
137
--set GITLAB_CONFIG_PATH '"${cfg.statePath}/config"' \
138
138
--set PATH '"${pkgs.nodejs}/bin:${pkgs.gzip}/bin:${config.services.postgresql.package}/bin:$PATH"' \
139
-
--set RAKEOPT '"-f ${pkgs.gitlab}/share/gitlab/Rakefile"'
139
+
--set RAKEOPT '"-f ${cfg.packages.gitlab}/share/gitlab/Rakefile"'
140
140
'';
141
141
};
142
142
···
152
152
'';
153
153
};
154
154
155
+
packages.gitlab = mkOption {
156
+
type = types.package;
157
+
default = pkgs.gitlab;
158
+
description = "Reference to the gitlab package";
159
+
};
160
+
161
+
packages.gitlab-shell = mkOption {
162
+
type = types.package;
163
+
default = pkgs.gitlab-shell;
164
+
description = "Reference to the gitlab-shell package";
165
+
};
166
+
167
+
packages.gitlab-workhorse = mkOption {
168
+
type = types.package;
169
+
default = pkgs.gitlab-workhorse;
170
+
description = "Reference to the gitlab-workhorse package";
171
+
};
172
+
155
173
statePath = mkOption {
156
174
type = types.str;
157
175
default = "/var/gitlab/state";
···
263
281
264
282
config = mkIf cfg.enable {
265
283
266
-
environment.systemPackages = [ pkgs.git gitlab-runner pkgs.gitlab-shell ];
284
+
environment.systemPackages = [ pkgs.git gitlab-runner cfg.packages.gitlab-shell ];
267
285
268
286
assertions = [
269
287
{ assertion = cfg.databasePassword != "";
···
309
327
User = cfg.user;
310
328
Group = cfg.group;
311
329
TimeoutSec = "300";
312
-
WorkingDirectory = "${pkgs.gitlab}/share/gitlab";
330
+
WorkingDirectory = "${cfg.packages.gitlab}/share/gitlab";
313
331
ExecStart="${bundler}/bin/bundle exec \"sidekiq -q post_receive -q mailer -q system_hook -q project_web_hook -q gitlab_shell -q common -q default -e production -P ${cfg.statePath}/tmp/sidekiq.pid\"";
314
332
};
315
333
};
···
334
352
Group = cfg.group;
335
353
TimeoutSec = "300";
336
354
ExecStart =
337
-
"${pkgs.gitlab-workhorse}/bin/gitlab-workhorse "
355
+
"${cfg.packages.gitlab-workhorse}/bin/gitlab-workhorse "
338
356
+ "-listenUmask 0 "
339
357
+ "-listenNetwork unix "
340
358
+ "-listenAddr /run/gitlab/gitlab-workhorse.socket "
341
359
+ "-authSocket ${gitlabSocket} "
342
-
+ "-documentRoot ${pkgs.gitlab}/share/gitlab/public";
360
+
+ "-documentRoot ${cfg.packages.gitlab}/share/gitlab/public";
343
361
};
344
362
};
345
363
···
384
402
chown -R ${cfg.user}:${cfg.group} ${gitlabEnv.HOME}/
385
403
chmod -R u+rwX,go-rwx+X ${gitlabEnv.HOME}/
386
404
387
-
cp -rf ${pkgs.gitlab}/share/gitlab/config.dist/* ${cfg.statePath}/config
405
+
cp -rf ${cfg.packages.gitlab}/share/gitlab/config.dist/* ${cfg.statePath}/config
388
406
ln -sf ${cfg.statePath}/config /run/gitlab/config
389
-
cp ${pkgs.gitlab}/share/gitlab/VERSION ${cfg.statePath}/VERSION
407
+
cp ${cfg.packages.gitlab}/share/gitlab/VERSION ${cfg.statePath}/VERSION
390
408
391
409
# JSON is a subset of YAML
392
410
ln -fs ${pkgs.writeText "gitlab.yml" (builtins.toJSON gitlabConfig)} ${cfg.statePath}/config/gitlab.yml
···
398
416
399
417
# Install the shell required to push repositories
400
418
ln -fs ${pkgs.writeText "config.yml" gitlabShellYml} "$GITLAB_SHELL_CONFIG_PATH"
401
-
ln -fs ${pkgs.gitlab-shell}/hooks "$GITLAB_SHELL_HOOKS_PATH"
402
-
${pkgs.gitlab-shell}/bin/install
419
+
ln -fs ${cfg.packages.gitlab-shell}/hooks "$GITLAB_SHELL_HOOKS_PATH"
420
+
${cfg.packages.gitlab-shell}/bin/install
403
421
404
422
if [ "${cfg.databaseHost}" = "127.0.0.1" ]; then
405
423
if ! test -e "${cfg.statePath}/db-created"; then
···
429
447
User = cfg.user;
430
448
Group = cfg.group;
431
449
TimeoutSec = "300";
432
-
WorkingDirectory = "${pkgs.gitlab}/share/gitlab";
450
+
WorkingDirectory = "${cfg.packages.gitlab}/share/gitlab";
433
451
ExecStart="${bundler}/bin/bundle exec \"unicorn -c ${cfg.statePath}/config/unicorn.rb -E production\"";
434
452
};
435
453