2022-02-20 05:27:41 +00:00
{ lib
, stdenv
, fetchurl
, gettext
, libgpg-error
, enableCapabilities ? false , libcap
, buildPackages
# for passthru.tests
, gnupg
, libotr
, rsyslog
} :
2020-04-24 23:36:52 +00:00
2024-09-26 11:04:55 +00:00
assert enableCapabilities -> stdenv . hostPlatform . isLinux ;
2020-04-24 23:36:52 +00:00
stdenv . mkDerivation rec {
pname = " l i b g c r y p t " ;
2024-01-02 11:29:13 +00:00
version = " 1 . 1 0 . 3 " ;
2020-04-24 23:36:52 +00:00
src = fetchurl {
url = " m i r r o r : / / g n u p g / l i b g c r y p t / ${ pname } - ${ version } . t a r . b z 2 " ;
2024-01-02 11:29:13 +00:00
hash = " s h a 2 5 6 - i w h w i X r F r G f e 1 W j c + t 9 F l p z 6 i m v r D 9 Y K 8 q n q 3 C o y c q o = " ;
2020-04-24 23:36:52 +00:00
} ;
2024-07-31 10:19:44 +00:00
outputs = [ " b i n " " l i b " " d e v " " i n f o " " o u t " ] ;
2020-04-24 23:36:52 +00:00
# The CPU Jitter random number generator must not be compiled with
# optimizations and the optimize -O0 pragma only works for gcc.
# The build enables -O2 by default for everything else.
2021-02-05 17:12:51 +00:00
hardeningDisable = lib . optional stdenv . cc . isClang " f o r t i f y " ;
2020-04-24 23:36:52 +00:00
depsBuildBuild = [ buildPackages . stdenv . cc ] ;
2021-10-08 15:17:17 +00:00
buildInputs = [ libgpg-error ]
2024-09-26 11:04:55 +00:00
++ lib . optional stdenv . hostPlatform . isDarwin gettext
2021-02-05 17:12:51 +00:00
++ lib . optional enableCapabilities libcap ;
2020-04-24 23:36:52 +00:00
2021-03-09 03:18:52 +00:00
strictDeps = true ;
2021-10-08 15:17:17 +00:00
configureFlags = [ " - - w i t h - l i b g p g - e r r o r - p r e f i x = ${ libgpg-error . dev } " ]
2024-06-24 18:47:55 +00:00
++ lib . optional ( stdenv . hostPlatform . isMusl || ( stdenv . hostPlatform . isDarwin && stdenv . hostPlatform . isAarch64 ) ) " - - d i s a b l e - a s m " # for darwin see https://dev.gnupg.org/T5157
# Fix undefined reference errors with version script under LLVM.
++ lib . optional ( stdenv . cc . bintools . isLLVM && lib . versionAtLeast stdenv . cc . bintools . version " 1 7 " ) " L D F L A G S = - W l , - - u n d e f i n e d - v e r s i o n " ;
2020-04-24 23:36:52 +00:00
2020-07-18 16:06:22 +00:00
# Necessary to generate correct assembly when compiling for aarch32 on
# aarch64
configurePlatforms = [ " h o s t " " b u i l d " ] ;
2021-01-05 17:05:55 +00:00
postConfigure = ''
sed - i configure \
- e ' s/NOEXECSTACK_FLAGS = $ /NOEXECSTACK_FLAGS = " - W a , - - n o e x e c s t a c k " / '
'' ;
2024-01-13 08:15:51 +00:00
enableParallelBuilding = true ;
2020-04-24 23:36:52 +00:00
# Make sure libraries are correct for .pc and .la files
# Also make sure includes are fixed for callers who don't use libgpgcrypt-config
postFixup = ''
2021-10-08 15:17:17 +00:00
sed - i ' s , #include <gpg-error.h>,#include "${libgpg-error.dev}/include/gpg-error.h",g' "$dev/include/gcrypt.h"
2024-07-31 10:19:44 +00:00
''
# The `libgcrypt-config` script references $dev and in the $dev output, the
# stdenv automagically puts the $bin output into propagatedBuildInputs. This
# would cause a cycle. This is a weird tool anyways, so let's stuff it in $dev
# instead.
+ ''
moveToOutput bin/libgcrypt-config $ dev
2021-02-05 17:12:51 +00:00
'' + l i b . o p t i o n a l S t r i n g e n a b l e C a p a b i l i t i e s ''
2024-07-31 10:19:44 +00:00
sed - i ' s , \ ( - lcap \ ) , - L $ { libcap . lib } /lib \ 1 , ' $ lib/lib/libgcrypt.la
2020-04-24 23:36:52 +00:00
'' ;
# TODO: figure out why this is even necessary and why the missing dylib only crashes
# random instead of every test
2024-09-26 11:04:55 +00:00
preCheck = lib . optionalString stdenv . hostPlatform . isDarwin ''
2024-07-31 10:19:44 +00:00
mkdir - p $ lib/lib
cp src/.libs/libgcrypt.20.dylib $ lib/lib
2020-04-24 23:36:52 +00:00
'' ;
doCheck = true ;
2024-01-13 08:15:51 +00:00
enableParallelChecking = true ;
2020-04-24 23:36:52 +00:00
2022-02-20 05:27:41 +00:00
passthru . tests = {
inherit gnupg libotr rsyslog ;
} ;
2021-02-05 17:12:51 +00:00
meta = with lib ; {
2020-04-24 23:36:52 +00:00
homepage = " h t t p s : / / w w w . g n u . o r g / s o f t w a r e / l i b g c r y p t / " ;
2023-05-24 13:37:59 +00:00
changelog = " h t t p s : / / g i t . g n u p g . o r g / c g i - b i n / g i t w e b . c g i ? p = ${ pname } . g i t ; a = b l o b ; f = N E W S ; h b = r e f s / t a g s / ${ pname } - ${ version } " ;
2020-04-24 23:36:52 +00:00
description = " G e n e r a l - p u r p o s e c r y p t o g r a p h i c l i b r a r y " ;
license = licenses . lgpl2Plus ;
platforms = platforms . all ;
2024-07-31 10:19:44 +00:00
maintainers = [ ] ;
2020-04-24 23:36:52 +00:00
} ;
}