linux_xanmod: 5.11.14 -> 5.11.15
[NixPkgs.git] / pkgs / development / libraries / openssl / default.nix
blobfda0c71655a69ec3f8b4f6595b3efa642394669d
1 { lib, stdenv, fetchurl, buildPackages, perl, coreutils
2 , withCryptodev ? false, cryptodev
3 , enableSSL2 ? false
4 , enableSSL3 ? false
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 ? true
12 assert (
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
20 # files.
22 with lib;
24 let
25   common = { version, sha256, patches ? [], withDocs ? false, extraMeta ? {} }:
26    stdenv.mkDerivation rec {
27     pname = "openssl";
28     inherit version;
30     src = fetchurl {
31       url = "https://www.openssl.org/source/${pname}-${version}.tar.gz";
32       inherit sha256;
33     };
35     inherit patches;
37     postPatch = ''
38       patchShebangs Configure
39     '' + optionalString (versionOlder version "1.1.0") ''
40       patchShebangs test/*
41       for a in test/t* ; do
42         substituteInPlace "$a" \
43           --replace /bin/rm rm
44       done
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'
51     '';
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 = [];
65     configureScript = {
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
74           then "./config"
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"
85         else
86           throw "Not sure what configuration to use for ${stdenv.hostPlatform.config}"
87       );
89     configureFlags = [
90       "shared" # "shared" builds both shared and static libraries
91       "--libdir=lib"
92       "--openssldir=etc/ssl"
93     ] ++ lib.optionals withCryptodev [
94       "-DHAVE_CRYPTODEV"
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";
104     makeFlags = [
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.
110       "MANSUFFIX=ssl"
111     ];
113     enableParallelBuilding = true;
115     postInstall =
116     lib.optionalString (!static) ''
117       # If we're building dynamic libraries, then don't install static
118       # libraries.
119       if [ -n "$(echo $out/lib/*.so $out/lib/*.dylib $out/lib/*.dll)" ]; then
120           rm "$out/lib/"*.a
121       fi
123       mkdir -p $bin
124     '' + lib.optionalString (!stdenv.hostPlatform.isWindows)
125       # Fix bin/c_rehash's perl interpreter line
126       #
127       # - openssl 1_0_2: embeds a reference to buildPackages.perl
128       # - openssl 1_1:   emits "#!/usr/bin/env perl"
129       #
130       # In the case of openssl_1_0_2, reset the invalid reference and let the
131       # interpreter hook take care of it.
132       #
133       # In both cases, if withPerl = false, the intepreter line is expected be
134       # "#!/usr/bin/env perl"
135     ''
136       substituteInPlace $out/bin/c_rehash --replace ${buildPackages.perl}/bin/perl "/usr/bin/env perl"
137     '' +
138     ''
139       mv $out/bin $bin/
141       mkdir $dev
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}
148     '';
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
154         exit 1
155       fi
156     '';
158     meta = with lib; {
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 ];
164     } // extraMeta;
165   };
167 in {
169   openssl_1_0_2 = common {
170     version = "1.0.2u";
171     sha256 = "ecd0c6ffb493dd06707d38b14bb4d8c2288bb7033735606569d8f90f89669d16";
172     patches = [
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)
178     ];
179     extraMeta.knownVulnerabilities = [ "Support for OpenSSL 1.0.2 ended with 2019." ];
180   };
182   openssl_1_1 = common {
183     version = "1.1.1k";
184     sha256 = "1rdfzcrxy9y38wqdw5942vmdax9hjhgrprzxm42csal7p5shhal9";
185     patches = [
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)
191     ];
192     withDocs = true;
193   };