1 { config, lib, stdenv, fetchurl, zlib, lzo, libtasn1, nettle, pkg-config, lzip
2 , perl, gmp, autoconf, automake, libidn, p11-kit, libiconv
3 , unbound, dns-root-data, gettext, cacert, util-linux
4 , guileBindings ? config.gnutls.guile or false, guile
5 , tpmSupport ? false, trousers, which, nettools, libunistring
6 , withSecurity ? false, Security # darwin Security.framework
9 assert guileBindings -> guile != null;
13 # XXX: Gnulib's `test-select' fails on FreeBSD:
14 # https://hydra.nixos.org/build/2962084/nixlog/1/raw .
15 doCheck = !stdenv.isFreeBSD && !stdenv.isDarwin && lib.versionAtLeast version "3.4"
16 && stdenv.buildPlatform == stdenv.hostPlatform;
18 inherit (stdenv.hostPlatform) isDarwin;
22 name = "gnutls-${version}";
26 url = "mirror://gnupg/gnutls/v3.7/gnutls-${version}.tar.xz";
27 sha256 = "0vxcbig87sdc73h58pmcpbi4al1zgcxid1jn67mhcpna7sbdfxrp";
30 outputs = [ "bin" "dev" "out" "man" "devdoc" ];
31 # Not normally useful docs.
32 outputInfo = "devdoc";
35 patches = [ ./nix-ssl-cert-file.patch ]
36 # Disable native add_system_trust.
37 ++ lib.optional (isDarwin && !withSecurity) ./no-security-framework.patch;
40 # - pkg-config: building against the result won't work before installing (3.5.11)
41 # - fastopen: no idea; it broke between 3.6.2 and 3.6.3 (3437fdde6 in particular)
42 # - trust-store: default trust store path (/etc/ssl/...) is missing in sandbox (3.5.11)
43 # - psk-file: no idea; it broke between 3.6.3 and 3.6.4
44 # Change p11-kit test to use pkg-config to find p11-kit
45 postPatch = lib.optionalString (lib.versionAtLeast version "3.6") ''
46 sed '2iexit 77' -i tests/{pkgconfig,fastopen}.sh
47 sed '/^void doit(void)/,/^{/ s/{/{ exit(77);/' -i tests/{trust-store,psk-file}.c
48 sed 's:/usr/lib64/pkcs11/ /usr/lib/pkcs11/ /usr/lib/x86_64-linux-gnu/pkcs11/:`pkg-config --variable=p11_module_path p11-kit-1`:' -i tests/p11-kit-trust.sh
49 '' + lib.optionalString stdenv.hostPlatform.isMusl '' # See https://gitlab.com/gnutls/gnutls/-/issues/945
50 sed '2iecho "certtool tests skipped in musl build"\nexit 0' -i tests/cert-tests/certtool.sh
53 preConfigure = "patchShebangs .";
55 lib.optional stdenv.isLinux "--with-default-trust-store-file=/etc/ssl/certs/ca-certificates.crt"
57 "--disable-dependency-tracking"
58 "--enable-fast-install"
59 "--with-unbound-root-key-file=${dns-root-data}/root.key"
60 ] ++ lib.optional guileBindings [
62 "--with-guile-site-dir=\${out}/share/guile/site"
63 "--with-guile-site-ccache-dir=\${out}/share/guile/site"
64 "--with-guile-extension-dir=\${out}/share/guile/site"
67 enableParallelBuilding = true;
69 buildInputs = [ lzo lzip libtasn1 libidn p11-kit zlib gmp libunistring unbound gettext libiconv ]
70 ++ lib.optional (isDarwin && withSecurity) Security
71 ++ lib.optional (tpmSupport && stdenv.isLinux) trousers
72 ++ lib.optional guileBindings guile;
74 nativeBuildInputs = [ perl pkg-config ]
75 ++ lib.optionals (isDarwin && !withSecurity) [ autoconf automake ]
76 ++ lib.optionals doCheck [ which nettools util-linux ];
78 propagatedBuildInputs = [ nettle ];
81 # stdenv's `NIX_SSL_CERT_FILE=/no-cert-file.crt` broke tests with:
82 # Error setting the x509 trust file: Error while reading file.
83 checkInputs = [ cacert ];
85 # Fixup broken libtool and pkg-config files
86 preFixup = lib.optionalString (!isDarwin) ''
87 sed ${lib.optionalString tpmSupport "-e 's,-ltspi,-L${trousers}/lib -ltspi,'"} \
88 -e 's,-lz,-L${zlib.out}/lib -lz,' \
89 -e 's,-L${gmp.dev}/lib,-L${gmp.out}/lib,' \
90 -e 's,-lgmp,-L${gmp.out}/lib -lgmp,' \
91 -i $out/lib/*.la "$dev/lib/pkgconfig/gnutls.pc"
93 # It seems only useful for static linking but basically noone does that.
94 substituteInPlace "$out/lib/libgnutls.la" \
95 --replace "-lunistring" ""
99 description = "The GNU Transport Layer Security Library";
102 GnuTLS is a project that aims to develop a library which
103 provides a secure layer, over a reliable transport
104 layer. Currently the GnuTLS library implements the proposed standards by
105 the IETF's TLS working group.
107 Quoting from the TLS protocol specification:
109 "The TLS protocol provides communications privacy over the
110 Internet. The protocol allows client/server applications to
111 communicate in a way that is designed to prevent eavesdropping,
112 tampering, or message forgery."
115 homepage = "https://www.gnu.org/software/gnutls/";
116 license = licenses.lgpl21Plus;
117 maintainers = with maintainers; [ eelco fpletz ];
118 platforms = platforms.all;