1{ fetchurl, stdenv, curl, openssl, zlib, expat, perl, python, gettext, cpio
2, gnugrep, gnused, gawk, coreutils # needed at runtime by git-filter-branch etc
3, gzip, openssh, pcre2
4, asciidoc, texinfo, xmlto, docbook2x, docbook_xsl, docbook_xml_dtd_45
5, libxslt, tcl, tk, makeWrapper, libiconv
6, svnSupport, subversionClient, perlLibs, smtpPerlLibs, gitwebPerlLibs
7, guiSupport
8, withManual ? true
9, pythonSupport ? true
10, withpcre2 ? true
11, sendEmailSupport
12, darwin
13}:
14
15let
16 version = "2.16.2";
17 svn = subversionClient.override { perlBindings = true; };
18in
19
20stdenv.mkDerivation {
21 name = "git-${version}";
22
23 src = fetchurl {
24 url = "https://www.kernel.org/pub/software/scm/git/git-${version}.tar.xz";
25 sha256 = "05y7480f2p7fkncbhf08zz56jbykcp0ia5gl6y3djs0lsa5mfq2m";
26 };
27
28 hardeningDisable = [ "format" ];
29
30 patches = [
31 ./docbook2texi.patch
32 ./symlinks-in-bin.patch
33 ./git-sh-i18n.patch
34 ./ssh-path.patch
35 ./git-send-email-honor-PATH.patch
36 ];
37
38 postPatch = ''
39 for x in connect.c git-gui/lib/remote_add.tcl ; do
40 substituteInPlace "$x" \
41 --subst-var-by ssh "${openssh}/bin/ssh"
42 done
43 '';
44
45 buildInputs = [curl openssl zlib expat gettext cpio makeWrapper libiconv perl]
46 ++ stdenv.lib.optionals withManual [ asciidoc texinfo xmlto docbook2x
47 docbook_xsl docbook_xml_dtd_45 libxslt ]
48 ++ stdenv.lib.optionals guiSupport [tcl tk]
49 ++ stdenv.lib.optionals withpcre2 [ pcre2 ]
50 ++ stdenv.lib.optionals stdenv.isDarwin [ darwin.Security ];
51
52
53 # required to support pthread_cancel()
54 NIX_LDFLAGS = stdenv.lib.optionalString (!stdenv.cc.isClang) "-lgcc_s"
55 + stdenv.lib.optionalString (stdenv.isFreeBSD) "-lthr";
56
57 makeFlags = "prefix=\${out} PERL_PATH=${perl}/bin/perl SHELL_PATH=${stdenv.shell} "
58 + (if pythonSupport then "PYTHON_PATH=${python}/bin/python" else "NO_PYTHON=1")
59 + (if stdenv.isSunOS then " INSTALL=install NO_INET_NTOP= NO_INET_PTON=" else "")
60 + (if stdenv.isDarwin then " NO_APPLE_COMMON_CRYPTO=1" else " sysconfdir=/etc/ ")
61 # XXX: USE_PCRE2 might be useful in general, look into it
62 # XXX other alpine options?
63 + (if stdenv.hostPlatform.isMusl then "NO_SYS_POLL_H=1 NO_GETTEXT=YesPlease" else "");
64
65 # build git-credential-osxkeychain if darwin
66 postBuild = stdenv.lib.optionalString stdenv.isDarwin ''
67 pushd $PWD/contrib/credential/osxkeychain/
68 make
69 popd
70 '';
71
72 # FIXME: "make check" requires Sparse; the Makefile must be tweaked
73 # so that `SPARSE_FLAGS' corresponds to the current architecture...
74 #doCheck = true;
75
76 installFlags = "NO_INSTALL_HARDLINKS=1"
77 + (if withpcre2 then " USE_LIBPCRE2=1" else "");
78
79
80 preInstall = stdenv.lib.optionalString stdenv.isDarwin ''
81 mkdir -p $out/bin
82 mv $PWD/contrib/credential/osxkeychain/git-credential-osxkeychain $out/bin
83 '';
84
85 postInstall =
86 ''
87 notSupported() {
88 unlink $1 || true
89 }
90
91 # Install git-subtree.
92 pushd contrib/subtree
93 make
94 make install ${stdenv.lib.optionalString withManual "install-doc"}
95 popd
96 rm -rf contrib/subtree
97
98 # Install contrib stuff.
99 mkdir -p $out/share/git
100 mv contrib $out/share/git/
101 ln -s "$out/share/git/contrib/credential/netrc/git-credential-netrc" $out/bin/
102 mkdir -p $out/share/emacs/site-lisp
103 ln -s "$out/share/git/contrib/emacs/"*.el $out/share/emacs/site-lisp/
104 mkdir -p $out/etc/bash_completion.d
105 ln -s $out/share/git/contrib/completion/git-completion.bash $out/etc/bash_completion.d/
106 ln -s $out/share/git/contrib/completion/git-prompt.sh $out/etc/bash_completion.d/
107
108 # grep is a runtime dependency, need to patch so that it's found
109 substituteInPlace $out/libexec/git-core/git-sh-setup \
110 --replace ' grep' ' ${gnugrep}/bin/grep' \
111 --replace ' egrep' ' ${gnugrep}/bin/egrep'
112
113 # Fix references to the perl, sed, awk and various coreutil binaries used by
114 # shell scripts that git calls (e.g. filter-branch)
115 SCRIPT="$(cat <<'EOS'
116 BEGIN{
117 @a=(
118 '${perl}/bin/perl', '${gnugrep}/bin/grep', '${gnused}/bin/sed', '${gawk}/bin/awk',
119 '${coreutils}/bin/cut', '${coreutils}/bin/basename', '${coreutils}/bin/dirname',
120 '${coreutils}/bin/wc', '${coreutils}/bin/tr'
121 );
122 }
123 foreach $c (@a) {
124 $n=(split("/", $c))[-1];
125 s|(?<=[^#][^/.-])\b''${n}(?=\s)|''${c}|g
126 }
127 EOS
128 )"
129 perl -0777 -i -pe "$SCRIPT" \
130 $out/libexec/git-core/git-{sh-setup,filter-branch,merge-octopus,mergetool,quiltimport,request-pull,stash,submodule,subtree,web--browse}
131
132 # Fix references to gettext.
133 substituteInPlace $out/libexec/git-core/git-sh-i18n \
134 --subst-var-by gettext ${gettext}
135
136 # gzip (and optionally bzip2, xz, zip) are runtime dependencies for
137 # gitweb.cgi, need to patch so that it's found
138 sed -i -e "s|'compressor' => \['gzip'|'compressor' => ['${gzip}/bin/gzip'|" \
139 $out/share/gitweb/gitweb.cgi
140 # Give access to CGI.pm and friends (was removed from perl core in 5.22)
141 for p in ${stdenv.lib.concatStringsSep " " gitwebPerlLibs}; do
142 sed -i -e "/use CGI /i use lib \"$p/lib/perl5/site_perl\";" \
143 "$out/share/gitweb/gitweb.cgi"
144 done
145
146 # Also put git-http-backend into $PATH, so that we can use smart
147 # HTTP(s) transports for pushing
148 ln -s $out/libexec/git-core/git-http-backend $out/bin/git-http-backend
149
150 # wrap perl commands
151 gitperllib=$out/lib/perl5/site_perl
152 for i in ${builtins.toString perlLibs}; do
153 gitperllib=$gitperllib:$i/lib/perl5/site_perl
154 done
155 wrapProgram $out/libexec/git-core/git-cvsimport \
156 --set GITPERLLIB "$gitperllib"
157 wrapProgram $out/libexec/git-core/git-add--interactive \
158 --set GITPERLLIB "$gitperllib"
159 wrapProgram $out/libexec/git-core/git-archimport \
160 --set GITPERLLIB "$gitperllib"
161 wrapProgram $out/libexec/git-core/git-instaweb \
162 --set GITPERLLIB "$gitperllib"
163 wrapProgram $out/libexec/git-core/git-cvsexportcommit \
164 --set GITPERLLIB "$gitperllib"
165 ''
166
167 + (if svnSupport then
168
169 ''# wrap git-svn
170 gitperllib=$out/lib/perl5/site_perl
171 for i in ${builtins.toString perlLibs} ${svn.out}; do
172 gitperllib=$gitperllib:$i/lib/perl5/site_perl
173 done
174 wrapProgram $out/libexec/git-core/git-svn \
175 --set GITPERLLIB "$gitperllib" \
176 --prefix PATH : "${svn.out}/bin" ''
177 else '' # replace git-svn by notification script
178 notSupported $out/libexec/git-core/git-svn
179 '')
180
181 + (if sendEmailSupport then
182 ''# wrap git-send-email
183 gitperllib=$out/lib/perl5/site_perl
184 for i in ${builtins.toString smtpPerlLibs}; do
185 gitperllib=$gitperllib:$i/lib/perl5/site_perl
186 done
187 wrapProgram $out/libexec/git-core/git-send-email \
188 --set GITPERLLIB "$gitperllib" ''
189 else '' # replace git-send-email by notification script
190 notSupported $out/libexec/git-core/git-send-email
191 '')
192
193 + stdenv.lib.optionalString withManual ''# Install man pages and Info manual
194 make -j $NIX_BUILD_CORES -l $NIX_BUILD_CORES PERL_PATH="${perl}/bin/perl" cmd-list.made install install-info \
195 -C Documentation ''
196
197 + (if guiSupport then ''
198 # Wrap Tcl/Tk programs
199 for prog in bin/gitk libexec/git-core/{git-gui,git-citool,git-gui--askpass}; do
200 sed -i -e "s|exec 'wish'|exec '${tk}/bin/wish'|g" \
201 -e "s|exec wish|exec '${tk}/bin/wish'|g" \
202 "$out/$prog"
203 done
204 '' else ''
205 # Don't wrap Tcl/Tk, replace them by notification scripts
206 for prog in bin/gitk libexec/git-core/git-gui; do
207 notSupported "$out/$prog"
208 done
209 '')
210 + stdenv.lib.optionalString stdenv.isDarwin ''
211 # enable git-credential-osxkeychain by default if darwin
212 cat > $out/etc/gitconfig << EOF
213[credential]
214 helper = osxkeychain
215EOF
216 '';
217
218
219 enableParallelBuilding = true;
220
221 meta = {
222 homepage = https://git-scm.com/;
223 description = "Distributed version control system";
224 license = stdenv.lib.licenses.gpl2;
225
226 longDescription = ''
227 Git, a popular distributed version control system designed to
228 handle very large projects with speed and efficiency.
229 '';
230
231 platforms = stdenv.lib.platforms.all;
232 maintainers = with stdenv.lib.maintainers; [ peti the-kenny wmertens ];
233 };
234}