1{ stdenv, fetchurl, gettext, libgpgerror, enableCapabilities ? false, libcap
2, buildPackages
3}:
4
5assert enableCapabilities -> stdenv.isLinux;
6
7stdenv.mkDerivation rec {
8 name = "libgcrypt-${version}";
9 version = "1.8.3";
10
11 src = fetchurl {
12 url = "mirror://gnupg/libgcrypt/${name}.tar.bz2";
13 sha256 = "0z5gs1khzyknyfjr19k8gk4q148s6q987ya85cpn0iv70fz91v36";
14 };
15
16 outputs = [ "out" "dev" "info" ];
17 outputBin = "dev";
18
19 # The CPU Jitter random number generator must not be compiled with
20 # optimizations and the optimize -O0 pragma only works for gcc.
21 # The build enables -O2 by default for everything else.
22 hardeningDisable = stdenv.lib.optional stdenv.cc.isClang "fortify";
23
24 depsBuildBuild = stdenv.lib.optional stdenv.isCross buildPackages.stdenv.cc;
25
26 # Accepted upstream, should be in next update: #42150, https://dev.gnupg.org/T4034
27 patches = [ ./fix-jent-locking.patch ];
28
29 buildInputs = [ libgpgerror ]
30 ++ stdenv.lib.optional stdenv.isDarwin gettext
31 ++ stdenv.lib.optional enableCapabilities libcap;
32
33 preConfigure = if stdenv.isCross then ''
34 # This is intentional: gpg-error-config is a shell script that will work during the build
35 mkdir -p "$NIX_BUILD_TOP"/bin
36 ln -s ${libgpgerror.dev}/bin/gpg-error-config "$NIX_BUILD_TOP/bin"
37 export PATH="$NIX_BUILD_TOP/bin:$PATH"
38 '' else null;
39
40 # Make sure libraries are correct for .pc and .la files
41 # Also make sure includes are fixed for callers who don't use libgpgcrypt-config
42 postFixup = ''
43 sed -i 's,#include <gpg-error.h>,#include "${libgpgerror.dev}/include/gpg-error.h",g' "$dev/include/gcrypt.h"
44 '' + stdenv.lib.optionalString enableCapabilities ''
45 sed -i 's,\(-lcap\),-L${libcap.lib}/lib \1,' $out/lib/libgcrypt.la
46 '';
47
48 # TODO: figure out why this is even necessary and why the missing dylib only crashes
49 # random instead of every test
50 preCheck = stdenv.lib.optionalString stdenv.isDarwin ''
51 mkdir -p $out/lib
52 cp src/.libs/libgcrypt.20.dylib $out/lib
53 '';
54
55 doCheck = true;
56
57 meta = with stdenv.lib; {
58 homepage = https://www.gnu.org/software/libgcrypt/;
59 description = "General-purpose cryptographic library";
60 license = licenses.lgpl2Plus;
61 platforms = platforms.all;
62 maintainers = [ maintainers.wkennington maintainers.vrthra ];
63 repositories.git = git://git.gnupg.org/libgcrypt.git;
64 };
65}