1 { fetchurl, lib, stdenv, buildPackages
2 , curl, openssl, zlib, expat, perlPackages, python3, gettext, cpio
3 , gnugrep, gnused, gawk, coreutils # needed at runtime by git-filter-branch etc
5 , asciidoc, texinfo, xmlto, docbook2x, docbook_xsl, docbook_xml_dtd_45
6 , libxslt, tcl, tk, makeWrapper, libiconv
7 , svnSupport ? false, subversionClient, perlLibs, smtpPerlLibs
8 , perlSupport ? stdenv.buildPlatform == stdenv.hostPlatform
10 , osxkeychainSupport ? stdenv.isDarwin
13 , pythonSupport ? true
15 , sendEmailSupport ? perlSupport
16 , Security, CoreServices
18 , withLibsecret ? false
19 , pkg-config, glib, libsecret
20 , gzip # needed at runtime by gitweb.cgi
23 , doInstallCheck ? !stdenv.isDarwin # extremely slow on darwin
27 assert osxkeychainSupport -> stdenv.isDarwin;
28 assert sendEmailSupport -> perlSupport;
29 assert svnSupport -> perlSupport;
33 svn = subversionClient.override { perlBindings = perlSupport; };
34 gitwebPerlLibs = with perlPackages; [ CGI HTMLParser CGIFast FCGI FCGIProcManager HTMLTagCloud ];
37 stdenv.mkDerivation (finalAttrs: {
39 + lib.optionalString svnSupport "-with-svn"
40 + lib.optionalString (!svnSupport && !guiSupport && !sendEmailSupport && !withManual && !pythonSupport && !withpcre2) "-minimal";
44 url = "https://www.kernel.org/pub/software/scm/git/git-${version}.tar.xz";
45 hash = "sha256-41hzjctbXqNAzpAKABXAOuhugE5/9k5HqkYx3e5oHeM=";
48 outputs = [ "out" ] ++ lib.optional withManual "doc";
49 separateDebugInfo = true;
51 hardeningDisable = [ "format" ];
53 enableParallelBuilding = true;
58 ./git-send-email-honor-PATH.patch
59 ./installCheck-path.patch
60 ] ++ lib.optionals withSsh [
65 # Fix references to gettext introduced by ./git-sh-i18n.patch
66 substituteInPlace git-sh-i18n.sh \
67 --subst-var-by gettext ${gettext}
69 # ensure we are using the correct shell when executing the test scripts
71 '' + lib.optionalString withSsh ''
72 for x in connect.c git-gui/lib/remote_add.tcl ; do
73 substituteInPlace "$x" \
74 --subst-var-by ssh "${openssh}/bin/ssh"
78 nativeBuildInputs = [ gettext perlPackages.perl makeWrapper pkg-config ]
79 ++ lib.optionals withManual [ asciidoc texinfo xmlto docbook2x
80 docbook_xsl docbook_xml_dtd_45 libxslt ];
81 buildInputs = [ curl openssl zlib expat cpio libiconv bash ]
82 ++ lib.optionals perlSupport [ perlPackages.perl ]
83 ++ lib.optionals guiSupport [tcl tk]
84 ++ lib.optionals withpcre2 [ pcre2 ]
85 ++ lib.optionals stdenv.isDarwin [ Security CoreServices ]
86 ++ lib.optionals withLibsecret [ glib libsecret ];
88 # required to support pthread_cancel()
89 NIX_LDFLAGS = lib.optionalString (stdenv.cc.isGNU && stdenv.hostPlatform.libc == "glibc") "-lgcc_s"
90 + lib.optionalString (stdenv.isFreeBSD) "-lthr";
93 "ac_cv_prog_CURL_CONFIG=${lib.getDev curl}/bin/curl-config"
94 ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
95 "ac_cv_fread_reads_directories=yes"
96 "ac_cv_snprintf_returns_bogus=no"
97 "ac_cv_iconv_omits_bom=no"
101 makeFlagsArray+=( perllibdir=$out/$(perl -MConfig -wle 'print substr $Config{installsitelib}, 1 + length $Config{siteprefixexp}') )
107 # Git does not allow setting a shell separately for building and run-time.
108 # Therefore lets leave it at the default /bin/sh when cross-compiling
109 ++ lib.optional (stdenv.buildPlatform == stdenv.hostPlatform) "SHELL_PATH=${stdenv.shell}"
110 ++ (if perlSupport then ["PERL_PATH=${perlPackages.perl}/bin/perl"] else ["NO_PERL=1"])
111 ++ (if pythonSupport then ["PYTHON_PATH=${python3}/bin/python"] else ["NO_PYTHON=1"])
112 ++ lib.optionals stdenv.isSunOS ["INSTALL=install" "NO_INET_NTOP=" "NO_INET_PTON="]
113 ++ (if stdenv.isDarwin then ["NO_APPLE_COMMON_CRYPTO=1"] else ["sysconfdir=/etc"])
114 ++ lib.optionals stdenv.hostPlatform.isMusl ["NO_SYS_POLL_H=1" "NO_GETTEXT=YesPlease"]
115 ++ lib.optional withpcre2 "USE_LIBPCRE2=1"
116 ++ lib.optional (!nlsSupport) "NO_GETTEXT=1"
117 # git-gui refuses to start with the version of tk distributed with
118 # macOS Catalina. We can prevent git from building the .app bundle
119 # by specifying an invalid tk framework. The postInstall step will
120 # then ensure that git-gui uses tcl/tk from nixpkgs, which is an
121 # acceptable version.
123 # See https://github.com/Homebrew/homebrew-core/commit/dfa3ccf1e7d3901e371b5140b935839ba9d8b706
124 ++ lib.optional stdenv.isDarwin "TKFRAMEWORK=/nonexistent";
126 disallowedReferences = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
132 make -C contrib/subtree
133 '' + (lib.optionalString perlSupport ''
134 make -C contrib/diff-highlight
135 '') + (lib.optionalString osxkeychainSupport ''
136 make -C contrib/credential/osxkeychain
137 '') + (lib.optionalString withLibsecret ''
138 make -C contrib/credential/libsecret
144 # WARNING: Do not `rm` or `mv` files from the source tree; use `cp` instead.
145 # We need many of these files during the installCheckPhase.
147 installFlags = [ "NO_INSTALL_HARDLINKS=1" ];
149 preInstall = (lib.optionalString osxkeychainSupport ''
151 ln -s $out/share/git/contrib/credential/osxkeychain/git-credential-osxkeychain $out/bin/
152 rm -f $PWD/contrib/credential/osxkeychain/git-credential-osxkeychain.o
153 '') + (lib.optionalString withLibsecret ''
155 ln -s $out/share/git/contrib/credential/libsecret/git-credential-libsecret $out/bin/
156 rm -f $PWD/contrib/credential/libsecret/git-credential-libsecret.o
165 # Install git-subtree.
166 make -C contrib/subtree install ${lib.optionalString withManual "install-doc"}
167 rm -rf contrib/subtree
169 # Install contrib stuff.
170 mkdir -p $out/share/git
171 cp -a contrib $out/share/git/
172 mkdir -p $out/share/bash-completion/completions
173 ln -s $out/share/git/contrib/completion/git-completion.bash $out/share/bash-completion/completions/git
174 ln -s $out/share/git/contrib/completion/git-prompt.sh $out/share/bash-completion/completions/
175 # only readme, developed in another repo
176 rm -r contrib/hooks/multimail
177 mkdir -p $out/share/git-core/contrib
178 cp -a contrib/hooks/ $out/share/git-core/contrib/
179 substituteInPlace $out/share/git-core/contrib/hooks/pre-auto-gc-battery \
180 --replace ' grep' ' ${gnugrep}/bin/grep' \
182 # grep is a runtime dependency, need to patch so that it's found
183 substituteInPlace $out/libexec/git-core/git-sh-setup \
184 --replace ' grep' ' ${gnugrep}/bin/grep' \
185 --replace ' egrep' ' ${gnugrep}/bin/egrep'
187 # Fix references to the perl, sed, awk and various coreutil binaries used by
188 # shell scripts that git calls (e.g. filter-branch)
189 SCRIPT="$(cat <<'EOS'
192 '${gnugrep}/bin/grep', '${gnused}/bin/sed', '${gawk}/bin/awk',
193 '${coreutils}/bin/cut', '${coreutils}/bin/basename', '${coreutils}/bin/dirname',
194 '${coreutils}/bin/wc', '${coreutils}/bin/tr'
195 ${lib.optionalString perlSupport ", '${perlPackages.perl}/bin/perl'"}
199 $n=(split("/", $c))[-1];
200 s|(?<=[^#][^/.-])\b''${n}(?=\s)|''${c}|g
204 perl -0777 -i -pe "$SCRIPT" \
205 $out/libexec/git-core/git-{sh-setup,filter-branch,merge-octopus,mergetool,quiltimport,request-pull,submodule,subtree,web--browse}
208 # Also put git-http-backend into $PATH, so that we can use smart
209 # HTTP(s) transports for pushing
210 ln -s $out/libexec/git-core/git-http-backend $out/bin/git-http-backend
211 ln -s $out/share/git/contrib/git-jump/git-jump $out/bin/git-jump
212 '' + lib.optionalString perlSupport ''
214 makeWrapper "$out/share/git/contrib/credential/netrc/git-credential-netrc.perl" $out/bin/git-credential-netrc \
215 --set PERL5LIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}"
216 wrapProgram $out/libexec/git-core/git-cvsimport \
217 --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}"
218 wrapProgram $out/libexec/git-core/git-archimport \
219 --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}"
220 wrapProgram $out/libexec/git-core/git-instaweb \
221 --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}"
222 wrapProgram $out/libexec/git-core/git-cvsexportcommit \
223 --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}"
225 # gzip (and optionally bzip2, xz, zip) are runtime dependencies for
226 # gitweb.cgi, need to patch so that it's found
227 sed -i -e "s|'compressor' => \['gzip'|'compressor' => ['${gzip}/bin/gzip'|" \
228 $out/share/gitweb/gitweb.cgi
229 # Give access to CGI.pm and friends (was removed from perl core in 5.22)
230 for p in ${lib.concatStringsSep " " gitwebPerlLibs}; do
231 sed -i -e "/use CGI /i use lib \"$p/${perlPackages.perl.libPrefix}\";" \
232 "$out/share/gitweb/gitweb.cgi"
236 + (if svnSupport then ''
238 wrapProgram $out/libexec/git-core/git-svn \
239 --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath (perlLibs ++ [svn.out])}" \
240 --prefix PATH : "${svn.out}/bin" ''
241 else '' # replace git-svn by notification script
242 notSupported $out/libexec/git-core/git-svn
245 + (if sendEmailSupport then ''
246 # wrap git-send-email
247 wrapProgram $out/libexec/git-core/git-send-email \
248 --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath smtpPerlLibs}"
250 # replace git-send-email by notification script
251 notSupported $out/libexec/git-core/git-send-email
254 + lib.optionalString withManual ''# Install man pages
255 make -j $NIX_BUILD_CORES PERL_PATH="${buildPackages.perl}/bin/perl" cmd-list.made install install-html \
258 + (if guiSupport then ''
259 # Wrap Tcl/Tk programs
260 for prog in bin/gitk libexec/git-core/{git-gui,git-citool,git-gui--askpass}; do
261 sed -i -e "s|exec 'wish'|exec '${tk}/bin/wish'|g" \
262 -e "s|exec wish|exec '${tk}/bin/wish'|g" \
265 ln -s $out/share/git/contrib/completion/git-completion.bash $out/share/bash-completion/completions/gitk
267 # Don't wrap Tcl/Tk, replace them by notification scripts
268 for prog in bin/gitk libexec/git-core/git-gui; do
269 notSupported "$out/$prog"
272 + lib.optionalString osxkeychainSupport ''
273 # enable git-credential-osxkeychain on darwin if desired (default)
275 cat > $out/etc/gitconfig << EOF
285 inherit doInstallCheck;
287 installCheckTarget = "test";
289 # see also installCheckFlagsArray
290 installCheckFlags = [
291 "DEFAULT_TEST_TARGET=prove"
292 "PERL_PATH=${buildPackages.perl}/bin/perl"
295 nativeInstallCheckInputs = lib.optional stdenv.isDarwin sysctl;
298 installCheckFlagsArray+=(
299 GIT_PROVE_OPTS="--jobs $NIX_BUILD_CORES --failures --state=failed,save"
300 GIT_TEST_INSTALLED=$out/bin
301 ${lib.optionalString (!svnSupport) "NO_SVN_TESTS=y"}
304 function disable_test {
305 local test=$1 pattern=$2
306 if [ $# -eq 1 ]; then
307 mv t/{,skip-}$test.sh || true
310 -e "/^\s*test_expect_.*$pattern/,/^\s*' *\$/{s/^/: #/}"
314 # Shared permissions are forbidden in sandbox builds:
315 substituteInPlace t/test-lib.sh \
316 --replace "test_set_prereq POSIXPERM" ""
317 # TODO: Investigate while these still fail (without POSIXPERM):
318 disable_test t0001-init 'shared overrides system'
319 disable_test t0001-init 'init honors global core.sharedRepository'
320 disable_test t1301-shared-repo
321 # /build/git-2.44.0/contrib/completion/git-completion.bash: line 452: compgen: command not found
322 disable_test t9902-completion
324 # Our patched gettext never fallbacks
325 disable_test t0201-gettext-fallbacks
326 '' + lib.optionalString (!sendEmailSupport) ''
327 # Disable sendmail tests
328 disable_test t9001-send-email
330 # XXX: I failed to understand why this one fails.
331 # Could someone try to re-enable it on the next release ?
332 # Tested to fail: 2.18.0 and 2.19.0
333 disable_test t1700-split-index "null sha1"
336 disable_test t5319-multi-pack-index
337 disable_test t6421-merge-partial-clone
339 # Fails reproducibly on ZFS on Linux with formD normalization
340 disable_test t0021-conversion
341 disable_test t3910-mac-os-precompose
343 '' + lib.optionalString (!perlSupport) ''
344 # request-pull is a Bash script that invokes Perl, so it is not available
345 # when NO_PERL=1, and the test should be skipped, but the test suite does
346 # not check for the Perl prerequisite.
347 disable_test t5150-request-pull
348 '' + lib.optionalString stdenv.isDarwin ''
349 # XXX: Some tests added in 2.24.0 fail.
350 # Please try to re-enable on the next release.
351 disable_test t7816-grep-binary-pattern
352 # fail (as of 2.33.0)
353 #===( 18623;1208 8/? 224/? 2/? )= =fatal: Not a valid object name refs/tags/signed-empty
354 disable_test t6300-for-each-ref
355 # not ok 1 - populate workdir (with 2.33.1 on x86_64-darwin)
356 disable_test t5003-archive-zip
357 '' + lib.optionalString (stdenv.isDarwin && stdenv.isAarch64) ''
358 disable_test t7527-builtin-fsmonitor
359 '' + lib.optionalString stdenv.hostPlatform.isMusl ''
360 # Test fails (as of 2.17.0, musl 1.1.19)
361 disable_test t3900-i18n-commit
362 # Fails largely due to assumptions about BOM
363 # Tested to fail: 2.18.0
364 disable_test t0028-working-tree-encoding
367 stripDebugList = [ "lib" "libexec" "bin" "share/git/contrib/credential/libsecret" ];
370 shellPath = "/bin/git-shell";
372 withInstallCheck = finalAttrs.finalPackage.overrideAttrs (_: {
373 doInstallCheck = true;
375 buildbot-integration = nixosTests.buildbot;
380 homepage = "https://git-scm.com/";
381 description = "Distributed version control system";
382 license = lib.licenses.gpl2;
383 changelog = "https://github.com/git/git/blob/v${version}/Documentation/RelNotes/${version}.txt";
386 Git, a popular distributed version control system designed to
387 handle very large projects with speed and efficiency.
390 platforms = lib.platforms.all;
391 maintainers = with lib.maintainers; [ primeos wmertens globin kashw2 ];