nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 fetchurl,
3 lib,
4 stdenv,
5 buildPackages,
6 curl,
7 openssl,
8 zlib-ng,
9 expat,
10 perlPackages,
11 python3,
12 gettext,
13 gnugrep,
14 gnused,
15 gawk,
16 coreutils, # needed at runtime by git-filter-branch etc
17 openssh,
18 pcre2,
19 bash,
20 asciidoc,
21 texinfo,
22 xmlto,
23 docbook2x,
24 docbook_xsl,
25 docbook_xml_dtd_45,
26 libxslt,
27 tcl,
28 tk,
29 makeWrapper,
30 libiconv,
31 libiconvReal,
32 svnSupport ? false,
33 subversionClient,
34 perlLibs,
35 smtpPerlLibs,
36 perlSupport ? stdenv.buildPlatform == stdenv.hostPlatform,
37 nlsSupport ? true,
38 osxkeychainSupport ? stdenv.hostPlatform.isDarwin,
39 guiSupport ? false,
40 # Disable the manual since libxslt doesn't seem to parse the files correctly.
41 withManual ? !stdenv.hostPlatform.useLLVM,
42 pythonSupport ? true,
43 withpcre2 ? true,
44 sendEmailSupport ? perlSupport,
45 nixosTests,
46 withLibsecret ? false,
47 pkg-config,
48 glib,
49 libsecret,
50 gzip, # needed at runtime by gitweb.cgi
51 withSsh ? false,
52 sysctl,
53 deterministic-host-uname, # trick Makefile into targeting the host platform when cross-compiling
54 doInstallCheck ? !stdenv.hostPlatform.isDarwin, # extremely slow on darwin
55 tests,
56}:
57
58assert osxkeychainSupport -> stdenv.hostPlatform.isDarwin;
59assert sendEmailSupport -> perlSupport;
60assert svnSupport -> perlSupport;
61
62let
63 version = "2.50.1";
64 svn = subversionClient.override { perlBindings = perlSupport; };
65 gitwebPerlLibs = with perlPackages; [
66 CGI
67 HTMLParser
68 CGIFast
69 FCGI
70 FCGIProcManager
71 HTMLTagCloud
72 ];
73in
74
75stdenv.mkDerivation (finalAttrs: {
76 pname =
77 "git"
78 + lib.optionalString svnSupport "-with-svn"
79 + lib.optionalString (
80 !svnSupport && !guiSupport && !sendEmailSupport && !withManual && !pythonSupport && !withpcre2
81 ) "-minimal";
82 inherit version;
83
84 src = fetchurl {
85 url =
86 if lib.strings.hasInfix "-rc" version then
87 "https://www.kernel.org/pub/software/scm/git/testing/git-${
88 builtins.replaceStrings [ "-" ] [ "." ] version
89 }.tar.xz"
90 else
91 "https://www.kernel.org/pub/software/scm/git/git-${version}.tar.xz";
92 hash = "sha256-fj5sNt7L2PHu3RTULbZnS+A2ccIgSGS++ipBdWxcj8Q=";
93 };
94
95 outputs = [ "out" ] ++ lib.optional withManual "doc";
96 separateDebugInfo = true;
97 __structuredAttrs = true;
98
99 hardeningDisable = [ "format" ];
100
101 enableParallelBuilding = true;
102 enableParallelInstalling = true;
103
104 patches = [
105 ./docbook2texi.patch
106 ./git-sh-i18n.patch
107 ./git-send-email-honor-PATH.patch
108 ./installCheck-path.patch
109 ]
110 ++ lib.optionals withSsh [
111 ./ssh-path.patch
112 ];
113
114 postPatch = ''
115 # Fix references to gettext introduced by ./git-sh-i18n.patch
116 substituteInPlace git-sh-i18n.sh \
117 --subst-var-by gettext ${gettext}
118 ''
119 + lib.optionalString doInstallCheck ''
120 # ensure we are using the correct shell when executing the test scripts
121 patchShebangs t/*.sh
122 ''
123 + lib.optionalString withSsh ''
124 for x in connect.c git-gui/lib/remote_add.tcl ; do
125 substituteInPlace "$x" \
126 --subst-var-by ssh "${openssh}/bin/ssh"
127 done
128 '';
129
130 nativeBuildInputs = [
131 deterministic-host-uname
132 gettext
133 perlPackages.perl
134 makeWrapper
135 pkg-config
136 ]
137 ++ lib.optionals withManual [
138 asciidoc
139 texinfo
140 xmlto
141 docbook2x
142 docbook_xsl
143 docbook_xml_dtd_45
144 libxslt
145 ];
146 buildInputs = [
147 curl
148 openssl
149 zlib-ng
150 expat
151 (if stdenv.hostPlatform.isFreeBSD then libiconvReal else libiconv)
152 bash
153 ]
154 ++ lib.optionals perlSupport [ perlPackages.perl ]
155 ++ lib.optionals guiSupport [
156 tcl
157 tk
158 ]
159 ++ lib.optionals withpcre2 [ pcre2 ]
160 ++ lib.optionals withLibsecret [
161 glib
162 libsecret
163 ];
164
165 # required to support pthread_cancel()
166 env.NIX_LDFLAGS =
167 lib.optionalString (stdenv.cc.isGNU && stdenv.hostPlatform.libc == "glibc") "-lgcc_s"
168 + lib.optionalString (stdenv.hostPlatform.isFreeBSD) "-lthr";
169
170 configureFlags = [
171 "ac_cv_prog_CURL_CONFIG=${lib.getDev curl}/bin/curl-config"
172 ]
173 ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
174 "ac_cv_fread_reads_directories=yes"
175 "ac_cv_snprintf_returns_bogus=no"
176 "ac_cv_iconv_omits_bom=no"
177 ];
178
179 preBuild = ''
180 makeFlagsArray+=( perllibdir=$out/$(perl -MConfig -wle 'print substr $Config{installsitelib}, 1 + length $Config{siteprefixexp}') )
181 '';
182
183 makeFlags = [
184 "prefix=\${out}"
185 "ZLIB_NG=1"
186 ]
187 # Git does not allow setting a shell separately for building and run-time.
188 # Therefore lets leave it at the default /bin/sh when cross-compiling
189 ++ lib.optional (stdenv.buildPlatform == stdenv.hostPlatform) "SHELL_PATH=${stdenv.shell}"
190 ++ (if perlSupport then [ "PERL_PATH=${perlPackages.perl}/bin/perl" ] else [ "NO_PERL=1" ])
191 ++ (if pythonSupport then [ "PYTHON_PATH=${python3}/bin/python" ] else [ "NO_PYTHON=1" ])
192 ++ lib.optionals stdenv.hostPlatform.isSunOS [
193 "INSTALL=install"
194 "NO_INET_NTOP="
195 "NO_INET_PTON="
196 ]
197 ++ (if stdenv.hostPlatform.isDarwin then [ "NO_APPLE_COMMON_CRYPTO=1" ] else [ "sysconfdir=/etc" ])
198 ++ lib.optionals stdenv.hostPlatform.isMusl [
199 "NO_SYS_POLL_H=1"
200 "NO_GETTEXT=YesPlease"
201 ]
202 ++ lib.optional withpcre2 "USE_LIBPCRE2=1"
203 ++ lib.optional (!nlsSupport) "NO_GETTEXT=1"
204 # git-gui refuses to start with the version of tk distributed with
205 # macOS Catalina. We can prevent git from building the .app bundle
206 # by specifying an invalid tk framework. The postInstall step will
207 # then ensure that git-gui uses tcl/tk from nixpkgs, which is an
208 # acceptable version.
209 #
210 # See https://github.com/Homebrew/homebrew-core/commit/dfa3ccf1e7d3901e371b5140b935839ba9d8b706
211 ++ lib.optional stdenv.hostPlatform.isDarwin "TKFRAMEWORK=/nonexistent";
212
213 disallowedReferences = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
214 stdenv.shellPackage
215 ];
216
217 postBuild = ''
218 # Set up the flags array for make in the same way as for the main build
219 # phase from stdenv.
220 local flagsArray=(
221 ''${enableParallelBuilding:+-j''${NIX_BUILD_CORES}}
222 SHELL="$SHELL"
223 )
224 concatTo flagsArray makeFlags makeFlagsArray buildFlags buildFlagsArray
225 echoCmd 'build flags' "''${flagsArray[@]}"
226 ''
227 + lib.optionalString withManual ''
228 # Need to build the main Git documentation before building the
229 # contrib/subtree documentation, as the latter depends on the
230 # asciidoc.conf file created by the former.
231 make -C Documentation PERL_PATH=${lib.getExe buildPackages.perlPackages.perl} "''${flagsArray[@]}"
232 ''
233 + ''
234 make -C contrib/subtree "''${flagsArray[@]}" all ${lib.optionalString withManual "doc"}
235 ''
236 + lib.optionalString perlSupport ''
237 make -C contrib/diff-highlight "''${flagsArray[@]}"
238 ''
239 + lib.optionalString osxkeychainSupport ''
240 make -C contrib/credential/osxkeychain "''${flagsArray[@]}"
241 ''
242 + lib.optionalString withLibsecret ''
243 make -C contrib/credential/libsecret "''${flagsArray[@]}"
244 ''
245 + ''
246 unset flagsArray
247 '';
248
249 ## Install
250
251 # WARNING: Do not `rm` or `mv` files from the source tree; use `cp` instead.
252 # We need many of these files during the installCheckPhase.
253
254 installFlags = [ "NO_INSTALL_HARDLINKS=1" ];
255
256 preInstall =
257 lib.optionalString osxkeychainSupport ''
258 mkdir -p $out/libexec/git-core
259 ln -s $out/share/git/contrib/credential/osxkeychain/git-credential-osxkeychain $out/libexec/git-core/
260
261 # ideally unneeded, but added for backwards compatibility
262 mkdir -p $out/bin
263 ln -s $out/libexec/git-core/git-credential-osxkeychain $out/bin/
264
265 rm -f $PWD/contrib/credential/osxkeychain/git-credential-osxkeychain.o
266 ''
267 + lib.optionalString withLibsecret ''
268 mkdir -p $out/libexec/git-core
269 ln -s $out/share/git/contrib/credential/libsecret/git-credential-libsecret $out/libexec/git-core/
270
271 # ideally unneeded, but added for backwards compatibility
272 mkdir -p $out/bin
273 ln -s $out/libexec/git-core/git-credential-libsecret $out/bin/
274
275 rm -f $PWD/contrib/credential/libsecret/git-credential-libsecret.o
276 '';
277
278 postInstall = ''
279 # Set up the flags array for make in the same way as for the main install
280 # phase from stdenv.
281 local flagsArray=(
282 ''${enableParallelInstalling:+-j''${NIX_BUILD_CORES}}
283 SHELL="$SHELL"
284 )
285 concatTo flagsArray makeFlags makeFlagsArray installFlags installFlagsArray
286 echoCmd 'install flags' "''${flagsArray[@]}"
287
288 # Install git-subtree.
289 make -C contrib/subtree "''${flagsArray[@]}" install ${lib.optionalString withManual "install-doc"}
290 rm -rf contrib/subtree
291
292 # Install contrib stuff.
293 mkdir -p $out/share/git
294 cp -a contrib $out/share/git/
295 mkdir -p $out/share/bash-completion/completions
296 ln -s $out/share/git/contrib/completion/git-prompt.sh $out/share/bash-completion/completions/
297 # only readme, developed in another repo
298 rm -r contrib/hooks/multimail
299 mkdir -p $out/share/git-core/contrib
300 cp -a contrib/hooks/ $out/share/git-core/contrib/
301 substituteInPlace $out/share/git-core/contrib/hooks/pre-auto-gc-battery \
302 --replace ' grep' ' ${gnugrep}/bin/grep' \
303
304 # grep is a runtime dependency, need to patch so that it's found
305 substituteInPlace $out/libexec/git-core/git-sh-setup \
306 --replace ' grep' ' ${gnugrep}/bin/grep' \
307 --replace ' egrep' ' ${gnugrep}/bin/egrep'
308
309 # Fix references to the perl, sed, awk and various coreutil binaries used by
310 # shell scripts that git calls (e.g. filter-branch)
311 SCRIPT="$(cat <<'EOS'
312 BEGIN{
313 @a=(
314 '${gnugrep}/bin/grep', '${gnused}/bin/sed', '${gawk}/bin/awk',
315 '${coreutils}/bin/cut', '${coreutils}/bin/basename', '${coreutils}/bin/dirname',
316 '${coreutils}/bin/wc', '${coreutils}/bin/tr'
317 ${lib.optionalString perlSupport ", '${perlPackages.perl}/bin/perl'"}
318 );
319 }
320 foreach $c (@a) {
321 $n=(split("/", $c))[-1];
322 s|(?<=[^#][^/.-])\b''${n}(?=\s)|''${c}|g
323 }
324 EOS
325 )"
326 perl -0777 -i -pe "$SCRIPT" \
327 $out/libexec/git-core/git-{sh-setup,filter-branch,merge-octopus,mergetool,quiltimport,request-pull,submodule,subtree,web--browse}
328
329
330 # Also put git-http-backend into $PATH, so that we can use smart
331 # HTTP(s) transports for pushing
332 ln -s $out/libexec/git-core/git-http-backend $out/bin/git-http-backend
333 ln -s $out/share/git/contrib/git-jump/git-jump $out/bin/git-jump
334 ''
335 + lib.optionalString perlSupport ''
336 # wrap perl commands
337 makeWrapper "$out/share/git/contrib/credential/netrc/git-credential-netrc.perl" $out/libexec/git-core/git-credential-netrc \
338 --set PERL5LIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}"
339 # ideally unneeded, but added for backwards compatibility
340 ln -s $out/libexec/git-core/git-credential-netrc $out/bin/
341
342 wrapProgram $out/libexec/git-core/git-cvsimport \
343 --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}"
344 wrapProgram $out/libexec/git-core/git-archimport \
345 --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}"
346 wrapProgram $out/libexec/git-core/git-instaweb \
347 --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}"
348 wrapProgram $out/libexec/git-core/git-cvsexportcommit \
349 --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}"
350
351 # gzip (and optionally bzip2, xz, zip) are runtime dependencies for
352 # gitweb.cgi, need to patch so that it's found
353 sed -i -e "s|'compressor' => \['gzip'|'compressor' => ['${gzip}/bin/gzip'|" \
354 $out/share/gitweb/gitweb.cgi
355 # Give access to CGI.pm and friends (was removed from perl core in 5.22)
356 for p in ${lib.concatStringsSep " " gitwebPerlLibs}; do
357 sed -i -e "/use CGI /i use lib \"$p/${perlPackages.perl.libPrefix}\";" \
358 "$out/share/gitweb/gitweb.cgi"
359 done
360 ''
361
362 + (
363 if svnSupport then
364 ''
365 # wrap git-svn
366 wrapProgram $out/libexec/git-core/git-svn \
367 --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${
368 perlPackages.makePerlPath (perlLibs ++ [ svn.out ])
369 }" \
370 --prefix PATH : "${svn.out}/bin"
371 ''
372 else
373 ''
374 rm $out/libexec/git-core/git-svn
375 ''
376 )
377
378 + (
379 if sendEmailSupport then
380 ''
381 # wrap git-send-email
382 wrapProgram $out/libexec/git-core/git-send-email \
383 --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath smtpPerlLibs}"
384 ''
385 else
386 ''
387 rm $out/libexec/git-core/git-send-email
388 ''
389 )
390
391 + lib.optionalString withManual ''
392 # Install man pages
393 make "''${flagsArray[@]}" install install-html \
394 -C Documentation
395 ''
396
397 + (
398 if guiSupport then
399 ''
400 # Wrap Tcl/Tk programs
401 for prog in bin/gitk libexec/git-core/{git-gui,git-citool,git-gui--askpass}; do
402 sed -i -e "s|exec 'wish'|exec '${tk}/bin/wish'|g" \
403 -e "s|exec wish|exec '${tk}/bin/wish'|g" \
404 "$out/$prog"
405 done
406 ln -s $out/share/git/contrib/completion/git-completion.bash $out/share/bash-completion/completions/gitk
407 ''
408 else
409 ''
410 for prog in bin/gitk libexec/git-core/git-gui; do
411 rm "$out/$prog"
412 done
413 ''
414 )
415 + lib.optionalString osxkeychainSupport ''
416 # enable git-credential-osxkeychain on darwin if desired (default)
417 mkdir -p $out/etc
418 cat > $out/etc/gitconfig << EOF
419 [credential]
420 helper = osxkeychain
421 EOF
422 ''
423 + ''
424 unset flagsArray
425 '';
426
427 ## InstallCheck
428
429 doCheck = false;
430 inherit doInstallCheck;
431
432 installCheckTarget = "test";
433
434 # see also installCheckFlagsArray
435 installCheckFlags = [
436 "DEFAULT_TEST_TARGET=prove"
437 "PERL_PATH=${buildPackages.perl}/bin/perl"
438 ];
439
440 nativeInstallCheckInputs = lib.optional (
441 stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isFreeBSD
442 ) sysctl;
443
444 preInstallCheck = ''
445 # Some tests break with high concurrency
446 # https://github.com/NixOS/nixpkgs/pull/403237
447 if ((NIX_BUILD_CORES > 32)); then
448 NIX_BUILD_CORES=32
449 fi
450
451 installCheckFlagsArray+=(
452 GIT_PROVE_OPTS="--jobs $NIX_BUILD_CORES --failures --state=failed,save"
453 GIT_TEST_INSTALLED=$out/bin
454 ${lib.optionalString (!svnSupport) "NO_SVN_TESTS=y"}
455 )
456
457 function disable_test {
458 local test=$1 pattern=$2
459 if [ $# -eq 1 ]; then
460 mv t/{,skip-}$test.sh || true
461 else
462 sed -i t/$test.sh \
463 -e "/^\s*test_expect_.*$pattern/,/^\s*' *\$/{s/^/: #/}"
464 fi
465 }
466
467 # Shared permissions are forbidden in sandbox builds:
468 substituteInPlace t/test-lib.sh \
469 --replace "test_set_prereq POSIXPERM" ""
470 # TODO: Investigate while these still fail (without POSIXPERM):
471 # Tested to fail: 2.46.0
472 disable_test t0001-init 'shared overrides system'
473 # Tested to fail: 2.46.0
474 disable_test t0001-init 'init honors global core.sharedRepository'
475 # Tested to fail: 2.46.0
476 disable_test t1301-shared-repo
477 # /build/git-2.44.0/contrib/completion/git-completion.bash: line 452: compgen: command not found
478 disable_test t9902-completion
479
480 # Our patched gettext never fallbacks
481 disable_test t0201-gettext-fallbacks
482 ''
483 + lib.optionalString (!sendEmailSupport) ''
484 # Disable sendmail tests
485 disable_test t9001-send-email
486 ''
487 + ''
488 # Flaky tests:
489 disable_test t0027-auto-crlf
490 disable_test t1451-fsck-buffer
491 disable_test t5319-multi-pack-index
492 disable_test t6421-merge-partial-clone
493 disable_test t7504-commit-msg-hook
494
495 # Fails reproducibly on ZFS on Linux with formD normalization
496 disable_test t0021-conversion
497 disable_test t3910-mac-os-precompose
498 ''
499 + lib.optionalString stdenv.hostPlatform.isDarwin ''
500 # XXX: Some tests added in 2.24.0 fail.
501 # Please try to re-enable on the next release.
502 disable_test t7816-grep-binary-pattern
503 # fail (as of 2.33.0)
504 #===( 18623;1208 8/? 224/? 2/? )= =fatal: Not a valid object name refs/tags/signed-empty
505 disable_test t6300-for-each-ref
506 # not ok 1 - populate workdir (with 2.33.1 on x86_64-darwin)
507 disable_test t5003-archive-zip
508 ''
509 + lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) ''
510 disable_test t7527-builtin-fsmonitor
511 ''
512 +
513 lib.optionalString (stdenv.hostPlatform.isStatic && stdenv.hostPlatform.system == "x86_64-linux")
514 ''
515 # https://github.com/NixOS/nixpkgs/pull/394957
516 # > t2082-parallel-checkout-attributes.sh (Wstat: 256 (exited 1) Tests: 5 Failed: 1)
517 disable_test t2082-parallel-checkout-attributes
518 ''
519 + lib.optionalString stdenv.hostPlatform.isMusl ''
520 # Test fails (as of 2.17.0, musl 1.1.19)
521 disable_test t3900-i18n-commit
522 # Fails largely due to assumptions about BOM
523 # Tested to fail: 2.18.0
524 disable_test t0028-working-tree-encoding
525 '';
526
527 stripDebugList = [
528 "lib"
529 "libexec"
530 "bin"
531 "share/git/contrib/credential/libsecret"
532 ];
533
534 passthru = {
535 shellPath = "/bin/git-shell";
536 tests = {
537 withInstallCheck = finalAttrs.finalPackage.overrideAttrs (_: {
538 doInstallCheck = true;
539 });
540 buildbot-integration = nixosTests.buildbot;
541 }
542 // tests.fetchgit;
543 updateScript = ./update.sh;
544 };
545
546 meta = {
547 homepage = "https://git-scm.com/";
548 description = "Distributed version control system";
549 license = lib.licenses.gpl2;
550 changelog = "https://github.com/git/git/blob/v${version}/Documentation/RelNotes/${version}.txt";
551
552 longDescription = ''
553 Git, a popular distributed version control system designed to
554 handle very large projects with speed and efficiency.
555 '';
556
557 platforms = lib.platforms.all;
558 maintainers = with lib.maintainers; [
559 wmertens
560 globin
561 kashw2
562 me-and
563 philiptaron
564 ];
565 mainProgram = "git";
566 };
567})