1 { config, lib, stdenv, fetchurl, zlib, lzo, libtasn1, nettle, pkg-config, lzip
2 , perl, gmp, autoconf, automake, libidn2, libiconv
3 , unbound, dns-root-data, gettext, util-linux
4 , cxxBindings ? !stdenv.hostPlatform.isStatic # tries to link libstdc++.so
5 , guileBindings ? config.gnutls.guile or false, guile
6 , tpmSupport ? false, trousers, which, nettools, libunistring
7 , withP11-kit ? !stdenv.hostPlatform.isStatic, p11-kit
8 , withSecurity ? true, Security # darwin Security.framework
9 # certificate compression - only zlib now, more possible: zstd, brotli
12 assert guileBindings -> guile != null;
15 # XXX: Gnulib's `test-select' fails on FreeBSD:
16 # https://hydra.nixos.org/build/2962084/nixlog/1/raw .
17 doCheck = !stdenv.isFreeBSD && !stdenv.isDarwin
18 && stdenv.buildPlatform == stdenv.hostPlatform;
20 inherit (stdenv.hostPlatform) isDarwin;
23 stdenv.mkDerivation rec {
28 url = "mirror://gnupg/gnutls/v${lib.versions.majorMinor version}/gnutls-${version}.tar.xz";
29 sha256 = "sha256-xYrTmvBnDv5qiu5eOosjMaEgBBi2S3xRl3+zltRhcRQ=";
32 outputs = [ "bin" "dev" "out" "man" "devdoc" ];
33 # Not normally useful docs.
34 outputInfo = "devdoc";
37 patches = [ ./nix-ssl-cert-file.patch ]
38 # Disable native add_system_trust.
39 # FIXME: apparently it's not enough to drop the framework anymore; maybe related to
40 # https://gitlab.com/gnutls/gnutls/-/commit/c19cb93d492e45141bfef9b926dfeba36003261c
41 ++ lib.optional (isDarwin && !withSecurity) ./no-security-framework.patch;
44 # - pkg-config: building against the result won't work before installing (3.5.11)
45 # - fastopen: no idea; it broke between 3.6.2 and 3.6.3 (3437fdde6 in particular)
46 # - trust-store: default trust store path (/etc/ssl/...) is missing in sandbox (3.5.11)
47 # - psk-file: no idea; it broke between 3.6.3 and 3.6.4
48 # Change p11-kit test to use pkg-config to find p11-kit
50 sed '2iexit 77' -i tests/{pkgconfig,fastopen}.sh
51 sed '/^void doit(void)/,/^{/ s/{/{ exit(77);/' -i tests/{trust-store,psk-file}.c
52 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
53 '' + lib.optionalString stdenv.hostPlatform.isMusl '' # See https://gitlab.com/gnutls/gnutls/-/issues/945
54 sed '2iecho "certtool tests skipped in musl build"\nexit 0' -i tests/cert-tests/certtool.sh
57 preConfigure = "patchShebangs .";
59 lib.optionals withP11-kit [
60 "--with-default-trust-store-file=/etc/ssl/certs/ca-certificates.crt"
61 "--with-default-trust-store-pkcs11=pkcs11:"
63 "--disable-dependency-tracking"
64 "--enable-fast-install"
65 "--with-unbound-root-key-file=${dns-root-data}/root.key"
66 (lib.withFeature withP11-kit "p11-kit")
67 (lib.enableFeature cxxBindings "cxx")
68 ] ++ lib.optionals guileBindings [
70 "--with-guile-site-dir=\${out}/share/guile/site"
71 "--with-guile-site-ccache-dir=\${out}/share/guile/site"
72 "--with-guile-extension-dir=\${out}/share/guile/site"
75 enableParallelBuilding = true;
77 buildInputs = [ lzo lzip libtasn1 libidn2 zlib gmp libunistring unbound gettext libiconv ]
78 ++ lib.optional (withP11-kit) p11-kit
79 ++ lib.optional (tpmSupport && stdenv.isLinux) trousers
80 ++ lib.optional guileBindings guile;
82 nativeBuildInputs = [ perl pkg-config ]
83 ++ lib.optionals (isDarwin && !withSecurity) [ autoconf automake ]
84 ++ lib.optionals doCheck [ which nettools util-linux ];
86 propagatedBuildInputs = [ nettle ]
87 # Builds dynamically linking against gnutls seem to need the framework now.
88 ++ lib.optional (isDarwin && withSecurity) Security;
91 # stdenv's `NIX_SSL_CERT_FILE=/no-cert-file.crt` breaks tests.
92 # Also empty files won't work, and we want to avoid potentially impure /etc/
93 preCheck = "NIX_SSL_CERT_FILE=${./dummy.crt}";
95 # Fixup broken libtool and pkg-config files
96 preFixup = lib.optionalString (!isDarwin) ''
97 sed ${lib.optionalString tpmSupport "-e 's,-ltspi,-L${trousers}/lib -ltspi,'"} \
98 -e 's,-lz,-L${zlib.out}/lib -lz,' \
99 -e 's,-L${gmp.dev}/lib,-L${gmp.out}/lib,' \
100 -e 's,-lgmp,-L${gmp.out}/lib -lgmp,' \
101 -i $out/lib/*.la "$dev/lib/pkgconfig/gnutls.pc"
103 # It seems only useful for static linking but basically noone does that.
104 substituteInPlace "$out/lib/libgnutls.la" \
105 --replace "-lunistring" ""
109 description = "The GNU Transport Layer Security Library";
112 GnuTLS is a project that aims to develop a library which
113 provides a secure layer, over a reliable transport
114 layer. Currently the GnuTLS library implements the proposed standards by
115 the IETF's TLS working group.
117 Quoting from the TLS protocol specification:
119 "The TLS protocol provides communications privacy over the
120 Internet. The protocol allows client/server applications to
121 communicate in a way that is designed to prevent eavesdropping,
122 tampering, or message forgery."
125 homepage = "https://gnutls.org/";
126 license = licenses.lgpl21Plus;
127 maintainers = with maintainers; [ vcunat ];
128 platforms = platforms.all;