1 { lib, stdenv, fetchurl, darwin, pkg-config, perl, nixosTests
2 , brotliSupport ? false, brotli
3 , c-aresSupport ? false, c-aresMinimal
4 , gnutlsSupport ? false, gnutls
5 , gsaslSupport ? false, gsasl
6 , gssSupport ? with stdenv.hostPlatform; (
8 # disable gss because of: undefined reference to `k5_bcmp'
9 # a very sad story re static: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=439039
11 # the "mig" tool does not configure its compiler correctly. This could be
12 # fixed in mig, but losing gss support on cross compilation to darwin is
13 # not worth the effort.
14 !(isDarwin && (stdenv.buildPlatform != stdenv.hostPlatform))
16 , http2Support ? true, nghttp2
17 , http3Support ? false, nghttp3, ngtcp2
18 , websocketSupport ? false
19 , idnSupport ? false, libidn2
20 , ldapSupport ? false, openldap
21 , opensslSupport ? zlibSupport, openssl
22 , pslSupport ? false, libpsl
23 , rtmpSupport ? false, rtmpdump
24 , scpSupport ? zlibSupport && !stdenv.hostPlatform.isSunOS && !stdenv.hostPlatform.isCygwin, libssh2
25 , wolfsslSupport ? false, wolfssl
26 , rustlsSupport ? false, rustls-ffi
27 , zlibSupport ? true, zlib
28 , zstdSupport ? false, zstd
43 # Note: this package is used for bootstrapping fetchurl, and thus
44 # cannot use fetchpatch! All mutable patches (generated by GitHub or
45 # cgit) that are needed here should be included directly in Nixpkgs as
48 assert !((lib.count (x: x) [ gnutlsSupport opensslSupport wolfsslSupport rustlsSupport ]) > 1);
50 stdenv.mkDerivation (finalAttrs: {
56 "https://curl.haxx.se/download/curl-${finalAttrs.version}.tar.xz"
57 "https://github.com/curl/curl/releases/download/curl-${builtins.replaceStrings [ "." ] [ "_" ] finalAttrs.version}/curl-${finalAttrs.version}.tar.xz"
59 hash = "sha256-21nPDWccpuf1wsXsF3CEozp54EyX5xzxg6XN6iNQVOs=";
63 # https://github.com/NixOS/nixpkgs/issues/356114
64 # https://github.com/curl/curl/issues/15496
65 # https://github.com/curl/curl/commit/f5c616930b5cf148b1b2632da4f5963ff48bdf88
66 # TODO: Remove this patch when 8.11.1/8.12.0 releases
67 ./fix-netrc-regression.patch
69 # https://github.com/curl/curl/issues/15513
70 # https://github.com/curl/curl/commit/0cdde0fdfbeb8c35420f6d03fa4b77ed73497694
71 ./fix-netrc-regression-2.patch
74 # this could be accomplished by updateAutotoolsGnuConfigScriptsHook, but that causes infinite recursion
75 # necessary for FreeBSD code path in configure
77 substituteInPlace ./config.guess --replace-fail /usr/bin/uname uname
81 outputs = [ "bin" "dev" "out" "man" "devdoc" ];
82 separateDebugInfo = stdenv.hostPlatform.isLinux;
84 enableParallelBuilding = true;
88 env = lib.optionalAttrs (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic) {
89 # Not having this causes curl’s `configure` script to fail with static builds on Darwin because
90 # some of curl’s propagated inputs need libiconv.
91 NIX_LDFLAGS = "-liconv";
94 nativeBuildInputs = [ pkg-config perl ];
96 # Zlib and OpenSSL must be propagated because `libcurl.la' contains
97 # "-lz -lssl", which aren't necessary direct build inputs of
98 # applications that use Curl.
99 propagatedBuildInputs =
100 lib.optional brotliSupport brotli ++
101 lib.optional c-aresSupport c-aresMinimal ++
102 lib.optional gnutlsSupport gnutls ++
103 lib.optional gsaslSupport gsasl ++
104 lib.optional gssSupport libkrb5 ++
105 lib.optional http2Support nghttp2 ++
106 lib.optionals http3Support [ nghttp3 ngtcp2 ] ++
107 lib.optional idnSupport libidn2 ++
108 lib.optional ldapSupport openldap ++
109 lib.optional opensslSupport openssl ++
110 lib.optional pslSupport libpsl ++
111 lib.optional rtmpSupport rtmpdump ++
112 lib.optional scpSupport libssh2 ++
113 lib.optional wolfsslSupport wolfssl ++
114 lib.optional rustlsSupport rustls-ffi ++
115 lib.optional zlibSupport zlib ++
116 lib.optional zstdSupport zstd ++
117 lib.optionals stdenv.hostPlatform.isDarwin (with darwin.apple_sdk.frameworks; [
123 # for the second line see https://curl.haxx.se/mail/tracker-2014-03/0087.html
125 sed -e 's|/usr/bin|/no-such-path|g' -i.bak configure
126 rm src/tool_hugehelp.c
127 '' + lib.optionalString (pslSupport && stdenv.hostPlatform.isStatic) ''
128 # curl doesn't understand that libpsl2 has deps because it doesn't use
130 # https://github.com/curl/curl/pull/12919
131 configureFlagsArray+=("LIBS=-lidn2 -lunistring")
135 "--enable-versioned-symbols"
136 # Build without manual
138 (lib.enableFeature c-aresSupport "ares")
139 (lib.enableFeature ldapSupport "ldap")
140 (lib.enableFeature ldapSupport "ldaps")
141 (lib.enableFeature websocketSupport "websockets")
142 # --with-ca-fallback is only supported for openssl and gnutls https://github.com/curl/curl/blame/curl-8_0_1/acinclude.m4#L1640
143 (lib.withFeature (opensslSupport || gnutlsSupport) "ca-fallback")
144 (lib.withFeature http3Support "nghttp3")
145 (lib.withFeature http3Support "ngtcp2")
146 (lib.withFeature rtmpSupport "librtmp")
147 (lib.withFeature rustlsSupport "rustls")
148 (lib.withFeature zstdSupport "zstd")
149 (lib.withFeature pslSupport "libpsl")
150 (lib.withFeatureAs brotliSupport "brotli" (lib.getDev brotli))
151 (lib.withFeatureAs gnutlsSupport "gnutls" (lib.getDev gnutls))
152 (lib.withFeatureAs idnSupport "libidn2" (lib.getDev libidn2))
153 (lib.withFeatureAs opensslSupport "openssl" (lib.getDev openssl))
154 (lib.withFeatureAs scpSupport "libssh2" (lib.getDev libssh2))
155 (lib.withFeatureAs wolfsslSupport "wolfssl" (lib.getDev wolfssl))
157 ++ lib.optional gssSupport "--with-gssapi=${lib.getDev libkrb5}"
158 # For the 'urandom', maybe it should be a cross-system option
159 ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform)
160 "--with-random=/dev/urandom"
161 ++ lib.optionals stdenv.hostPlatform.isDarwin [
162 # Disable default CA bundle, use NIX_SSL_CERT_FILE or fallback to nss-cacert from the default profile.
163 # Without this curl might detect /etc/ssl/cert.pem at build time on macOS, causing curl to ignore NIX_SSL_CERT_FILE.
164 "--without-ca-bundle"
166 ] ++ lib.optionals (!gnutlsSupport && !opensslSupport && !wolfsslSupport && !rustlsSupport) [
168 ] ++ lib.optionals (rustlsSupport && !stdenv.hostPlatform.isDarwin) [
169 "--with-ca-bundle=/etc/ssl/certs/ca-certificates.crt"
170 ] ++ lib.optionals (gnutlsSupport && !stdenv.hostPlatform.isDarwin) [
171 "--with-ca-path=/etc/ssl/certs"
174 CXX = "${stdenv.cc.targetPrefix}c++";
175 CXXCPP = "${stdenv.cc.targetPrefix}c++ -E";
177 # takes 14 minutes on a 24 core and because many other packages depend on curl
178 # they cannot be run concurrently and are a bottleneck
179 # tests are available in passthru.tests.withCheck
183 '' + lib.optionalString stdenv.hostPlatform.isDarwin ''
184 # bad interaction with sandbox if enabled?
185 rm tests/data/test1453
186 rm tests/data/test1086
187 '' + lib.optionalString stdenv.hostPlatform.isMusl ''
188 # different resolving behaviour?
189 rm tests/data/test1592
193 moveToOutput bin/curl-config "$dev"
195 # Install completions
196 make -C scripts install
197 '' + lib.optionalString scpSupport ''
198 sed '/^dependency_libs/s|${lib.getDev libssh2}|${lib.getLib libssh2}|' -i "$out"/lib/*.la
199 '' + lib.optionalString gnutlsSupport ''
200 ln $out/lib/libcurl${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/libcurl-gnutls${stdenv.hostPlatform.extensions.sharedLibrary}
201 ln $out/lib/libcurl${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/libcurl-gnutls${stdenv.hostPlatform.extensions.sharedLibrary}.4
202 ln $out/lib/libcurl${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/libcurl-gnutls${stdenv.hostPlatform.extensions.sharedLibrary}.4.4.0
206 useThisCurl = attr: attr.override { curl = finalAttrs.finalPackage; };
208 inherit opensslSupport openssl;
210 withCheck = finalAttrs.finalPackage.overrideAttrs (_: { doCheck = true; });
211 fetchpatch = tests.fetchpatch.simple.override { fetchpatch = (fetchpatch.override { fetchurl = useThisCurl fetchurl; }) // { version = 1; }; };
212 curlpp = useThisCurl curlpp;
213 coeurl = useThisCurl coeurl;
214 haskell-curl = useThisCurl haskellPackages.curl;
215 ocaml-curly = useThisCurl ocamlPackages.curly;
216 pycurl = useThisCurl python3.pkgs.pycurl;
217 php-curl = useThisCurl phpExtensions.curl;
218 # error: attribute 'override' missing
219 # Additional checking with support http3 protocol.
220 # nginx-http3 = useThisCurl nixosTests.nginx-http3;
221 nginx-http3 = nixosTests.nginx-http3;
222 pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
223 static = pkgsStatic.curl;
228 changelog = "https://curl.se/ch/${finalAttrs.version}.html";
229 description = "Command line tool for transferring files with URL syntax";
230 homepage = "https://curl.se/";
231 license = lib.licenses.curl;
232 maintainers = with lib.maintainers; [ lovek323 ];
233 platforms = lib.platforms.all;
234 # Fails to link against static brotli or gss
235 broken = stdenv.hostPlatform.isStatic && (brotliSupport || gssSupport);
236 pkgConfigModules = [ "libcurl" ];
237 mainProgram = "curl";