1 { lib, stdenv, fetchurl, m4
3 , withStatic ? stdenv.hostPlatform.isStatic
6 let inherit (lib) optional; in
8 let self = stdenv.mkDerivation rec {
12 src = fetchurl { # we need to use bz2, others aren't in bootstrapping stdenv
13 urls = [ "mirror://gnu/gmp/gmp-${version}.tar.bz2" "ftp://ftp.gmplib.org/pub/gmp-${version}/gmp-${version}.tar.bz2" ];
14 sha256 = "0q5i39pxrasgn9qdxzpfbwhh11ph80p57x6hf48m74261d97j83m";
17 #outputs TODO: split $cxx due to libstdc++ dependency
18 # maybe let ghc use a version with *.so shared with rest of nixpkgs and *.a added
19 # - see #5855 for related discussion
20 outputs = [ "out" "dev" "info" ];
21 passthru.static = self.out;
23 nativeBuildInputs = [ m4 ];
26 ./5.1.3-CVE-2021-43618.patch
27 ] ++ lib.optionals stdenv.isDarwin [
33 (lib.enableFeature cxx "cxx")
34 # Build a "fat binary", with routines for several sub-architectures
35 # (x86), except on Solaris where some tests crash with "Memory fault".
36 # See <https://hydra.nixos.org/build/2760931>, for instance.
38 # no darwin because gmp uses ASM that clang doesn't like
39 (lib.enableFeature (!stdenv.isSunOS && stdenv.hostPlatform.isx86) "fat")
40 # The config.guess in GMP tries to runtime-detect various
41 # ARM optimization flags via /proc/cpuinfo (and is also
42 # broken on multicore CPUs). Avoid this impurity.
43 "--build=${stdenv.buildPlatform.config}"
44 ] ++ optional (cxx && stdenv.isDarwin) "CPPFLAGS=-fexceptions"
45 ++ optional (stdenv.isDarwin && stdenv.is64bit) "ABI=64"
50 dontDisableStatic = withStatic;
52 enableParallelBuilding = true;
55 homepage = "https://gmplib.org/";
56 description = "GNU multiple precision arithmetic library";
57 license = licenses.gpl3Plus;
60 '' GMP is a free library for arbitrary precision arithmetic, operating
61 on signed integers, rational numbers, and floating point numbers.
62 There is no practical limit to the precision except the ones implied
63 by the available memory in the machine GMP runs on. GMP has a rich
64 set of functions, and the functions have a regular interface.
66 The main target applications for GMP are cryptography applications
67 and research, Internet security applications, algebra systems,
68 computational algebra research, etc.
70 GMP is carefully designed to be as fast as possible, both for small
71 operands and for huge operands. The speed is achieved by using
72 fullwords as the basic arithmetic type, by using fast algorithms,
73 with highly optimised assembly code for the most common inner loops
74 for a lot of CPUs, and by a general emphasis on speed.
76 GMP is faster than any other bignum library. The advantage for GMP
77 increases with the operand sizes for many operations, since GMP uses
78 asymptotically faster algorithms.
81 platforms = platforms.all;
82 badPlatforms = [ "x86_64-darwin" ];