at 24.11-pre 394 lines 16 kB view raw
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 4, openssh, pcre2, bash 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 9, nlsSupport ? true 10, osxkeychainSupport ? stdenv.isDarwin 11, guiSupport ? false 12, withManual ? true 13, pythonSupport ? true 14, withpcre2 ? true 15, sendEmailSupport ? perlSupport 16, Security, CoreServices 17, nixosTests 18, withLibsecret ? false 19, pkg-config, glib, libsecret 20, gzip # needed at runtime by gitweb.cgi 21, withSsh ? false 22, sysctl 23, doInstallCheck ? !stdenv.isDarwin # extremely slow on darwin 24, tests 25}: 26 27assert osxkeychainSupport -> stdenv.isDarwin; 28assert sendEmailSupport -> perlSupport; 29assert svnSupport -> perlSupport; 30 31let 32 version = "2.44.1"; 33 svn = subversionClient.override { perlBindings = perlSupport; }; 34 gitwebPerlLibs = with perlPackages; [ CGI HTMLParser CGIFast FCGI FCGIProcManager HTMLTagCloud ]; 35in 36 37stdenv.mkDerivation (finalAttrs: { 38 pname = "git" 39 + lib.optionalString svnSupport "-with-svn" 40 + lib.optionalString (!svnSupport && !guiSupport && !sendEmailSupport && !withManual && !pythonSupport && !withpcre2) "-minimal"; 41 inherit version; 42 43 src = fetchurl { 44 url = "https://www.kernel.org/pub/software/scm/git/git-${version}.tar.xz"; 45 hash = "sha256-e2CmJMD3AJoWuFYlBiGq/c3YXrjUS7AgYXtlJbhyYeQ="; 46 }; 47 48 outputs = [ "out" ] ++ lib.optional withManual "doc"; 49 separateDebugInfo = true; 50 51 hardeningDisable = [ "format" ]; 52 53 enableParallelBuilding = true; 54 55 patches = [ 56 ./docbook2texi.patch 57 ./git-sh-i18n.patch 58 ./git-send-email-honor-PATH.patch 59 ./installCheck-path.patch 60 ] ++ lib.optionals withSsh [ 61 ./ssh-path.patch 62 ]; 63 64 postPatch = '' 65 # Fix references to gettext introduced by ./git-sh-i18n.patch 66 substituteInPlace git-sh-i18n.sh \ 67 --subst-var-by gettext ${gettext} 68 69 # ensure we are using the correct shell when executing the test scripts 70 patchShebangs t/*.sh 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" 75 done 76 ''; 77 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 ]; 87 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"; 91 92 configureFlags = [ 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" 98 ]; 99 100 preBuild = '' 101 makeFlagsArray+=( perllibdir=$out/$(perl -MConfig -wle 'print substr $Config{installsitelib}, 1 + length $Config{siteprefixexp}') ) 102 ''; 103 104 makeFlags = [ 105 "prefix=\${out}" 106 ] 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. 122 # 123 # See https://github.com/Homebrew/homebrew-core/commit/dfa3ccf1e7d3901e371b5140b935839ba9d8b706 124 ++ lib.optional stdenv.isDarwin "TKFRAMEWORK=/nonexistent"; 125 126 disallowedReferences = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ 127 stdenv.shellPackage 128 ]; 129 130 131 postBuild = '' 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 139 ''); 140 141 142 ## Install 143 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. 146 147 installFlags = [ "NO_INSTALL_HARDLINKS=1" ]; 148 149 preInstall = (lib.optionalString osxkeychainSupport '' 150 mkdir -p $out/bin 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 '' 154 mkdir -p $out/bin 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 157 ''); 158 159 postInstall = 160 '' 161 notSupported() { 162 unlink $1 || true 163 } 164 165 # Install git-subtree. 166 make -C contrib/subtree install ${lib.optionalString withManual "install-doc"} 167 rm -rf contrib/subtree 168 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' \ 181 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' 186 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' 190 BEGIN{ 191 @a=( 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'"} 196 ); 197 } 198 foreach $c (@a) { 199 $n=(split("/", $c))[-1]; 200 s|(?<=[^#][^/.-])\b''${n}(?=\s)|''${c}|g 201 } 202 EOS 203 )" 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} 206 207 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 '' 213 # wrap perl commands 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}" 224 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" 233 done 234 '' 235 236 + (if svnSupport then '' 237 # wrap git-svn 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 243 '') 244 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}" 249 '' else '' 250 # replace git-send-email by notification script 251 notSupported $out/libexec/git-core/git-send-email 252 '') 253 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 \ 256 -C Documentation '' 257 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" \ 263 "$out/$prog" 264 done 265 ln -s $out/share/git/contrib/completion/git-completion.bash $out/share/bash-completion/completions/gitk 266 '' else '' 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" 270 done 271 '') 272 + lib.optionalString osxkeychainSupport '' 273 # enable git-credential-osxkeychain on darwin if desired (default) 274 mkdir -p $out/etc 275 cat > $out/etc/gitconfig << EOF 276 [credential] 277 helper = osxkeychain 278 EOF 279 ''; 280 281 282 ## InstallCheck 283 284 doCheck = false; 285 inherit doInstallCheck; 286 287 installCheckTarget = "test"; 288 289 # see also installCheckFlagsArray 290 installCheckFlags = [ 291 "DEFAULT_TEST_TARGET=prove" 292 "PERL_PATH=${buildPackages.perl}/bin/perl" 293 ]; 294 295 nativeInstallCheckInputs = lib.optional stdenv.isDarwin sysctl; 296 297 preInstallCheck = '' 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"} 302 ) 303 304 function disable_test { 305 local test=$1 pattern=$2 306 if [ $# -eq 1 ]; then 307 mv t/{,skip-}$test.sh || true 308 else 309 sed -i t/$test.sh \ 310 -e "/^\s*test_expect_.*$pattern/,/^\s*' *\$/{s/^/: #/}" 311 fi 312 } 313 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 323 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 329 '' + '' 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" 334 335 # Flaky tests: 336 disable_test t5319-multi-pack-index 337 disable_test t6421-merge-partial-clone 338 339 # Fails reproducibly on ZFS on Linux with formD normalization 340 disable_test t0021-conversion 341 disable_test t3910-mac-os-precompose 342 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 365 ''; 366 367 stripDebugList = [ "lib" "libexec" "bin" "share/git/contrib/credential/libsecret" ]; 368 369 passthru = { 370 shellPath = "/bin/git-shell"; 371 tests = { 372 withInstallCheck = finalAttrs.finalPackage.overrideAttrs (_: { 373 doInstallCheck = true; 374 }); 375 buildbot-integration = nixosTests.buildbot; 376 } // tests.fetchgit; 377 }; 378 379 meta = { 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"; 384 385 longDescription = '' 386 Git, a popular distributed version control system designed to 387 handle very large projects with speed and efficiency. 388 ''; 389 390 platforms = lib.platforms.all; 391 maintainers = with lib.maintainers; [ primeos wmertens globin kashw2 ]; 392 mainProgram = "git"; 393 }; 394})