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: 543288b6494f
Choose a base ref
...
head repository: NixOS/nix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9a5ca802c711
Choose a head ref
  • 5 commits
  • 13 files changed
  • 1 contributor

Commits on Jan 22, 2020

  1. Copy the full SHA
    32f31a8 View commit details
  2. Fix 'nix flake update'

    edolstra committed Jan 22, 2020
    Copy the full SHA
    90d55ed View commit details
  3. Copy the full SHA
    b5c9dbc View commit details
  4. resolveFlake -> lockFlake

    "resolve" is ambiguous (also used for registry resolution).
    edolstra committed Jan 22, 2020
    Copy the full SHA
    872a22f View commit details
  5. Copy the full SHA
    9a5ca80 View commit details
6 changes: 5 additions & 1 deletion 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/registry.hh"
#include "flake/flakeref.hh"

namespace nix {

@@ -40,7 +42,9 @@ MixEvalArgs::MixEvalArgs()
.description("override a flake registry value")
.arity(2)
.handler([&](std::vector<std::string> ss) {
registryOverrides.push_back(std::make_pair(ss[0], ss[1]));
fetchers::overrideRegistry(
parseFlakeRef(ss[0], absPath(".")).input,
parseFlakeRef(ss[1], absPath(".")).input);
});
}

2 changes: 0 additions & 2 deletions src/libexpr/common-eval-args.hh
Original file line number Diff line number Diff line change
@@ -16,8 +16,6 @@ struct MixEvalArgs : virtual Args

Strings searchPath;

std::vector<std::pair<std::string, std::string>> registryOverrides;

private:

std::map<std::string, std::string> autoArgs;
20 changes: 9 additions & 11 deletions src/libexpr/flake/flake.cc
Original file line number Diff line number Diff line change
@@ -302,7 +302,10 @@ static std::pair<Flake, LockedInput> updateLocks(

/* Compute an in-memory lockfile for the specified top-level flake,
and optionally write it to file, it the flake is writable. */
ResolvedFlake resolveFlake(EvalState & state, const FlakeRef & topRef, HandleLockFile handleLockFile)
LockedFlake lockFlake(
EvalState & state,
const FlakeRef & topRef,
HandleLockFile handleLockFile)
{
settings.requireExperimentalFeature("flakes");

@@ -356,12 +359,7 @@ ResolvedFlake resolveFlake(EvalState & state, const FlakeRef & topRef, HandleLoc
warn("using updated lock file without writing it to file");
}

return ResolvedFlake { .flake = std::move(flake), .lockFile = std::move(lockFile) };
}

void updateLockFile(EvalState & state, const FlakeRef & flakeRef, bool recreateLockFile)
{
resolveFlake(state, flakeRef, recreateLockFile ? RecreateLockFile : UpdateLockFile);
return LockedFlake { .flake = std::move(flake), .lockFile = std::move(lockFile) };
}

static void emitSourceInfoAttrs(EvalState & state, const fetchers::Tree & sourceInfo, Value & vAttrs)
@@ -480,24 +478,24 @@ void callFlake(EvalState & state,
}

void callFlake(EvalState & state,
const ResolvedFlake & resFlake,
const LockedFlake & lockedFlake,
Value & v)
{
callFlake(state, resFlake.flake, resFlake.lockFile, v);
callFlake(state, lockedFlake.flake, lockedFlake.lockFile, v);
}

// This function is exposed to be used in nix files.
static void prim_getFlake(EvalState & state, const Pos & pos, Value * * args, Value & v)
{
callFlake(state, resolveFlake(state, parseFlakeRef(state.forceStringNoCtx(*args[0], pos)),
callFlake(state, lockFlake(state, parseFlakeRef(state.forceStringNoCtx(*args[0], pos)),
evalSettings.pureEval ? AllPure : UseUpdatedLockFile), v);
}

static RegisterPrimOp r2("getFlake", 1, prim_getFlake);

}

Fingerprint ResolvedFlake::getFingerprint() const
Fingerprint LockedFlake::getFingerprint() const
{
// FIXME: as an optimization, if the flake contains a lock file
// and we haven't changed it, then it's sufficient to use
10 changes: 4 additions & 6 deletions src/libexpr/flake/flake.hh
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ struct Flake
{
FlakeRef originalRef;
FlakeRef resolvedRef;
std::string description;
std::optional<std::string> description;
std::shared_ptr<const fetchers::Tree> sourceInfo;
std::map<FlakeId, FlakeInput> inputs;
Value * vOutputs; // FIXME: gc
@@ -46,27 +46,25 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool allowLookup);
/* Fingerprint of a locked flake; used as a cache key. */
typedef Hash Fingerprint;

struct ResolvedFlake
struct LockedFlake
{
Flake flake;
LockFile lockFile;

Fingerprint getFingerprint() const;
};

ResolvedFlake resolveFlake(EvalState &, const FlakeRef &, HandleLockFile);
LockedFlake lockFlake(EvalState &, const FlakeRef &, HandleLockFile);

void callFlake(EvalState & state,
const Flake & flake,
const LockedInputs & inputs,
Value & v);

void callFlake(EvalState & state,
const ResolvedFlake & resFlake,
const LockedFlake & resFlake,
Value & v);

void updateLockFile(EvalState &, const FlakeRef & flakeRef, bool recreateLockFile);

}

}
4 changes: 4 additions & 0 deletions src/libstore/fetchers/fetchers.hh
Original file line number Diff line number Diff line change
@@ -27,6 +27,8 @@ struct Input : std::enable_shared_from_this<Input>
std::string type;
std::optional<Hash> narHash;

virtual ~Input() { }

virtual bool operator ==(const Input & other) const { return false; }

virtual bool isDirect() const { return true; }
@@ -63,6 +65,8 @@ struct ParsedURL;

struct InputScheme
{
virtual ~InputScheme() { }

virtual std::unique_ptr<Input> inputFromURL(const ParsedURL & url) = 0;
};

5 changes: 3 additions & 2 deletions src/libstore/fetchers/git.cc
Original file line number Diff line number Diff line change
@@ -142,7 +142,7 @@ struct GitInput : Input
return res;
}

std::optional<Path> getSourcePath() const
std::optional<Path> getSourcePath() const override
{
if (url.scheme == "git+file" && !ref && !rev)
return url.path;
@@ -172,7 +172,8 @@ struct GitInput : Input
return {std::move(*tree), input};
}

auto [isLocal, actualUrl] = getActualUrl();
auto [isLocal, actualUrl_] = getActualUrl();
auto actualUrl = actualUrl_; // work around clang bug

// If this is a local directory and no ref or revision is
// given, then allow the use of an unclean working tree.
3 changes: 2 additions & 1 deletion src/libstore/fetchers/mercurial.cc
Original file line number Diff line number Diff line change
@@ -84,7 +84,8 @@ struct MercurialInput : Input

auto input = std::make_shared<MercurialInput>(*this);

auto [isLocal, actualUrl] = getActualUrl();
auto [isLocal, actualUrl_] = getActualUrl();
auto actualUrl = actualUrl_; // work around clang bug

// FIXME: return lastModified.

26 changes: 14 additions & 12 deletions src/libstore/fetchers/registry.cc
Original file line number Diff line number Diff line change
@@ -11,11 +11,10 @@ namespace nix::fetchers {
std::shared_ptr<Registry> Registry::read(
const Path & path, RegistryType type)
{
auto registry = std::make_shared<Registry>();
registry->type = type;
auto registry = std::make_shared<Registry>(type);

if (!pathExists(path))
return std::make_shared<Registry>();
return std::make_shared<Registry>(type);

auto json = nlohmann::json::parse(readFile(path));

@@ -74,17 +73,20 @@ std::shared_ptr<Registry> getUserRegistry()
return Registry::read(getUserRegistryPath(), Registry::User);
}

#if 0
std::shared_ptr<Registry> getFlagRegistry(RegistryOverrides registryOverrides)
static std::shared_ptr<Registry> flagRegistry =
std::make_shared<Registry>(Registry::Flag);

std::shared_ptr<Registry> getFlagRegistry()
{
auto flagRegistry = std::make_shared<Registry>();
for (auto const & x : registryOverrides)
flagRegistry->entries.insert_or_assign(
parseFlakeRef2(x.first),
parseFlakeRef2(x.second));
return flagRegistry;
}
#endif

void overrideRegistry(
const std::shared_ptr<const Input> & from,
const std::shared_ptr<const Input> & to)
{
flagRegistry->add(from, to);
}

static std::shared_ptr<Registry> getGlobalRegistry(ref<Store> store)
{
@@ -107,7 +109,7 @@ static std::shared_ptr<Registry> getGlobalRegistry(ref<Store> store)
Registries getRegistries(ref<Store> store)
{
Registries registries;
//registries.push_back(getFlagRegistry(registryOverrides));
registries.push_back(getFlagRegistry());
registries.push_back(getUserRegistry());
registries.push_back(getGlobalRegistry(store));
return registries;
8 changes: 8 additions & 0 deletions src/libstore/fetchers/registry.hh
Original file line number Diff line number Diff line change
@@ -20,6 +20,10 @@ struct Registry

std::vector<std::pair<std::shared_ptr<const Input>, std::shared_ptr<const Input>>> entries;

Registry(RegistryType type)
: type(type)
{ }

static std::shared_ptr<Registry> read(
const Path & path, RegistryType type);

@@ -40,6 +44,10 @@ Path getUserRegistryPath();

Registries getRegistries(ref<Store> store);

void overrideRegistry(
const std::shared_ptr<const Input> & from,
const std::shared_ptr<const Input> & to);

std::shared_ptr<const Input> lookupInRegistries(
ref<Store> store,
std::shared_ptr<const Input> input);
32 changes: 13 additions & 19 deletions src/nix/flake.cc
Original file line number Diff line number Diff line change
@@ -41,9 +41,9 @@ class FlakeCommand : virtual Args, public EvalCommand, public MixFlakeOptions
return flake::getFlake(*evalState, getFlakeRef(), useRegistries);
}

ResolvedFlake resolveFlake()
LockedFlake lockFlake()
{
return flake::resolveFlake(*getEvalState(), getFlakeRef(), getLockFileMode());
return flake::lockFlake(*getEvalState(), getFlakeRef(), getLockFileMode());
}
};

@@ -80,7 +80,8 @@ static void printFlakeInfo(const Store & store, const Flake & flake)
{
std::cout << fmt("URL: %s\n", flake.resolvedRef.input->to_string());
std::cout << fmt("Edition: %s\n", flake.edition);
std::cout << fmt("Description: %s\n", flake.description);
if (flake.description)
std::cout << fmt("Description: %s\n", *flake.description);
std::cout << fmt("Path: %s\n", store.printStorePath(flake.sourceInfo->storePath));
if (flake.sourceInfo->rev)
std::cout << fmt("Revision: %s\n", flake.sourceInfo->rev->to_string(Base16, false));
@@ -94,7 +95,8 @@ static void printFlakeInfo(const Store & store, const Flake & flake)
static nlohmann::json flakeToJson(const Store & store, const Flake & flake)
{
nlohmann::json j;
j["description"] = flake.description;
if (flake.description)
j["description"] = *flake.description;
j["edition"] = flake.edition;
j["url"] = flake.resolvedRef.input->to_string();
if (flake.sourceInfo->rev)
@@ -120,16 +122,16 @@ struct CmdFlakeDeps : FlakeCommand
{
auto evalState = getEvalState();

std::queue<ResolvedFlake> todo;
todo.push(resolveFlake());
std::queue<LockedFlake> todo;
todo.push(lockFlake());

stopProgressBar();

while (!todo.empty()) {
auto resFlake = std::move(todo.front());
auto lockedFlake = std::move(todo.front());
todo.pop();

for (auto & info : resFlake.flakeDeps) {
for (auto & info : lockedFlake.flakeDeps) {
printFlakeInfo(*store, info.second.flake);
todo.push(info.second);
}
@@ -148,15 +150,7 @@ struct CmdFlakeUpdate : FlakeCommand
void run(nix::ref<nix::Store> store) override
{
auto evalState = getEvalState();

auto flakeRef = getFlakeRef();

#if 0
if (std::get_if<FlakeRef::IsPath>(&flakeRef.data))
updateLockFile(*evalState, flakeRef, true);
else
throw Error("cannot update lockfile of flake '%s'", flakeRef);
#endif
lockFlake();
}
};

@@ -185,7 +179,7 @@ struct CmdFlakeInfo : FlakeCommand, MixJSON
{
if (json) {
auto state = getEvalState();
auto flake = resolveFlake();
auto flake = lockFlake();

auto json = flakeToJson(*store, flake.flake);

@@ -241,7 +235,7 @@ struct CmdFlakeCheck : FlakeCommand, MixJSON
settings.readOnlyMode = !build;

auto state = getEvalState();
auto flake = resolveFlake();
auto flake = lockFlake();

auto checkSystemName = [&](const std::string & system, const Pos & pos) {
// FIXME: what's the format of "system"?
Loading