2024-06-05 15:53:02 +00:00
|
|
|
{ stdenv, lib, fetchFromGitLab, bundlerEnv
|
2024-01-02 11:29:13 +00:00
|
|
|
, ruby_3_1, tzdata, git, nettools, nixosTests, nodejs, openssl
|
2024-02-07 01:22:34 +00:00
|
|
|
, defaultGemConfig, buildRubyGem
|
2020-04-24 23:36:52 +00:00
|
|
|
, gitlabEnterprise ? false, callPackage, yarn
|
2024-04-21 15:54:59 +00:00
|
|
|
, fixup-yarn-lock, replace, file, cacert, fetchYarnDeps, makeWrapper, pkg-config
|
2024-02-07 01:22:34 +00:00
|
|
|
, cargo, rustc, rustPlatform
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2021-12-06 16:07:01 +00:00
|
|
|
data = lib.importJSON ./data.json;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
version = data.version;
|
|
|
|
src = fetchFromGitLab {
|
|
|
|
owner = data.owner;
|
|
|
|
repo = data.repo;
|
|
|
|
rev = data.rev;
|
|
|
|
sha256 = data.repo_hash;
|
|
|
|
};
|
|
|
|
|
|
|
|
rubyEnv = bundlerEnv rec {
|
|
|
|
name = "gitlab-env-${version}";
|
2024-01-02 11:29:13 +00:00
|
|
|
ruby = ruby_3_1;
|
2020-04-24 23:36:52 +00:00
|
|
|
gemdir = ./rubyEnv;
|
2024-02-07 01:22:34 +00:00
|
|
|
gemset = import (gemdir + "/gemset.nix") src;
|
|
|
|
gemConfig = defaultGemConfig // {
|
|
|
|
gpgme = attrs: {
|
2023-01-11 07:51:40 +00:00
|
|
|
nativeBuildInputs = [ pkg-config ];
|
|
|
|
};
|
2020-11-24 20:58:05 +00:00
|
|
|
# the openssl needs the openssl include files
|
2024-02-07 01:22:34 +00:00
|
|
|
openssl = attrs: {
|
2020-11-24 20:58:05 +00:00
|
|
|
buildInputs = [ openssl ];
|
|
|
|
};
|
2024-02-07 01:22:34 +00:00
|
|
|
ruby-magic = attrs: {
|
2021-04-08 16:26:57 +00:00
|
|
|
buildInputs = [ file ];
|
|
|
|
buildFlags = [ "--enable-system-libraries" ];
|
|
|
|
};
|
2024-02-07 01:22:34 +00:00
|
|
|
gitlab-glfm-markdown = attrs: {
|
|
|
|
cargoDeps = rustPlatform.fetchCargoTarball {
|
|
|
|
src = stdenv.mkDerivation {
|
|
|
|
inherit (buildRubyGem { inherit (attrs) gemName version source; })
|
|
|
|
name
|
|
|
|
src
|
|
|
|
unpackPhase
|
|
|
|
nativeBuildInputs
|
|
|
|
;
|
|
|
|
dontBuilt = true;
|
|
|
|
installPhase = ''
|
|
|
|
cp -R ext/glfm_markdown $out
|
|
|
|
cp Cargo.lock $out
|
|
|
|
'';
|
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
hash = "sha256-7q2xWAsFkXHxkYNzIjPwJRy72xMXF278cpVzqGLt/9Y=";
|
2024-02-07 01:22:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
dontBuild = false;
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
cargo
|
|
|
|
rustc
|
|
|
|
rustPlatform.cargoSetupHook
|
|
|
|
rustPlatform.bindgenHook
|
|
|
|
];
|
|
|
|
|
|
|
|
disallowedReferences = [
|
|
|
|
rustc.unwrapped
|
|
|
|
];
|
|
|
|
|
|
|
|
preInstall = ''
|
|
|
|
export CARGO_HOME="$PWD/../.cargo/"
|
|
|
|
'';
|
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
mv -v $GEM_HOME/gems/${attrs.gemName}-${attrs.version}/lib/{glfm_markdown/glfm_markdown.so,}
|
|
|
|
find $out -type f -name .rustc_info.json -delete
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
groups = [
|
|
|
|
"default" "unicorn" "ed25519" "metrics" "development" "puma" "test" "kerberos"
|
|
|
|
];
|
|
|
|
# N.B. omniauth_oauth2_generic and apollo_upload_server both provide a
|
|
|
|
# `console` executable.
|
|
|
|
ignoreCollisions = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
extraConfigPaths = [ "${src}/vendor" "${src}/gems" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
assets = stdenv.mkDerivation {
|
|
|
|
pname = "gitlab-assets";
|
|
|
|
inherit version src;
|
|
|
|
|
2022-10-06 18:32:54 +00:00
|
|
|
yarnOfflineCache = fetchYarnDeps {
|
|
|
|
yarnLock = src + "/yarn.lock";
|
|
|
|
sha256 = data.yarn_hash;
|
|
|
|
};
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
nativeBuildInputs = [ rubyEnv.wrappedRuby rubyEnv.bundler nodejs yarn git cacert fixup-yarn-lock ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-06-26 10:26:21 +00:00
|
|
|
patches = [
|
|
|
|
# Since version 12.6.0, the rake tasks need the location of git,
|
|
|
|
# so we have to apply the location patches here too.
|
|
|
|
./remove-hardcoded-locations.patch
|
|
|
|
|
|
|
|
# Gitlab edited the default database config since [1] and the
|
2023-07-15 17:15:38 +00:00
|
|
|
# installer now complains about valid keywords only being "main", "ci" and "embedded".
|
2022-06-26 10:26:21 +00:00
|
|
|
#
|
|
|
|
# [1]: https://gitlab.com/gitlab-org/gitlab/-/commit/99c0fac52b10cd9df62bbe785db799352a2d9028
|
2023-07-15 17:15:38 +00:00
|
|
|
./Remove-unsupported-database-names.patch
|
2022-06-26 10:26:21 +00:00
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
# One of the patches uses this variable - if it's unset, execution
|
|
|
|
# of rake tasks fails.
|
|
|
|
GITLAB_LOG_PATH = "log";
|
|
|
|
FOSS_ONLY = !gitlabEnterprise;
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
SKIP_YARN_INSTALL = 1;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
configurePhase = ''
|
|
|
|
runHook preConfigure
|
|
|
|
|
|
|
|
# Some rake tasks try to run yarn automatically, which won't work
|
|
|
|
rm lib/tasks/yarn.rake
|
|
|
|
|
|
|
|
# The rake tasks won't run without a basic configuration in place
|
2022-06-16 17:23:12 +00:00
|
|
|
mv config/database.yml.postgresql config/database.yml
|
2020-04-24 23:36:52 +00:00
|
|
|
mv config/gitlab.yml.example config/gitlab.yml
|
|
|
|
|
|
|
|
# Yarn and bundler wants a real home directory to write cache, config, etc to
|
|
|
|
export HOME=$NIX_BUILD_TOP/fake_home
|
|
|
|
|
|
|
|
# Make yarn install packages from our offline cache, not the registry
|
2022-10-06 18:32:54 +00:00
|
|
|
yarn config --offline set yarn-offline-mirror $yarnOfflineCache
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# Fixup "resolved"-entries in yarn.lock to match our offline cache
|
2024-01-02 11:29:13 +00:00
|
|
|
fixup-yarn-lock yarn.lock
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
yarn install --offline --frozen-lockfile --ignore-scripts --no-progress --non-interactive
|
|
|
|
|
|
|
|
patchShebangs node_modules/
|
2023-01-11 07:51:40 +00:00
|
|
|
patchShebangs scripts/frontend/
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
runHook postConfigure
|
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
bundle exec rake gitlab:assets:compile RAILS_ENV=production NODE_ENV=production SKIP_YARN_INSTALL=true
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
mv public/assets $out
|
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "gitlab${lib.optionalString gitlabEnterprise "-ee"}-${version}";
|
|
|
|
|
|
|
|
inherit src;
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2020-04-24 23:36:52 +00:00
|
|
|
buildInputs = [
|
2022-09-09 14:08:57 +00:00
|
|
|
rubyEnv rubyEnv.wrappedRuby rubyEnv.bundler tzdata git nettools
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
2021-04-17 00:35:05 +00:00
|
|
|
patches = [
|
|
|
|
# Change hardcoded paths to the NixOS equivalent
|
|
|
|
./remove-hardcoded-locations.patch
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
${lib.optionalString (!gitlabEnterprise) ''
|
|
|
|
# Remove all proprietary components
|
|
|
|
rm -rf ee
|
2021-06-28 23:13:55 +00:00
|
|
|
sed -i 's/-ee//' ./VERSION
|
2020-04-24 23:36:52 +00:00
|
|
|
''}
|
|
|
|
|
|
|
|
# For reasons I don't understand "bundle exec" ignores the
|
|
|
|
# RAILS_ENV causing tests to be executed that fail because we're
|
|
|
|
# not installing development and test gems above. Deleting the
|
|
|
|
# tests works though.
|
|
|
|
rm lib/tasks/test.rake
|
|
|
|
|
|
|
|
rm config/initializers/gitlab_shell_secret_token.rb
|
|
|
|
|
|
|
|
sed -i '/ask_to_continue/d' lib/tasks/gitlab/two_factor.rake
|
|
|
|
sed -ri -e '/log_level/a config.logger = Logger.new(STDERR)' config/environments/production.rb
|
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
mv config/puma.rb.example config/puma.rb
|
2020-04-24 23:36:52 +00:00
|
|
|
# Always require lib-files and application.rb through their store
|
|
|
|
# path, not their relative state directory path. This gets rid of
|
|
|
|
# warnings and means we don't have to link back to lib from the
|
|
|
|
# state directory.
|
2023-03-15 16:39:30 +00:00
|
|
|
${replace}/bin/replace-literal -f -r -e '../../lib' "$out/share/gitlab/lib" config
|
2020-04-24 23:36:52 +00:00
|
|
|
${replace}/bin/replace-literal -f -r -e '../lib' "$out/share/gitlab/lib" config
|
|
|
|
${replace}/bin/replace-literal -f -r -e "require_relative 'application'" "require_relative '$out/share/gitlab/config/application'" config
|
2023-11-16 04:20:00 +00:00
|
|
|
${replace}/bin/replace-literal -f -r -e 'require_relative "/home/git/gitlab/lib/gitlab/puma/error_handler"' "require_relative '$out/share/gitlab/lib/gitlab/puma/error_handler'" config
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
rm -f config/secrets.yml
|
|
|
|
mv config config.dist
|
|
|
|
rm -r tmp
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/share
|
|
|
|
cp -r . $out/share/gitlab
|
|
|
|
ln -sf ${assets} $out/share/gitlab/public/assets
|
|
|
|
rm -rf $out/share/gitlab/log
|
|
|
|
ln -sf /run/gitlab/log $out/share/gitlab/log
|
|
|
|
ln -sf /run/gitlab/uploads $out/share/gitlab/public/uploads
|
|
|
|
ln -sf /run/gitlab/config $out/share/gitlab/config
|
|
|
|
ln -sf /run/gitlab/tmp $out/share/gitlab/tmp
|
|
|
|
|
|
|
|
# rake tasks to mitigate CVE-2017-0882
|
|
|
|
# see https://about.gitlab.com/2017/03/20/gitlab-8-dot-17-dot-4-security-release/
|
|
|
|
cp ${./reset_token.rake} $out/share/gitlab/lib/tasks/reset_token.rake
|
2022-03-05 16:20:37 +00:00
|
|
|
|
|
|
|
# manually patch the shebang line in generate-loose-foreign-key
|
|
|
|
wrapProgram $out/share/gitlab/scripts/decomposition/generate-loose-foreign-key --set ENABLE_SPRING 0 --add-flags 'runner -e test'
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
inherit rubyEnv assets;
|
|
|
|
ruby = rubyEnv.wrappedRuby;
|
|
|
|
GITALY_SERVER_VERSION = data.passthru.GITALY_SERVER_VERSION;
|
|
|
|
GITLAB_PAGES_VERSION = data.passthru.GITLAB_PAGES_VERSION;
|
|
|
|
GITLAB_SHELL_VERSION = data.passthru.GITLAB_SHELL_VERSION;
|
|
|
|
GITLAB_WORKHORSE_VERSION = data.passthru.GITLAB_WORKHORSE_VERSION;
|
2021-06-28 23:13:55 +00:00
|
|
|
gitlabEnv.FOSS_ONLY = lib.boolToString (!gitlabEnterprise);
|
2020-04-24 23:36:52 +00:00
|
|
|
tests = {
|
|
|
|
nixos-test-passes = nixosTests.gitlab;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
homepage = "http://www.gitlab.com/";
|
|
|
|
platforms = platforms.linux;
|
2023-07-15 17:15:38 +00:00
|
|
|
maintainers = teams.gitlab.members;
|
2020-04-24 23:36:52 +00:00
|
|
|
} // (if gitlabEnterprise then
|
|
|
|
{
|
|
|
|
license = licenses.unfreeRedistributable; # https://gitlab.com/gitlab-org/gitlab-ee/raw/master/LICENSE
|
|
|
|
description = "GitLab Enterprise Edition";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
license = licenses.mit;
|
|
|
|
description = "GitLab Community Edition";
|
|
|
|
longDescription = "GitLab Community Edition (CE) is an open source end-to-end software development platform with built-in version control, issue tracking, code review, CI/CD, and more. Self-host GitLab CE on your own servers, in a container, or on a cloud provider.";
|
|
|
|
});
|
|
|
|
}
|