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