mirror of
https://github.com/NixOS/nix
synced 2025-06-28 13:41:15 +02:00
Backport libfetchers from the flakes branch
This provides a pluggable mechanism for defining new fetchers. It adds
a builtin function 'fetchTree' that generalizes existing fetchers like
'fetchGit', 'fetchMercurial' and 'fetchTarball'. 'fetchTree' takes a
set of attributes, e.g.
fetchTree {
type = "git";
url = "https://example.org/repo.git";
ref = "some-branch";
rev = "abcdef...";
}
The existing fetchers are just wrappers around this. Note that the
input attributes to fetchTree are the same as flake input
specifications and flake lock file entries.
All fetchers share a common cache stored in
~/.cache/nix/fetcher-cache-v1.sqlite. This replaces the ad hoc caching
mechanisms in fetchGit and download.cc (e.g. ~/.cache/nix/{tarballs,git-revs*}).
This also adds support for Git worktrees (c169ea5904
).
This commit is contained in:
parent
ebb20a5356
commit
462421d345
36 changed files with 2199 additions and 647 deletions
|
@ -3,6 +3,7 @@
|
|||
#include "download.hh"
|
||||
#include "store-api.hh"
|
||||
#include "../nix/legacy.hh"
|
||||
#include "fetchers.hh"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <regex>
|
||||
|
@ -86,12 +87,9 @@ static void update(const StringSet & channelNames)
|
|||
// We want to download the url to a file to see if it's a tarball while also checking if we
|
||||
// got redirected in the process, so that we can grab the various parts of a nix channel
|
||||
// definition from a consistent location if the redirect changes mid-download.
|
||||
CachedDownloadRequest request(url);
|
||||
request.ttl = 0;
|
||||
auto dl = getDownloader();
|
||||
auto result = dl->downloadCached(store, request);
|
||||
auto filename = result.path;
|
||||
url = chomp(result.effectiveUri);
|
||||
auto result = fetchers::downloadFile(store, url, std::string(baseNameOf(url)), false);
|
||||
auto filename = store->toRealPath(result.storePath);
|
||||
url = result.effectiveUrl;
|
||||
|
||||
// If the URL contains a version number, append it to the name
|
||||
// attribute (so that "nix-env -q" on the channels profile
|
||||
|
@ -114,11 +112,10 @@ static void update(const StringSet & channelNames)
|
|||
if (!unpacked) {
|
||||
// Download the channel tarball.
|
||||
try {
|
||||
filename = dl->downloadCached(store, CachedDownloadRequest(url + "/nixexprs.tar.xz")).path;
|
||||
filename = store->toRealPath(fetchers::downloadFile(store, url + "/nixexprs.tar.xz", "nixexprs.tar.xz", false).storePath);
|
||||
} catch (DownloadError & e) {
|
||||
filename = dl->downloadCached(store, CachedDownloadRequest(url + "/nixexprs.tar.bz2")).path;
|
||||
filename = store->toRealPath(fetchers::downloadFile(store, url + "/nixexprs.tar.bz2", "nixexprs.tar.bz2", false).storePath);
|
||||
}
|
||||
chomp(filename);
|
||||
}
|
||||
|
||||
// Regardless of where it came from, add the expression representing this channel to accumulated expression
|
||||
|
@ -185,6 +182,8 @@ static int _main(int argc, char ** argv)
|
|||
} else if (*arg == "--rollback") {
|
||||
cmd = cRollback;
|
||||
} else {
|
||||
if (hasPrefix(*arg, "-"))
|
||||
throw UsageError("unsupported argument '%s'", *arg);
|
||||
args.push_back(std::move(*arg));
|
||||
}
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue