1 { lib, stdenv, fetchurl, buildPackages, perl, coreutils, fetchFromGitHub
2 , withCryptodev ? false, cryptodev
5 , static ? stdenv.hostPlatform.isStatic
6 # Used to avoid cross compiling perl, for example, in darwin bootstrap tools.
7 # This will cause c_rehash to refer to perl via the environment, but otherwise
8 # will produce a perfectly functional openssl binary and library.
9 , withPerl ? stdenv.hostPlatform == stdenv.buildPlatform
13 stdenv.mkDerivation rec {
15 version = "3.0.7+quic1";
17 src = fetchFromGitHub {
20 rev = "openssl-${version}";
21 sha256 = "sha256-ZRS0ZV+/U4PD2lVE+PsUAWSuk5EFg5mOKYlwgY3Ecus=";
25 ../openssl/3.0/nix-ssl-cert-file.patch
27 # openssl will only compile in KTLS if the current kernel supports it.
28 # This patch disables build-time detection.
29 ../openssl/3.0/openssl-disable-kernel-detection.patch
31 (if stdenv.hostPlatform.isDarwin
32 then ../openssl/use-etc-ssl-certs-darwin.patch
33 else ../openssl/use-etc-ssl-certs.patch)
37 patchShebangs Configure
39 # config is a configure script which is not installed.
41 substituteInPlace config --replace '/usr/bin/env' '${buildPackages.coreutils}/bin/env'
42 '' + lib.optionalString stdenv.hostPlatform.isMusl ''
43 substituteInPlace crypto/async/arch/async_posix.h \
44 --replace '!defined(__ANDROID__) && !defined(__OpenBSD__)' \
45 '!defined(__ANDROID__) && !defined(__OpenBSD__) && 0'
48 outputs = [ "bin" "dev" "out" "man" "doc" ];
49 setOutputFlags = false;
51 !stdenv.hostPlatform.isDarwin &&
52 !(stdenv.hostPlatform.useLLVM or false) &&
55 nativeBuildInputs = [ perl removeReferencesTo ];
56 buildInputs = lib.optional withCryptodev cryptodev
57 # perl is included to allow the interpreter path fixup hook to set the
58 # correct interpreter in c_rehash.
59 ++ lib.optional withPerl perl;
61 # TODO(@Ericson2314): Improve with mass rebuild
62 configurePlatforms = [];
64 armv5tel-linux = "./Configure linux-armv4 -march=armv5te";
65 armv6l-linux = "./Configure linux-armv4 -march=armv6";
66 armv7l-linux = "./Configure linux-armv4 -march=armv7-a";
67 x86_64-darwin = "./Configure darwin64-x86_64-cc";
68 aarch64-darwin = "./Configure darwin64-arm64-cc";
69 x86_64-linux = "./Configure linux-x86_64";
70 x86_64-solaris = "./Configure solaris64-x86_64-gcc";
71 riscv64-linux = "./Configure linux64-riscv64";
73 if stdenv.hostPlatform.isMips64n64
74 then "./Configure linux64-mips64"
75 else if stdenv.hostPlatform.isMips64n32
76 then "./Configure linux-mips64"
77 else throw "unsupported ABI for ${stdenv.hostPlatform.system}";
78 }.${stdenv.hostPlatform.system} or (
79 if stdenv.hostPlatform == stdenv.buildPlatform
81 else if stdenv.hostPlatform.isBSD && stdenv.hostPlatform.isx86_64
82 then "./Configure BSD-x86_64"
83 else if stdenv.hostPlatform.isBSD && stdenv.hostPlatform.isx86_32
84 then "./Configure BSD-x86" + lib.optionalString (stdenv.hostPlatform.parsed.kernel.execFormat.name == "elf") "-elf"
85 else if stdenv.hostPlatform.isBSD
86 then "./Configure BSD-generic${toString stdenv.hostPlatform.parsed.cpu.bits}"
87 else if stdenv.hostPlatform.isMinGW
88 then "./Configure mingw${lib.optionalString
89 (stdenv.hostPlatform.parsed.cpu.bits != 32)
90 (toString stdenv.hostPlatform.parsed.cpu.bits)}"
91 else if stdenv.hostPlatform.isLinux
92 then "./Configure linux-generic${toString stdenv.hostPlatform.parsed.cpu.bits}"
93 else if stdenv.hostPlatform.isiOS
94 then "./Configure ios${toString stdenv.hostPlatform.parsed.cpu.bits}-cross"
96 throw "Not sure what configuration to use for ${stdenv.hostPlatform.config}"
99 # OpenSSL doesn't like the `--enable-static` / `--disable-shared` flags.
100 dontAddStaticConfigureFlags = true;
102 "shared" # "shared" builds both shared and static libraries
104 "--openssldir=etc/ssl"
105 ] ++ lib.optionals withCryptodev [
107 "-DUSE_CRYPTODEV_DIGESTS"
108 ] ++ lib.optional enableSSL2 "enable-ssl2"
109 ++ lib.optional enableSSL3 "enable-ssl3"
110 # We select KTLS here instead of the configure-time detection (which we patch out).
111 # KTLS should work on FreeBSD 13+ as well, so we could enable it if someone tests it.
112 ++ lib.optional (stdenv.isLinux && lib.versionAtLeast version "3.0.0") "enable-ktls"
113 ++ lib.optional stdenv.hostPlatform.isAarch64 "no-afalgeng"
114 # OpenSSL needs a specific `no-shared` configure flag.
115 # See https://wiki.openssl.org/index.php/Compilation_and_Installation#Configure_Options
116 # for a comprehensive list of configuration options.
117 ++ lib.optional static "no-shared"
118 # This introduces a reference to the CTLOG_FILE which is undesired when
119 # trying to build binaries statically.
120 ++ lib.optional static "no-ct"
124 "MANDIR=$(man)/share/man"
125 # This avoids conflicts between man pages of openssl subcommands (for
126 # example 'ts' and 'err') man pages and their equivalent top-level
127 # command in other packages (respectively man-pages and moreutils).
128 # This is done in ubuntu and archlinux, and possiibly many other distros.
132 enableParallelBuilding = true;
134 postInstall = (if static then ''
135 # OPENSSLDIR has a reference to self
136 ${removeReferencesTo}/bin/remove-references-to -t $out $out/lib/*.a
138 # If we're building dynamic libraries, then don't install static
140 if [ -n "$(echo $out/lib/*.so $out/lib/*.dylib $out/lib/*.dll)" ]; then
143 '') + lib.optionalString (!stdenv.hostPlatform.isWindows)
144 # Fix bin/c_rehash's perl interpreter line
146 # - openssl 1_0_2: embeds a reference to buildPackages.perl
147 # - openssl 1_1: emits "#!/usr/bin/env perl"
149 # In the case of openssl_1_0_2, reset the invalid reference and let the
150 # interpreter hook take care of it.
152 # In both cases, if withPerl = false, the intepreter line is expected be
153 # "#!/usr/bin/env perl"
155 substituteInPlace $out/bin/c_rehash --replace ${buildPackages.perl}/bin/perl "/usr/bin/env perl"
160 mv $out/include $dev/
161 # remove dependency on Perl at runtime
162 rm -r $out/etc/ssl/misc
163 rmdir $out/etc/ssl/{certs,private}
166 postFixup = lib.optionalString (!stdenv.hostPlatform.isWindows) ''
167 # Check to make sure the main output doesn't depend on perl
168 if grep -r '${buildPackages.perl}' $out; then
169 echo "Found an erroneous dependency on perl ^^^" >&2
175 homepage = "https://quictls.github.io";
176 description = "TLS/SSL and crypto library with QUIC APIs";
177 license = licenses.openssl;
178 platforms = platforms.all;
179 maintainers = with maintainers; [ izorkin ];