1 { lib, stdenv, fetchurl, buildPackages, perl, coreutils
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.
13 lib.assertMsg (!withPerl -> stdenv.hostPlatform != stdenv.buildPlatform)
14 "withPerl should not be disabled unless cross compiling"
17 # Note: this package is used for bootstrapping fetchurl, and thus
18 # cannot use fetchpatch! All mutable patches (generated by GitHub or
19 # cgit) that are needed here should be included directly in Nixpkgs as
25 common = { version, sha256, patches ? [], withDocs ? false, extraMeta ? {} }:
26 stdenv.mkDerivation rec {
31 url = "https://www.openssl.org/source/${pname}-${version}.tar.gz";
38 patchShebangs Configure
39 '' + optionalString (versionOlder version "1.1.0") ''
42 substituteInPlace "$a" \
45 '' + optionalString (versionAtLeast version "1.1.1") ''
46 substituteInPlace config --replace '/usr/bin/env' '${coreutils}/bin/env'
47 '' + optionalString (versionAtLeast version "1.1.0" && stdenv.hostPlatform.isMusl) ''
48 substituteInPlace crypto/async/arch/async_posix.h \
49 --replace '!defined(__ANDROID__) && !defined(__OpenBSD__)' \
50 '!defined(__ANDROID__) && !defined(__OpenBSD__) && 0'
53 outputs = [ "bin" "dev" "out" "man" ] ++ optional withDocs "doc";
54 setOutputFlags = false;
55 separateDebugInfo = !(stdenv.hostPlatform.useLLVM or false) && stdenv.cc.isGNU;
57 nativeBuildInputs = [ perl ];
58 buildInputs = lib.optional withCryptodev cryptodev
59 # perl is included to allow the interpreter path fixup hook to set the
60 # correct interpreter in c_rehash.
61 ++ lib.optional withPerl perl;
63 # TODO(@Ericson2314): Improve with mass rebuild
64 configurePlatforms = [];
66 armv5tel-linux = "./Configure linux-armv4 -march=armv5te";
67 armv6l-linux = "./Configure linux-armv4 -march=armv6";
68 armv7l-linux = "./Configure linux-armv4 -march=armv7-a";
69 x86_64-darwin = "./Configure darwin64-x86_64-cc";
70 x86_64-linux = "./Configure linux-x86_64";
71 x86_64-solaris = "./Configure solaris64-x86_64-gcc";
72 }.${stdenv.hostPlatform.system} or (
73 if stdenv.hostPlatform == stdenv.buildPlatform
75 else if stdenv.hostPlatform.isMinGW
76 then "./Configure mingw${optionalString
77 (stdenv.hostPlatform.parsed.cpu.bits != 32)
78 (toString stdenv.hostPlatform.parsed.cpu.bits)}"
79 else if stdenv.hostPlatform.isLinux
80 then (if stdenv.hostPlatform.isx86_64
81 then "./Configure linux-x86_64"
82 else "./Configure linux-generic${toString stdenv.hostPlatform.parsed.cpu.bits}")
83 else if stdenv.hostPlatform.isiOS
84 then "./Configure ios${toString stdenv.hostPlatform.parsed.cpu.bits}-cross"
86 throw "Not sure what configuration to use for ${stdenv.hostPlatform.config}"
90 "shared" # "shared" builds both shared and static libraries
92 "--openssldir=etc/ssl"
93 ] ++ lib.optionals withCryptodev [
95 "-DUSE_CRYPTODEV_DIGESTS"
96 ] ++ lib.optional enableSSL2 "enable-ssl2"
97 ++ lib.optional enableSSL3 "enable-ssl3"
98 ++ lib.optional (versionAtLeast version "1.1.0" && stdenv.hostPlatform.isAarch64) "no-afalgeng"
99 # OpenSSL needs a specific `no-shared` configure flag.
100 # See https://wiki.openssl.org/index.php/Compilation_and_Installation#Configure_Options
101 # for a comprehensive list of configuration options.
102 ++ lib.optional (versionAtLeast version "1.1.0" && static) "no-shared";
105 "MANDIR=$(man)/share/man"
106 # This avoids conflicts between man pages of openssl subcommands (for
107 # example 'ts' and 'err') man pages and their equivalent top-level
108 # command in other packages (respectively man-pages and moreutils).
109 # This is done in ubuntu and archlinux, and possiibly many other distros.
113 enableParallelBuilding = true;
116 lib.optionalString (!static) ''
117 # If we're building dynamic libraries, then don't install static
119 if [ -n "$(echo $out/lib/*.so $out/lib/*.dylib $out/lib/*.dll)" ]; then
124 '' + lib.optionalString (!stdenv.hostPlatform.isWindows)
125 # Fix bin/c_rehash's perl interpreter line
127 # - openssl 1_0_2: embeds a reference to buildPackages.perl
128 # - openssl 1_1: emits "#!/usr/bin/env perl"
130 # In the case of openssl_1_0_2, reset the invalid reference and let the
131 # interpreter hook take care of it.
133 # In both cases, if withPerl = false, the intepreter line is expected be
134 # "#!/usr/bin/env perl"
136 substituteInPlace $out/bin/c_rehash --replace ${buildPackages.perl}/bin/perl "/usr/bin/env perl"
142 mv $out/include $dev/
144 # remove dependency on Perl at runtime
145 rm -r $out/etc/ssl/misc
147 rmdir $out/etc/ssl/{certs,private}
150 postFixup = lib.optionalString (!stdenv.hostPlatform.isWindows) ''
151 # Check to make sure the main output doesn't depend on perl
152 if grep -r '${buildPackages.perl}' $out; then
153 echo "Found an erroneous dependency on perl ^^^" >&2
159 homepage = "https://www.openssl.org/";
160 description = "A cryptographic library that implements the SSL and TLS protocols";
161 license = licenses.openssl;
162 platforms = platforms.all;
163 maintainers = [ maintainers.peti ];
169 openssl_1_0_2 = common {
171 sha256 = "ecd0c6ffb493dd06707d38b14bb4d8c2288bb7033735606569d8f90f89669d16";
173 ./1.0.2/nix-ssl-cert-file.patch
175 (if stdenv.hostPlatform.isDarwin
176 then ./1.0.2/use-etc-ssl-certs-darwin.patch
177 else ./1.0.2/use-etc-ssl-certs.patch)
179 extraMeta.knownVulnerabilities = [ "Support for OpenSSL 1.0.2 ended with 2019." ];
182 openssl_1_1 = common {
184 sha256 = "1rdfzcrxy9y38wqdw5942vmdax9hjhgrprzxm42csal7p5shhal9";
186 ./1.1/nix-ssl-cert-file.patch
188 (if stdenv.hostPlatform.isDarwin
189 then ./1.1/use-etc-ssl-certs-darwin.patch
190 else ./1.1/use-etc-ssl-certs.patch)