Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nix
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5512bdd06df2
Choose a base ref
...
head repository: NixOS/nix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0cb81acdcc25
Choose a head ref
  • 1 commit
  • 35 files changed
  • 1 contributor

Commits on Mar 30, 2020

  1. 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 (c169ea5).
    edolstra committed Mar 30, 2020
    Copy the full SHA
    0cb81ac View commit details
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ makefiles = \
nix-rust/local.mk \
src/libutil/local.mk \
src/libstore/local.mk \
src/libfetchers/local.mk \
src/libmain/local.mk \
src/libexpr/local.mk \
src/nix/local.mk \
8 changes: 5 additions & 3 deletions src/libexpr/common-eval-args.cc
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@
#include "download.hh"
#include "util.hh"
#include "eval.hh"
#include "fetchers.hh"
#include "store-api.hh"

namespace nix {

@@ -46,9 +48,9 @@ Bindings * MixEvalArgs::getAutoArgs(EvalState & state)
Path lookupFileArg(EvalState & state, string s)
{
if (isUri(s)) {
CachedDownloadRequest request(s);
request.unpack = true;
return getDownloader()->downloadCached(state.store, request).path;
return state.store->toRealPath(
fetchers::downloadTarball(
state.store, resolveUri(s), "source", false).storePath);
} else if (s.size() > 2 && s.at(0) == '<' && s.at(s.size() - 1) == '>') {
Path p = s.substr(1, s.size() - 2);
return state.findFile(p);
4 changes: 2 additions & 2 deletions src/libexpr/local.mk
Original file line number Diff line number Diff line change
@@ -6,9 +6,9 @@ libexpr_DIR := $(d)

libexpr_SOURCES := $(wildcard $(d)/*.cc) $(wildcard $(d)/primops/*.cc) $(d)/lexer-tab.cc $(d)/parser-tab.cc

libexpr_CXXFLAGS += -I src/libutil -I src/libstore -I src/libmain -I src/libexpr
libexpr_CXXFLAGS += -I src/libutil -I src/libstore -I src/libfetchers -I src/libmain -I src/libexpr

libexpr_LIBS = libutil libstore libnixrust
libexpr_LIBS = libutil libstore libfetchers libnixrust

libexpr_LDFLAGS =
ifneq ($(OS), FreeBSD)
6 changes: 3 additions & 3 deletions src/libexpr/parser.y
Original file line number Diff line number Diff line change
@@ -545,6 +545,7 @@ formal

#include "eval.hh"
#include "download.hh"
#include "fetchers.hh"
#include "store-api.hh"


@@ -687,9 +688,8 @@ std::pair<bool, std::string> EvalState::resolveSearchPathElem(const SearchPathEl

if (isUri(elem.second)) {
try {
CachedDownloadRequest request(elem.second);
request.unpack = true;
res = { true, getDownloader()->downloadCached(store, request).path };
res = { true, store->toRealPath(fetchers::downloadTarball(
store, resolveUri(elem.second), "source", false).storePath) };
} catch (DownloadError & e) {
printError(format("warning: Nix search path entry '%1%' cannot be downloaded, ignoring") % elem.second);
res = { false, "" };
67 changes: 0 additions & 67 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "archive.hh"
#include "derivations.hh"
#include "download.hh"
#include "eval-inline.hh"
#include "eval.hh"
#include "globals.hh"
@@ -2045,68 +2044,6 @@ static void prim_splitVersion(EvalState & state, const Pos & pos, Value * * args
}


/*************************************************************
* Networking
*************************************************************/


void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
const string & who, bool unpack, const std::string & defaultName)
{
CachedDownloadRequest request("");
request.unpack = unpack;
request.name = defaultName;

state.forceValue(*args[0]);

if (args[0]->type == tAttrs) {

state.forceAttrs(*args[0], pos);

for (auto & attr : *args[0]->attrs) {
string n(attr.name);
if (n == "url")
request.uri = state.forceStringNoCtx(*attr.value, *attr.pos);
else if (n == "sha256")
request.expectedHash = Hash(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256);
else if (n == "name")
request.name = state.forceStringNoCtx(*attr.value, *attr.pos);
else
throw EvalError(format("unsupported argument '%1%' to '%2%', at %3%") % attr.name % who % attr.pos);
}

if (request.uri.empty())
throw EvalError(format("'url' argument required, at %1%") % pos);

} else
request.uri = state.forceStringNoCtx(*args[0], pos);

state.checkURI(request.uri);

if (evalSettings.pureEval && !request.expectedHash)
throw Error("in pure evaluation mode, '%s' requires a 'sha256' argument", who);

auto res = getDownloader()->downloadCached(state.store, request);

if (state.allowedPaths)
state.allowedPaths->insert(res.path);

mkString(v, res.storePath, PathSet({res.storePath}));
}


static void prim_fetchurl(EvalState & state, const Pos & pos, Value * * args, Value & v)
{
fetch(state, pos, args, v, "fetchurl", false, "");
}


static void prim_fetchTarball(EvalState & state, const Pos & pos, Value * * args, Value & v)
{
fetch(state, pos, args, v, "fetchTarball", true, "source");
}


/*************************************************************
* Primop registration
*************************************************************/
@@ -2289,10 +2226,6 @@ void EvalState::createBaseEnv()
addPrimOp("derivationStrict", 1, prim_derivationStrict);
addPrimOp("placeholder", 1, prim_placeholder);

// Networking
addPrimOp("__fetchurl", 1, prim_fetchurl);
addPrimOp("fetchTarball", 1, prim_fetchTarball);

/* Add a wrapper around the derivation primop that computes the
`drvPath' and `outPath' attributes lazily. */
string path = canonPath(settings.nixDataDir + "/nix/corepkgs/derivation.nix", true);
1 change: 1 addition & 0 deletions src/libexpr/primops.hh
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ struct RegisterPrimOp
them. */
/* Load a ValueInitializer from a DSO and return whatever it initializes */
void prim_importNative(EvalState & state, const Pos & pos, Value * * args, Value & v);

/* Execute a program and parse its output */
void prim_exec(EvalState & state, const Pos & pos, Value * * args, Value & v);

Loading