1 { fetchurl, fetchpatch, 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, libiconvReal
7 , svnSupport ? false, subversionClient, perlLibs, smtpPerlLibs
8 , perlSupport ? stdenv.buildPlatform == stdenv.hostPlatform
10 , osxkeychainSupport ? stdenv.hostPlatform.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.hostPlatform.isDarwin # extremely slow on darwin
27 assert osxkeychainSupport -> stdenv.hostPlatform.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-iIyvuL1qtMu+vBaAQKiFDrCI+B3DrCYXGVz8CHfw9UM=";
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 [
62 ] ++ lib.optionals (guiSupport && stdenv.hostPlatform.isDarwin) [
63 # Needed to workaround an issue in macOS where gitk shows a empty window
64 # https://github.com/Homebrew/homebrew-core/issues/68798
65 # https://github.com/git/git/pull/944
67 name = "gitk_check_main_window_visibility_before_waiting_for_it_to_show.patch";
68 url = "https://github.com/git/git/commit/1db62e44b7ec93b6654271ef34065b31496cd02e.patch";
69 hash = "sha256-ntvnrYFFsJ1Ebzc6vM9/AMFLHMS1THts73PIOG5DkQo=";
74 # Fix references to gettext introduced by ./git-sh-i18n.patch
75 substituteInPlace git-sh-i18n.sh \
76 --subst-var-by gettext ${gettext}
78 # ensure we are using the correct shell when executing the test scripts
80 '' + lib.optionalString withSsh ''
81 for x in connect.c git-gui/lib/remote_add.tcl ; do
82 substituteInPlace "$x" \
83 --subst-var-by ssh "${openssh}/bin/ssh"
87 nativeBuildInputs = [ gettext perlPackages.perl makeWrapper pkg-config ]
88 ++ lib.optionals withManual [ asciidoc texinfo xmlto docbook2x
89 docbook_xsl docbook_xml_dtd_45 libxslt ];
90 buildInputs = [ curl openssl zlib expat cpio (if stdenv.hostPlatform.isFreeBSD then libiconvReal else libiconv) bash ]
91 ++ lib.optionals perlSupport [ perlPackages.perl ]
92 ++ lib.optionals guiSupport [tcl tk]
93 ++ lib.optionals withpcre2 [ pcre2 ]
94 ++ lib.optionals stdenv.hostPlatform.isDarwin [ Security CoreServices ]
95 ++ lib.optionals withLibsecret [ glib libsecret ];
97 # required to support pthread_cancel()
98 NIX_LDFLAGS = lib.optionalString (stdenv.cc.isGNU && stdenv.hostPlatform.libc == "glibc") "-lgcc_s"
99 + lib.optionalString (stdenv.hostPlatform.isFreeBSD) "-lthr";
102 "ac_cv_prog_CURL_CONFIG=${lib.getDev curl}/bin/curl-config"
103 ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
104 "ac_cv_fread_reads_directories=yes"
105 "ac_cv_snprintf_returns_bogus=no"
106 "ac_cv_iconv_omits_bom=no"
110 makeFlagsArray+=( perllibdir=$out/$(perl -MConfig -wle 'print substr $Config{installsitelib}, 1 + length $Config{siteprefixexp}') )
116 # Git does not allow setting a shell separately for building and run-time.
117 # Therefore lets leave it at the default /bin/sh when cross-compiling
118 ++ lib.optional (stdenv.buildPlatform == stdenv.hostPlatform) "SHELL_PATH=${stdenv.shell}"
119 ++ (if perlSupport then ["PERL_PATH=${perlPackages.perl}/bin/perl"] else ["NO_PERL=1"])
120 ++ (if pythonSupport then ["PYTHON_PATH=${python3}/bin/python"] else ["NO_PYTHON=1"])
121 ++ lib.optionals stdenv.hostPlatform.isSunOS ["INSTALL=install" "NO_INET_NTOP=" "NO_INET_PTON="]
122 ++ (if stdenv.hostPlatform.isDarwin then ["NO_APPLE_COMMON_CRYPTO=1"] else ["sysconfdir=/etc"])
123 ++ lib.optionals stdenv.hostPlatform.isMusl ["NO_SYS_POLL_H=1" "NO_GETTEXT=YesPlease"]
124 ++ lib.optional withpcre2 "USE_LIBPCRE2=1"
125 ++ lib.optional (!nlsSupport) "NO_GETTEXT=1"
126 # git-gui refuses to start with the version of tk distributed with
127 # macOS Catalina. We can prevent git from building the .app bundle
128 # by specifying an invalid tk framework. The postInstall step will
129 # then ensure that git-gui uses tcl/tk from nixpkgs, which is an
130 # acceptable version.
132 # See https://github.com/Homebrew/homebrew-core/commit/dfa3ccf1e7d3901e371b5140b935839ba9d8b706
133 ++ lib.optional stdenv.hostPlatform.isDarwin "TKFRAMEWORK=/nonexistent"
134 ++ lib.optional (stdenv.hostPlatform.isFreeBSD && stdenv.hostPlatform != stdenv.buildPlatform) "uname_S=FreeBSD";
136 disallowedReferences = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
142 make -C contrib/subtree
143 '' + (lib.optionalString perlSupport ''
144 make -C contrib/diff-highlight
145 '') + (lib.optionalString osxkeychainSupport ''
146 make -C contrib/credential/osxkeychain
147 '') + (lib.optionalString withLibsecret ''
148 make -C contrib/credential/libsecret
154 # WARNING: Do not `rm` or `mv` files from the source tree; use `cp` instead.
155 # We need many of these files during the installCheckPhase.
157 installFlags = [ "NO_INSTALL_HARDLINKS=1" ];
159 preInstall = (lib.optionalString osxkeychainSupport ''
161 ln -s $out/share/git/contrib/credential/osxkeychain/git-credential-osxkeychain $out/bin/
162 rm -f $PWD/contrib/credential/osxkeychain/git-credential-osxkeychain.o
163 '') + (lib.optionalString withLibsecret ''
165 ln -s $out/share/git/contrib/credential/libsecret/git-credential-libsecret $out/bin/
166 rm -f $PWD/contrib/credential/libsecret/git-credential-libsecret.o
175 # Install git-subtree.
176 make -C contrib/subtree install ${lib.optionalString withManual "install-doc"}
177 rm -rf contrib/subtree
179 # Install contrib stuff.
180 mkdir -p $out/share/git
181 cp -a contrib $out/share/git/
182 mkdir -p $out/share/bash-completion/completions
183 ln -s $out/share/git/contrib/completion/git-completion.bash $out/share/bash-completion/completions/git
184 ln -s $out/share/git/contrib/completion/git-prompt.sh $out/share/bash-completion/completions/
185 # only readme, developed in another repo
186 rm -r contrib/hooks/multimail
187 mkdir -p $out/share/git-core/contrib
188 cp -a contrib/hooks/ $out/share/git-core/contrib/
189 substituteInPlace $out/share/git-core/contrib/hooks/pre-auto-gc-battery \
190 --replace ' grep' ' ${gnugrep}/bin/grep' \
192 # grep is a runtime dependency, need to patch so that it's found
193 substituteInPlace $out/libexec/git-core/git-sh-setup \
194 --replace ' grep' ' ${gnugrep}/bin/grep' \
195 --replace ' egrep' ' ${gnugrep}/bin/egrep'
197 # Fix references to the perl, sed, awk and various coreutil binaries used by
198 # shell scripts that git calls (e.g. filter-branch)
199 SCRIPT="$(cat <<'EOS'
202 '${gnugrep}/bin/grep', '${gnused}/bin/sed', '${gawk}/bin/awk',
203 '${coreutils}/bin/cut', '${coreutils}/bin/basename', '${coreutils}/bin/dirname',
204 '${coreutils}/bin/wc', '${coreutils}/bin/tr'
205 ${lib.optionalString perlSupport ", '${perlPackages.perl}/bin/perl'"}
209 $n=(split("/", $c))[-1];
210 s|(?<=[^#][^/.-])\b''${n}(?=\s)|''${c}|g
214 perl -0777 -i -pe "$SCRIPT" \
215 $out/libexec/git-core/git-{sh-setup,filter-branch,merge-octopus,mergetool,quiltimport,request-pull,submodule,subtree,web--browse}
218 # Also put git-http-backend into $PATH, so that we can use smart
219 # HTTP(s) transports for pushing
220 ln -s $out/libexec/git-core/git-http-backend $out/bin/git-http-backend
221 ln -s $out/share/git/contrib/git-jump/git-jump $out/bin/git-jump
222 '' + lib.optionalString perlSupport ''
224 makeWrapper "$out/share/git/contrib/credential/netrc/git-credential-netrc.perl" $out/bin/git-credential-netrc \
225 --set PERL5LIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}"
226 wrapProgram $out/libexec/git-core/git-cvsimport \
227 --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}"
228 wrapProgram $out/libexec/git-core/git-archimport \
229 --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}"
230 wrapProgram $out/libexec/git-core/git-instaweb \
231 --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}"
232 wrapProgram $out/libexec/git-core/git-cvsexportcommit \
233 --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath perlLibs}"
235 # gzip (and optionally bzip2, xz, zip) are runtime dependencies for
236 # gitweb.cgi, need to patch so that it's found
237 sed -i -e "s|'compressor' => \['gzip'|'compressor' => ['${gzip}/bin/gzip'|" \
238 $out/share/gitweb/gitweb.cgi
239 # Give access to CGI.pm and friends (was removed from perl core in 5.22)
240 for p in ${lib.concatStringsSep " " gitwebPerlLibs}; do
241 sed -i -e "/use CGI /i use lib \"$p/${perlPackages.perl.libPrefix}\";" \
242 "$out/share/gitweb/gitweb.cgi"
246 + (if svnSupport then ''
248 wrapProgram $out/libexec/git-core/git-svn \
249 --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath (perlLibs ++ [svn.out])}" \
250 --prefix PATH : "${svn.out}/bin" ''
251 else '' # replace git-svn by notification script
252 notSupported $out/libexec/git-core/git-svn
255 + (if sendEmailSupport then ''
256 # wrap git-send-email
257 wrapProgram $out/libexec/git-core/git-send-email \
258 --set GITPERLLIB "$out/${perlPackages.perl.libPrefix}:${perlPackages.makePerlPath smtpPerlLibs}"
260 # replace git-send-email by notification script
261 notSupported $out/libexec/git-core/git-send-email
264 + lib.optionalString withManual ''# Install man pages
265 make -j $NIX_BUILD_CORES PERL_PATH="${buildPackages.perl}/bin/perl" cmd-list.made install install-html \
268 + (if guiSupport then ''
269 # Wrap Tcl/Tk programs
270 for prog in bin/gitk libexec/git-core/{git-gui,git-citool,git-gui--askpass}; do
271 sed -i -e "s|exec 'wish'|exec '${tk}/bin/wish'|g" \
272 -e "s|exec wish|exec '${tk}/bin/wish'|g" \
275 ln -s $out/share/git/contrib/completion/git-completion.bash $out/share/bash-completion/completions/gitk
277 # Don't wrap Tcl/Tk, replace them by notification scripts
278 for prog in bin/gitk libexec/git-core/git-gui; do
279 notSupported "$out/$prog"
282 + lib.optionalString osxkeychainSupport ''
283 # enable git-credential-osxkeychain on darwin if desired (default)
285 cat > $out/etc/gitconfig << EOF
295 inherit doInstallCheck;
297 installCheckTarget = "test";
299 # see also installCheckFlagsArray
300 installCheckFlags = [
301 "DEFAULT_TEST_TARGET=prove"
302 "PERL_PATH=${buildPackages.perl}/bin/perl"
305 nativeInstallCheckInputs = lib.optional (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isFreeBSD) sysctl;
308 installCheckFlagsArray+=(
309 GIT_PROVE_OPTS="--jobs $NIX_BUILD_CORES --failures --state=failed,save"
310 GIT_TEST_INSTALLED=$out/bin
311 ${lib.optionalString (!svnSupport) "NO_SVN_TESTS=y"}
314 function disable_test {
315 local test=$1 pattern=$2
316 if [ $# -eq 1 ]; then
317 mv t/{,skip-}$test.sh || true
320 -e "/^\s*test_expect_.*$pattern/,/^\s*' *\$/{s/^/: #/}"
324 # Shared permissions are forbidden in sandbox builds:
325 substituteInPlace t/test-lib.sh \
326 --replace "test_set_prereq POSIXPERM" ""
327 # TODO: Investigate while these still fail (without POSIXPERM):
328 # Tested to fail: 2.46.0
329 disable_test t0001-init 'shared overrides system'
330 # Tested to fail: 2.46.0
331 disable_test t0001-init 'init honors global core.sharedRepository'
332 # Tested to fail: 2.46.0
333 disable_test t1301-shared-repo
334 # /build/git-2.44.0/contrib/completion/git-completion.bash: line 452: compgen: command not found
335 disable_test t9902-completion
337 # Our patched gettext never fallbacks
338 disable_test t0201-gettext-fallbacks
339 '' + lib.optionalString (!sendEmailSupport) ''
340 # Disable sendmail tests
341 disable_test t9001-send-email
344 disable_test t6421-merge-partial-clone
346 # Fails reproducibly on ZFS on Linux with formD normalization
347 disable_test t0021-conversion
348 disable_test t3910-mac-os-precompose
349 '' + lib.optionalString stdenv.hostPlatform.isDarwin ''
350 # XXX: Some tests added in 2.24.0 fail.
351 # Please try to re-enable on the next release.
352 disable_test t7816-grep-binary-pattern
353 # fail (as of 2.33.0)
354 #===( 18623;1208 8/? 224/? 2/? )= =fatal: Not a valid object name refs/tags/signed-empty
355 disable_test t6300-for-each-ref
356 # not ok 1 - populate workdir (with 2.33.1 on x86_64-darwin)
357 disable_test t5003-archive-zip
358 '' + lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) ''
359 disable_test t7527-builtin-fsmonitor
360 '' + lib.optionalString stdenv.hostPlatform.isMusl ''
361 # Test fails (as of 2.17.0, musl 1.1.19)
362 disable_test t3900-i18n-commit
363 # Fails largely due to assumptions about BOM
364 # Tested to fail: 2.18.0
365 disable_test t0028-working-tree-encoding
368 stripDebugList = [ "lib" "libexec" "bin" "share/git/contrib/credential/libsecret" ];
371 shellPath = "/bin/git-shell";
373 withInstallCheck = finalAttrs.finalPackage.overrideAttrs (_: {
374 doInstallCheck = true;
376 buildbot-integration = nixosTests.buildbot;
378 updateScript = ./update.sh;
382 homepage = "https://git-scm.com/";
383 description = "Distributed version control system";
384 license = lib.licenses.gpl2;
385 changelog = "https://github.com/git/git/blob/v${version}/Documentation/RelNotes/${version}.txt";
388 Git, a popular distributed version control system designed to
389 handle very large projects with speed and efficiency.
392 platforms = lib.platforms.all;
393 maintainers = with lib.maintainers; [ primeos wmertens globin kashw2 ];