1 { lib, stdenv, fetchurl, gettext, libgpgerror, enableCapabilities ? false, libcap, buildPackages }:
3 assert enableCapabilities -> stdenv.isLinux;
5 stdenv.mkDerivation rec {
10 url = "mirror://gnupg/libgcrypt/${pname}-${version}.tar.bz2";
11 sha256 = "sha256-ssENCRUTsnHkcXcnRgex/7o9lbGIu/qHl/lIrskFPFo=";
14 outputs = [ "out" "dev" "info" ];
17 # The CPU Jitter random number generator must not be compiled with
18 # optimizations and the optimize -O0 pragma only works for gcc.
19 # The build enables -O2 by default for everything else.
20 hardeningDisable = lib.optional stdenv.cc.isClang "fortify";
22 depsBuildBuild = [ buildPackages.stdenv.cc ];
24 buildInputs = [ libgpgerror ]
25 ++ lib.optional stdenv.isDarwin gettext
26 ++ lib.optional enableCapabilities libcap;
30 configureFlags = [ "--with-libgpg-error-prefix=${libgpgerror.dev}" ]
31 ++ lib.optional (stdenv.hostPlatform.isMusl || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64)) "--disable-asm"; # for darwin see https://dev.gnupg.org/T5157
33 # Necessary to generate correct assembly when compiling for aarch32 on
35 configurePlatforms = [ "host" "build" ];
39 -e 's/NOEXECSTACK_FLAGS=$/NOEXECSTACK_FLAGS="-Wa,--noexecstack"/'
42 # Make sure libraries are correct for .pc and .la files
43 # Also make sure includes are fixed for callers who don't use libgpgcrypt-config
45 sed -i 's,#include <gpg-error.h>,#include "${libgpgerror.dev}/include/gpg-error.h",g' "$dev/include/gcrypt.h"
46 '' + lib.optionalString enableCapabilities ''
47 sed -i 's,\(-lcap\),-L${libcap.lib}/lib \1,' $out/lib/libgcrypt.la
50 # TODO: figure out why this is even necessary and why the missing dylib only crashes
51 # random instead of every test
52 preCheck = lib.optionalString stdenv.isDarwin ''
54 cp src/.libs/libgcrypt.20.dylib $out/lib
60 homepage = "https://www.gnu.org/software/libgcrypt/";
61 description = "General-purpose cryptographic library";
62 license = licenses.lgpl2Plus;
63 platforms = platforms.all;
64 maintainers = with maintainers; [ vrthra ];
65 repositories.git = "git://git.gnupg.org/libgcrypt.git";