16#include "nix/store/config.hh"
24const std::filesystem::path & nixConfDir();
26class FileTransferSettings :
public Config
28 static std::optional<std::filesystem::path> getDefaultSSLCertFile();
30 void anchor()
override;
33 FileTransferSettings();
35 Setting<bool> enableHttp2{
this,
true,
"http2",
"Whether to enable HTTP/2 support."};
42 Whether to try enabling HTTP/3 (QUIC).
43 When enabled, Nix requests HTTP/3 and transparently falls back
44 to HTTP/2 or HTTP/1.1 for servers that do not support it.
45 This option has no effect unless the `nix` binary is linked
46 against a libcurl built with HTTP/3 (QUIC) support.
50 this,
"",
"user-agent-suffix",
"String appended to the user agent in HTTP requests."};
57 The maximum number of parallel TCP connections used to fetch
58 files from binary caches and by other downloads. It defaults
59 to 25. 0 means no limit.
61 {"binary-caches-parallel-connections"}};
76 The timeout (in seconds) for establishing connections in the
77 binary cache substituter. It corresponds to `curl`’s
78 `--connect-timeout` option. A value of 0 means no limit.
84 "stalled-download-timeout",
86 The timeout (in seconds) for receiving data from servers
87 during download. Nix cancels idle downloads after this
94 "filetransfer-retry-attempts",
96 The number of times Nix attempts a file transfer (download
97 or upload) before giving up. Retries apply to transient
98 failures: connection-level errors, HTTP 408, 429, and most
99 5xx responses. Authentication failures (401/403/407),
100 404/410, and other 4xx responses are not retried.
102 {"download-attempts"}};
107 "filetransfer-retry-delay",
109 Initial delay in milliseconds before retrying a failed file transfer
110 (download or upload). The delay doubles with each subsequent attempt
111 (exponential backoff) and is subject to random jitter (see
112 `filetransfer-retry-jitter`).
118 "filetransfer-retry-delay-rate-limited",
120 Initial delay in milliseconds before retrying a file transfer that
121 failed with a rate-limit response (HTTP 429 or 503). The delay doubles
122 with each subsequent attempt.
124 Servers may send a `Retry-After` header specifying a longer delay;
125 when present, Nix respects the larger of the two values.
131 "filetransfer-retry-max-delay",
133 Ceiling on the exponential backoff delay in milliseconds. This does not
134 cap server-provided `Retry-After` values, which are honored as-is.
140 "filetransfer-retry-jitter",
142 Whether to apply random jitter to retry delays. When enabled, each
143 retry waits for a random duration between 0 and the computed delay
144 ("full jitter"), which spreads out retry storms from many clients.
146 Disable for deterministic retry timing (primarily useful for tests).
152 "download-buffer-size",
154 The size of Nix's internal download buffer in bytes during `curl` transfers. If data is
155 not processed quickly enough to exceed the size of this buffer, downloads may stall.
156 The default is 1048576 (1 MiB).
164 Specify the maximum transfer rate in kilobytes per second you want
165 Nix to use for downloads.
170 nixConfDir() /
"netrc",
173 If set to an absolute path to a `netrc` file, Nix uses the HTTP
174 authentication credentials in this file when trying to download from
175 a remote host through HTTP or HTTPS. Defaults to
176 `$NIX_CONF_DIR/netrc`.
178 The `netrc` file consists of a list of accounts in the following
185 For the exact syntax, see [the `curl`
186 documentation](https://ec.haxx.se/usingcurl-netrc.html).
190 > This must be an absolute path, and `~` is not resolved. For
191 > example, `~/.netrc` won't resolve to your home directory's
197 getDefaultSSLCertFile(),
200 The path of a file containing CA certificates used to
201 authenticate `https://` downloads. Nix by default uses
202 the first of the following files that exists:
204 1. `/etc/ssl/certs/ca-certificates.crt`
205 2. `/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt`
207 The path can be overridden by the following environment
208 variables, in order of precedence:
210 1. `NIX_SSL_CERT_FILE`
238 std::string username;
239 std::optional<std::string> password;
242enum class PauseTransfer :
bool {
247struct FileTransferRequest
251 std::string expectedETag;
253 ActivityId parentAct;
254 bool decompress =
true;
262 std::optional<uint32_t> retryDelayRateLimitedMs;
263 std::optional<uint32_t> retryMaxDelayMs;
264 std::optional<uint32_t> retryAttempts;
274 std::optional<std::filesystem::path>
tlsKey;
279 : sizeHint(s.s.length())
290 std::size_t sizeHint = 0;
294 std::optional<UploadData> data;
295 std::string mimeType;
314 std::optional<std::string> preResolvedAwsSessionToken;
318 : uri(std::move(uri))
319 , parentAct(getCurActivity())
334 std::string
verb(
bool continuous =
false)
const
337 case HttpMethod::Head:
338 case HttpMethod::Get:
339 return continuous ?
"downloading" :
"download";
340 case HttpMethod::Put:
341 case HttpMethod::Post:
343 return continuous ?
"uploading" :
"upload";
344 case HttpMethod::Delete:
345 return continuous ?
"deleting" :
"delete";
350 std::string noun()
const
353 case HttpMethod::Head:
354 case HttpMethod::Get:
356 case HttpMethod::Put:
357 case HttpMethod::Post:
360 case HttpMethod::Delete:
369 friend struct curlFileTransfer;
371 std::optional<std::string> awsSigV4Provider;
401 uint64_t bodySize = 0;
425 std::weak_ptr<Item> item;
426 friend struct FileTransfer;
428 explicit ItemHandle(std::weak_ptr<Item> item)
473 enum Error { NotFound, Unauthorized, Forbidden, Misc, Transient };
491class FileTransferError final :
public CloneableError<FileTransferError, Error>
494 void anchor()
override;
497 FileTransfer::Error error;
501 template<
typename...
Args>
502 FileTransferError(FileTransfer::Error error, std::optional<std::string>
response,
Args &&... args);
Definition callback.hh:19
std::optional< std::string > response
intentionally optional
Definition filetransfer.hh:499
Definition filetransfer.hh:27
Definition filetransfer.hh:417
Definition serialise.hh:183
Definition configuration.hh:476
Definition store-api.hh:397
Definition serialise.hh:315
HttpMethod
Definition filetransfer.hh:223
Definition filetransfer.hh:248
std::function< PauseTransfer(std::string_view data)> dataCallback
Definition filetransfer.hh:302
std::string displayUri() const
Definition filetransfer.cc:1335
std::optional< std::filesystem::path > tlsKey
Definition filetransfer.hh:274
std::optional< uint32_t > retryDelayMs
Definition filetransfer.hh:261
std::optional< UsernameAuth > usernameAuth
Definition filetransfer.hh:308
std::string verb(bool continuous=false) const
Definition filetransfer.hh:334
std::optional< std::filesystem::path > tlsCert
Definition filetransfer.hh:269
Definition filetransfer.hh:376
std::string data
Definition filetransfer.hh:399
std::vector< std::string > urls
Definition filetransfer.hh:394
bool cached
Definition filetransfer.hh:381
std::optional< std::string > immutableUrl
Definition filetransfer.hh:408
std::string etag
Definition filetransfer.hh:386
Definition filetransfer.hh:424
Definition filetransfer.hh:414
FileTransferResult download(const FileTransferRequest &request)
Definition filetransfer.cc:1392
FileTransferResult upload(const FileTransferRequest &request)
Definition filetransfer.cc:1397
virtual ItemHandle enqueueFileTransfer(const FileTransferRequest &request, Callback< FileTransferResult > callback)=0
FileTransferResult deleteResource(const FileTransferRequest &request)
Definition filetransfer.cc:1403
virtual void unpauseTransfer(ItemHandle handle)=0
Definition serialise.hh:18
Definition filetransfer.hh:237