2021-01-17 00:15:33 +00:00
{ fetchurl , lib , stdenv , buildPackages
2020-04-24 23:36:52 +00:00
, curl , openssl , zlib , expat , perlPackages , python3 , gettext , cpio
, gnugrep , gnused , gawk , coreutils # needed at runtime by git-filter-branch etc
2021-12-06 16:07:01 +00:00
, openssh , pcre2 , bash
2021-06-28 23:13:55 +00:00
, asciidoc , texinfo , xmlto , docbook2x , docbook_xsl , docbook_xml_dtd_45
2020-04-24 23:36:52 +00:00
, libxslt , tcl , tk , makeWrapper , libiconv
, svnSupport , subversionClient , perlLibs , smtpPerlLibs
2021-05-28 09:39:13 +00:00
, perlSupport ? stdenv . buildPlatform == stdenv . hostPlatform
2020-08-20 17:08:02 +00:00
, nlsSupport ? true
2021-03-09 03:18:52 +00:00
, osxkeychainSupport ? stdenv . isDarwin
2020-04-24 23:36:52 +00:00
, guiSupport
, withManual ? true
, pythonSupport ? true
, withpcre2 ? true
, sendEmailSupport
, darwin
2021-05-20 23:08:51 +00:00
, nixosTests
2020-04-24 23:36:52 +00:00
, withLibsecret ? false
2021-02-05 17:12:51 +00:00
, pkg-config , glib , libsecret
2020-04-24 23:36:52 +00:00
, gzip # needed at runtime by gitweb.cgi
} :
2021-03-09 03:18:52 +00:00
assert osxkeychainSupport -> stdenv . isDarwin ;
2020-04-24 23:36:52 +00:00
assert sendEmailSupport -> perlSupport ;
assert svnSupport -> perlSupport ;
let
2022-02-10 20:34:41 +00:00
version = " 2 . 3 5 . 1 " ;
2020-04-24 23:36:52 +00:00
svn = subversionClient . override { perlBindings = perlSupport ; } ;
gitwebPerlLibs = with perlPackages ; [ CGI HTMLParser CGIFast FCGI FCGIProcManager HTMLTagCloud ] ;
in
stdenv . mkDerivation {
pname = " g i t " ;
inherit version ;
src = fetchurl {
url = " h t t p s : / / w w w . k e r n e l . o r g / p u b / s o f t w a r e / s c m / g i t / g i t - ${ version } . t a r . x z " ;
2022-02-10 20:34:41 +00:00
sha256 = " 1 0 0 h 3 7 c p w 4 9 p m l p f 6 l c p m 1 x i 5 7 8 g l l f 6 y 9 i n 6 0 h 5 m x j 3 c j 7 5 4 s 6 p " ;
2020-04-24 23:36:52 +00:00
} ;
2021-01-17 00:15:33 +00:00
outputs = [ " o u t " ] ++ lib . optional withManual " d o c " ;
2020-04-24 23:36:52 +00:00
hardeningDisable = [ " f o r m a t " ] ;
enableParallelBuilding = true ;
## Patch
patches = [
./docbook2texi.patch
./git-sh-i18n.patch
./ssh-path.patch
./git-send-email-honor-PATH.patch
./installCheck-path.patch
] ;
postPatch = ''
for x in connect . c git-gui/lib/remote_add.tcl ; do
substituteInPlace " $ x " \
- - subst-var-by ssh " ${ openssh } / b i n / s s h "
done
# Fix references to gettext introduced by ./git-sh-i18n.patch
substituteInPlace git-sh-i18n . sh \
- - subst-var-by gettext $ { gettext }
2021-09-26 12:46:18 +00:00
# ensure we are using the correct shell when executing the test scripts
patchShebangs t /* . s h
2020-04-24 23:36:52 +00:00
'' ;
2021-03-09 03:18:52 +00:00
nativeBuildInputs = [ gettext perlPackages . perl makeWrapper ]
2021-06-28 23:13:55 +00:00
++ lib . optionals withManual [ asciidoc texinfo xmlto docbook2x
docbook_xsl docbook_xml_dtd_45 libxslt ] ;
2021-12-06 16:07:01 +00:00
buildInputs = [ curl openssl zlib expat cpio libiconv bash ]
2021-01-17 00:15:33 +00:00
++ lib . optionals perlSupport [ perlPackages . perl ]
++ lib . optionals guiSupport [ tcl tk ]
++ lib . optionals withpcre2 [ pcre2 ]
++ lib . optionals stdenv . isDarwin [ darwin . Security ]
2021-02-05 17:12:51 +00:00
++ lib . optionals withLibsecret [ pkg-config glib libsecret ] ;
2020-04-24 23:36:52 +00:00
# required to support pthread_cancel()
2021-06-28 23:13:55 +00:00
NIX_LDFLAGS = lib . optionalString ( stdenv . cc . isGNU && stdenv . hostPlatform . libc == " g l i b c " ) " - l g c c _ s "
2021-01-17 00:15:33 +00:00
+ lib . optionalString ( stdenv . isFreeBSD ) " - l t h r " ;
2020-04-24 23:36:52 +00:00
2021-12-06 16:07:01 +00:00
configureFlags = [
" a c _ c v _ p r o g _ C U R L _ C O N F I G = ${ lib . getDev curl } / b i n / c u r l - c o n f i g "
] ++ lib . optionals ( stdenv . buildPlatform != stdenv . hostPlatform ) [
2020-04-24 23:36:52 +00:00
" a c _ c v _ f r e a d _ r e a d s _ d i r e c t o r i e s = y e s "
" a c _ c v _ s n p r i n t f _ r e t u r n s _ b o g u s = n o "
" a c _ c v _ i c o n v _ o m i t s _ b o m = n o "
] ;
preBuild = ''
makeFlagsArray + = ( perllibdir = $ out / $ ( perl - MConfig - wle ' print substr $ Config { installsitelib } , 1 + length $ Config { siteprefixexp } ' ) )
'' ;
makeFlags = [
" p r e f i x = \$ { o u t } "
]
2021-12-06 16:07:01 +00:00
# Git does not allow setting a shell separately for building and run-time.
# Therefore lets leave it at the default /bin/sh when cross-compiling
++ lib . optional ( stdenv . buildPlatform == stdenv . hostPlatform ) " S H E L L _ P A T H = ${ stdenv . shell } "
2020-04-24 23:36:52 +00:00
++ ( if perlSupport then [ " P E R L _ P A T H = ${ perlPackages . perl } / b i n / p e r l " ] else [ " N O _ P E R L = 1 " ] )
++ ( if pythonSupport then [ " P Y T H O N _ P A T H = ${ python3 } / b i n / p y t h o n " ] else [ " N O _ P Y T H O N = 1 " ] )
2021-01-17 00:15:33 +00:00
++ lib . optionals stdenv . isSunOS [ " I N S T A L L = i n s t a l l " " N O _ I N E T _ N T O P = " " N O _ I N E T _ P T O N = " ]
2020-04-24 23:36:52 +00:00
++ ( if stdenv . isDarwin then [ " N O _ A P P L E _ C O M M O N _ C R Y P T O = 1 " ] else [ " s y s c o n f d i r = / e t c " ] )
2021-01-17 00:15:33 +00:00
++ lib . optionals stdenv . hostPlatform . isMusl [ " N O _ S Y S _ P O L L _ H = 1 " " N O _ G E T T E X T = Y e s P l e a s e " ]
++ lib . optional withpcre2 " U S E _ L I B P C R E 2 = 1 "
++ lib . optional ( ! nlsSupport ) " N O _ G E T T E X T = 1 "
2020-04-24 23:36:52 +00:00
# git-gui refuses to start with the version of tk distributed with
# macOS Catalina. We can prevent git from building the .app bundle
# by specifying an invalid tk framework. The postInstall step will
# then ensure that git-gui uses tcl/tk from nixpkgs, which is an
# acceptable version.
#
# See https://github.com/Homebrew/homebrew-core/commit/dfa3ccf1e7d3901e371b5140b935839ba9d8b706
2021-01-17 00:15:33 +00:00
++ lib . optional stdenv . isDarwin " T K F R A M E W O R K = / n o n e x i s t e n t " ;
2020-04-24 23:36:52 +00:00
2021-12-06 16:07:01 +00:00
disallowedReferences = lib . optionals ( stdenv . buildPlatform != stdenv . hostPlatform ) [
stdenv . shellPackage
] ;
2020-04-24 23:36:52 +00:00
postBuild = ''
make - C contrib/subtree
2021-01-17 00:15:33 +00:00
'' + ( l i b . o p t i o n a l S t r i n g p e r l S u p p o r t ''
2020-04-24 23:36:52 +00:00
make - C contrib/diff-highlight
2021-03-09 03:18:52 +00:00
'' ) + ( l i b . o p t i o n a l S t r i n g o s x k e y c h a i n S u p p o r t ''
2020-04-24 23:36:52 +00:00
make - C contrib/credential/osxkeychain
2021-01-17 00:15:33 +00:00
'' ) + ( l i b . o p t i o n a l S t r i n g w i t h L i b s e c r e t ''
2020-04-24 23:36:52 +00:00
make - C contrib/credential/libsecret
'' ) ;
## Install
# WARNING: Do not `rm` or `mv` files from the source tree; use `cp` instead.
# We need many of these files during the installCheckPhase.
installFlags = [ " N O _ I N S T A L L _ H A R D L I N K S = 1 " ] ;
2021-03-09 03:18:52 +00:00
preInstall = ( lib . optionalString osxkeychainSupport ''
2020-04-24 23:36:52 +00:00
mkdir - p $ out/bin
ln - s $ out/share/git/contrib/credential/osxkeychain/git-credential-osxkeychain $ out/bin /
rm - f $ PWD/contrib/credential/osxkeychain/git-credential-osxkeychain.o
2021-01-17 00:15:33 +00:00
'' ) + ( l i b . o p t i o n a l S t r i n g w i t h L i b s e c r e t ''
2020-04-24 23:36:52 +00:00
mkdir - p $ out/bin
ln - s $ out/share/git/contrib/credential/libsecret/git-credential-libsecret $ out/bin /
rm - f $ PWD/contrib/credential/libsecret/git-credential-libsecret.o
'' ) ;
postInstall =
''
notSupported ( ) {
unlink $ 1 || true
}
# Install git-subtree.
2021-06-28 23:13:55 +00:00
make - C contrib/subtree install $ { lib . optionalString withManual " i n s t a l l - d o c " }
2020-04-24 23:36:52 +00:00
rm - rf contrib/subtree
# Install contrib stuff.
mkdir - p $ out/share/git
cp - a contrib $ out/share/git /
mkdir - p $ out/share/bash-completion/completions
ln - s $ out/share/git/contrib/completion/git-completion.bash $ out/share/bash-completion/completions/git
2020-11-21 19:51:51 +00:00
mkdir - p $ out/share/bash-completion/completions
ln - s $ out/share/git/contrib/completion/git-prompt.sh $ out/share/bash-completion/completions /
2020-04-24 23:36:52 +00:00
# grep is a runtime dependency, need to patch so that it's found
substituteInPlace $ out/libexec/git-core/git-sh-setup \
- - replace ' grep' ' $ { gnugrep } /bin/grep ' \
- - replace ' egrep' ' $ { gnugrep } /bin/egrep '
# Fix references to the perl, sed, awk and various coreutil binaries used by
# shell scripts that git calls (e.g. filter-branch)
SCRIPT = " $ ( c a t < < ' E O S '
BEGIN {
@ a = (
' $ { gnugrep } /bin/grep ' , ' $ { gnused } /bin/sed ' , ' $ { gawk } /bin/awk ' ,
' $ { coreutils } /bin/cut ' , ' $ { coreutils } /bin/basename ' , ' $ { coreutils } /bin/dirname ' ,
' $ { coreutils } /bin/wc ' , ' $ { coreutils } /bin/tr '
2021-01-17 00:15:33 +00:00
$ { lib . optionalString perlSupport " , ' ${ perlPackages . perl } / b i n / p e r l ' " }
2020-04-24 23:36:52 +00:00
) ;
}
foreach $ c ( @ a ) {
$ n = ( split ( " / " , $ c ) ) [ -1 ] ;
s | ( ? <= [ ^ #][^/.-])\b''${n}(?=\s)|''${c}|g
}
EOS
) "
perl -0777 - i - pe " $ S C R I P T " \
$ out/libexec/git-core/git- { sh-setup , filter-branch , merge-octopus , mergetool , quiltimport , request-pull , submodule , subtree , web--browse }
# Also put git-http-backend into $PATH, so that we can use smart
# HTTP(s) transports for pushing
ln - s $ out/libexec/git-core/git-http-backend $ out/bin/git-http-backend
2021-01-17 00:15:33 +00:00
'' + l i b . o p t i o n a l S t r i n g p e r l S u p p o r t ''
2020-04-24 23:36:52 +00:00
# wrap perl commands
makeWrapper " $ o u t / s h a r e / g i t / c o n t r i b / c r e d e n t i a l / n e t r c / g i t - c r e d e n t i a l - n e t r c . p e r l " $ out/bin/git-credential-netrc \
- - set PERL5LIB " $ o u t / ${ perlPackages . perl . libPrefix } : ${ perlPackages . makePerlPath perlLibs } "
wrapProgram $ out/libexec/git-core/git-cvsimport \
- - set GITPERLLIB " $ o u t / ${ perlPackages . perl . libPrefix } : ${ perlPackages . makePerlPath perlLibs } "
wrapProgram $ out/libexec/git-core/git-add--interactive \
- - set GITPERLLIB " $ o u t / ${ perlPackages . perl . libPrefix } : ${ perlPackages . makePerlPath perlLibs } "
wrapProgram $ out/libexec/git-core/git-archimport \
- - set GITPERLLIB " $ o u t / ${ perlPackages . perl . libPrefix } : ${ perlPackages . makePerlPath perlLibs } "
wrapProgram $ out/libexec/git-core/git-instaweb \
- - set GITPERLLIB " $ o u t / ${ perlPackages . perl . libPrefix } : ${ perlPackages . makePerlPath perlLibs } "
wrapProgram $ out/libexec/git-core/git-cvsexportcommit \
- - set GITPERLLIB " $ o u t / ${ perlPackages . perl . libPrefix } : ${ perlPackages . makePerlPath perlLibs } "
# gzip (and optionally bzip2, xz, zip) are runtime dependencies for
# gitweb.cgi, need to patch so that it's found
sed - i - e " s | ' c o m p r e s s o r ' = > \[ ' g z i p ' | ' c o m p r e s s o r ' = > [ ' ${ gzip } / b i n / g z i p ' | " \
$ out/share/gitweb/gitweb.cgi
# Give access to CGI.pm and friends (was removed from perl core in 5.22)
2021-01-17 00:15:33 +00:00
for p in $ { lib . concatStringsSep " " gitwebPerlLibs } ; do
2020-04-24 23:36:52 +00:00
sed - i - e " / u s e C G I / i u s e l i b \" $ p / ${ perlPackages . perl . libPrefix } \" ; " \
" $ o u t / s h a r e / g i t w e b / g i t w e b . c g i "
done
''
+ ( if svnSupport then ''
# wrap git-svn
wrapProgram $ out/libexec/git-core/git-svn \
- - set GITPERLLIB " $ o u t / ${ perlPackages . perl . libPrefix } : ${ perlPackages . makePerlPath ( perlLibs ++ [ svn . out ] ) } " \
- - prefix PATH : " ${ svn . out } / b i n " ''
else '' # r e p l a c e g i t - s v n b y n o t i f i c a t i o n s c r i p t
notSupported $ out/libexec/git-core/git-svn
'' )
+ ( if sendEmailSupport then ''
# wrap git-send-email
wrapProgram $ out/libexec/git-core/git-send-email \
- - set GITPERLLIB " $ o u t / ${ perlPackages . perl . libPrefix } : ${ perlPackages . makePerlPath smtpPerlLibs } "
'' e l s e ''
# replace git-send-email by notification script
notSupported $ out/libexec/git-core/git-send-email
'' )
2021-01-17 00:15:33 +00:00
+ lib . optionalString withManual '' # I n s t a l l m a n p a g e s
2021-06-28 23:13:55 +00:00
make - j $ NIX_BUILD_CORES - l $ NIX_BUILD_CORES PERL_PATH = " ${ buildPackages . perl } / b i n / p e r l " cmd-list . made install install-html \
2020-04-24 23:36:52 +00:00
- C Documentation ''
+ ( if guiSupport then ''
# Wrap Tcl/Tk programs
for prog in bin/gitk libexec/git-core / { git-gui , git-citool , git-gui--askpass } ; do
sed - i - e " s | e x e c ' w i s h ' | e x e c ' ${ tk } / b i n / w i s h ' | g " \
- e " s | e x e c w i s h | e x e c ' ${ tk } / b i n / w i s h ' | g " \
" $ o u t / $ p r o g "
done
ln - s $ out/share/git/contrib/completion/git-completion.bash $ out/share/bash-completion/completions/gitk
'' e l s e ''
# Don't wrap Tcl/Tk, replace them by notification scripts
for prog in bin/gitk libexec/git-core/git-gui ; do
notSupported " $ o u t / $ p r o g "
done
'' )
2021-03-09 03:18:52 +00:00
+ lib . optionalString osxkeychainSupport ''
# enable git-credential-osxkeychain on darwin if desired (default)
2020-11-21 19:51:51 +00:00
mkdir - p $ out/etc
2020-04-24 23:36:52 +00:00
cat > $ out/etc/gitconfig < < EOF
[ credential ]
helper = osxkeychain
EOF
'' ;
## InstallCheck
doCheck = false ;
doInstallCheck = true ;
installCheckTarget = " t e s t " ;
# see also installCheckFlagsArray
installCheckFlags = [
" D E F A U L T _ T E S T _ T A R G E T = p r o v e "
" P E R L _ P A T H = ${ buildPackages . perl } / b i n / p e r l "
] ;
preInstallCheck = ''
installCheckFlagsArray + = (
GIT_PROVE_OPTS = " - - j o b s $ N I X _ B U I L D _ C O R E S - - f a i l u r e s - - s t a t e = f a i l e d , s a v e "
GIT_TEST_INSTALLED = $ out/bin
2021-01-17 00:15:33 +00:00
$ { lib . optionalString ( ! svnSupport ) " N O _ S V N _ T E S T S = y " }
2020-04-24 23:36:52 +00:00
)
function disable_test {
local test = $ 1 pattern = $ 2
if [ $ # -eq 1 ]; then
mv t / { , skip- } $ test . sh || true
else
sed - i t / $ test . sh \
2020-06-18 07:06:33 +00:00
- e " / ^ \s * t e s t _ e x p e c t _ . * $ p a t t e r n / , / ^ \s * ' * \$ / { s / ^ / : # / } "
2020-04-24 23:36:52 +00:00
fi
}
2021-06-28 23:13:55 +00:00
# Shared permissions are forbidden in sandbox builds:
substituteInPlace t/test-lib.sh \
- - replace " t e s t _ s e t _ p r e r e q P O S I X P E R M " " "
# TODO: Investigate while these still fail (without POSIXPERM):
disable_test t0001-init ' shared overrides system'
disable_test t0001-init ' init honors global core . sharedRepository'
2020-04-24 23:36:52 +00:00
disable_test t1301-shared-repo
2021-09-18 10:52:07 +00:00
# git-completion.bash: line 405: compgen: command not found:
disable_test t9902-completion ' option aliases are shown with GIT_COMPLETION_SHOW_ALL'
2020-04-24 23:36:52 +00:00
# Our patched gettext never fallbacks
disable_test t0201-gettext-fallbacks
2021-01-17 00:15:33 +00:00
$ { lib . optionalString ( ! sendEmailSupport ) ''
2020-04-24 23:36:52 +00:00
# Disable sendmail tests
disable_test t9001-send-email
'' }
# XXX: I failed to understand why this one fails.
# Could someone try to re-enable it on the next release ?
# Tested to fail: 2.18.0 and 2.19.0
disable_test t1700-split-index " n u l l s h a 1 "
# Tested to fail: 2.18.0
disable_test t9902-completion " s o u r c i n g t h e c o m p l e t i o n s c r i p t c l e a r s c a c h e d - - o p t i o n s "
2021-04-05 15:23:46 +00:00
# Flaky tests:
disable_test t5319-multi-pack-index
2021-09-26 12:46:18 +00:00
disable_test t6421-merge-partial-clone
2021-04-05 15:23:46 +00:00
2021-01-17 00:15:33 +00:00
$ { lib . optionalString ( ! perlSupport ) ''
2020-04-24 23:36:52 +00:00
# request-pull is a Bash script that invokes Perl, so it is not available
# when NO_PERL=1, and the test should be skipped, but the test suite does
# not check for the Perl prerequisite.
disable_test t5150-request-pull
'' }
2021-01-17 00:15:33 +00:00
'' + l i b . o p t i o n a l S t r i n g s t d e n v . i s D a r w i n ''
2020-04-24 23:36:52 +00:00
# XXX: Some tests added in 2.24.0 fail.
# Please try to re-enable on the next release.
disable_test t7816-grep-binary-pattern
2021-10-09 14:59:57 +00:00
# fail (as of 2.33.0)
#===( 18623;1208 8/? 224/? 2/? )= =fatal: Not a valid object name refs/tags/signed-empty
disable_test t6300-for-each-ref
#===( 22665;1651 9/? 1/? 0/? 0/? )= =/private/tmp/nix-build-git-2.33.0.drv-2/git-2.33.0/t/../contrib/completion/git-completion.bash: line 405: compgen: command not found
disable_test t9902-completion
2021-12-06 16:07:01 +00:00
# not ok 1 - populate workdir (with 2.33.1 on x86_64-darwin)
disable_test t5003-archive-zip
2021-01-17 00:15:33 +00:00
'' + l i b . o p t i o n a l S t r i n g s t d e n v . h o s t P l a t f o r m . i s M u s l ''
2020-04-24 23:36:52 +00:00
# Test fails (as of 2.17.0, musl 1.1.19)
disable_test t3900-i18n-commit
# Fails largely due to assumptions about BOM
# Tested to fail: 2.18.0
disable_test t0028-working-tree-encoding
'' ;
stripDebugList = [ " l i b " " l i b e x e c " " b i n " " s h a r e / g i t / c o n t r i b / c r e d e n t i a l / l i b s e c r e t " ] ;
2021-07-14 22:03:04 +00:00
passthru = {
shellPath = " / b i n / g i t - s h e l l " ;
tests = {
buildbot-integration = nixosTests . buildbot ;
} ;
2021-05-20 23:08:51 +00:00
} ;
2020-04-24 23:36:52 +00:00
meta = {
homepage = " h t t p s : / / g i t - s c m . c o m / " ;
description = " D i s t r i b u t e d v e r s i o n c o n t r o l s y s t e m " ;
2021-01-17 00:15:33 +00:00
license = lib . licenses . gpl2 ;
2021-04-05 15:23:46 +00:00
changelog = " h t t p s : / / g i t h u b . c o m / g i t / g i t / b l o b / v ${ version } / D o c u m e n t a t i o n / R e l N o t e s / ${ version } . t x t " ;
2020-04-24 23:36:52 +00:00
longDescription = ''
Git , a popular distributed version control system designed to
handle very large projects with speed and efficiency .
'' ;
2021-01-17 00:15:33 +00:00
platforms = lib . platforms . all ;
2021-10-17 02:12:59 +00:00
maintainers = with lib . maintainers ; [ primeos wmertens globin ] ;
2020-04-24 23:36:52 +00:00
} ;
}