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: 42a12f9232c8
Choose a base ref
...
head repository: NixOS/nix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8c75621da626
Choose a head ref
  • 2 commits
  • 6 files changed
  • 1 contributor

Commits on Apr 20, 2020

  1. Revive 'nix search'

    It uses the evaluation cache now rather than the ad hoc JSON cache.
    edolstra committed Apr 20, 2020
    Copy the full SHA
    b69323f View commit details
  2. Fix typo

    edolstra committed Apr 20, 2020
    Copy the full SHA
    8c75621 View commit details
Showing with 119 additions and 205 deletions.
  1. +2 −2 src/libexpr/flake/flake.cc
  2. +2 −2 src/nix/flake.cc
  3. +35 −6 src/nix/installables.cc
  4. +8 −2 src/nix/installables.hh
  5. +64 −165 src/nix/search.cc
  6. +8 −28 tests/search.sh
4 changes: 2 additions & 2 deletions src/libexpr/flake/flake.cc
Original file line number Diff line number Diff line change
@@ -235,10 +235,10 @@ static Flake getFlake(
auto sEpoch = state.symbols.create("epoch"); // FIXME: remove soon

if (vInfo.attrs->get(sEdition))
warn("flake '%s' has deprecated attribution 'edition'", lockedRef);
warn("flake '%s' has deprecated attribute 'edition'", lockedRef);

if (vInfo.attrs->get(sEpoch))
warn("flake '%s' has deprecated attribution 'epoch'", lockedRef);
warn("flake '%s' has deprecated attribute 'epoch'", lockedRef);

if (auto description = vInfo.attrs->get(state.sDescription)) {
expectType(state, tString, *description->value, *description->pos);
4 changes: 2 additions & 2 deletions src/nix/flake.cc
Original file line number Diff line number Diff line change
@@ -695,7 +695,7 @@ struct CmdFlakeShow : FlakeCommand
void run(nix::ref<nix::Store> store) override
{
auto state = getEvalState();
auto flake = lockFlake();
auto flake = std::make_shared<LockedFlake>(lockFlake());

std::function<void(eval_cache::AttrCursor & visitor, const std::vector<Symbol> & attrPath, const std::string & headerPrefix, const std::string & nextPrefix)> visit;

@@ -815,7 +815,7 @@ struct CmdFlakeShow : FlakeCommand

auto cache = openEvalCache(*state, flake, useEvalCache);

visit(*cache->getRoot(), {}, fmt(ANSI_BOLD "%s" ANSI_NORMAL, flake.flake.lockedRef), "");
visit(*cache->getRoot(), {}, fmt(ANSI_BOLD "%s" ANSI_NORMAL, flake->flake.lockedRef), "");
}
};

41 changes: 35 additions & 6 deletions src/nix/installables.cc
Original file line number Diff line number Diff line change
@@ -133,6 +133,15 @@ App Installable::toApp(EvalState & state)
return App(state, *toValue(state).first);
}

std::vector<std::pair<std::shared_ptr<eval_cache::AttrCursor>, std::string>>
Installable::getCursor(EvalState & state, bool useEvalCache)
{
auto evalCache =
std::make_shared<nix::eval_cache::EvalCache>(false, Hash(), state,
[&]() { return toValue(state).first; });
return {{evalCache->getRoot(), ""}};
}

struct InstallableStorePath : Installable
{
ref<Store> store;
@@ -285,22 +294,22 @@ Value * InstallableFlake::getFlakeOutputs(EvalState & state, const flake::Locked

ref<eval_cache::EvalCache> openEvalCache(
EvalState & state,
const flake::LockedFlake & lockedFlake,
std::shared_ptr<flake::LockedFlake> lockedFlake,
bool useEvalCache)
{
return ref(std::make_shared<nix::eval_cache::EvalCache>(
useEvalCache,
lockedFlake.getFingerprint(),
lockedFlake->getFingerprint(),
state,
[&]()
[&state, lockedFlake]()
{
/* For testing whether the evaluation cache is
complete. */
if (getEnv("NIX_ALLOW_EVAL").value_or("1") == "0")
throw Error("not everything is cached, but evaluation is not allowed");

auto vFlake = state.allocValue();
flake::callFlake(state, lockedFlake, *vFlake);
flake::callFlake(state, *lockedFlake, *vFlake);

state.forceAttrs(*vFlake);

@@ -315,7 +324,8 @@ std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableF
{
auto state = cmd.getEvalState();

auto lockedFlake = lockFlake(*state, flakeRef, cmd.lockFlags);
auto lockedFlake = std::make_shared<flake::LockedFlake>(
lockFlake(*state, flakeRef, cmd.lockFlags));

auto cache = openEvalCache(*state, lockedFlake, true);
auto root = cache->getRoot();
@@ -343,7 +353,7 @@ std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableF
attr->getAttr(state->sOutputName)->getString()
};

return {attrPath, lockedFlake.flake.lockedRef, std::move(drvInfo)};
return {attrPath, lockedFlake->flake.lockedRef, std::move(drvInfo)};
}

throw Error("flake '%s' does not provide attribute %s",
@@ -378,6 +388,25 @@ std::pair<Value *, Pos> InstallableFlake::toValue(EvalState & state)
flakeRef, concatStringsSep(", ", quoteStrings(attrPaths)));
}

std::vector<std::pair<std::shared_ptr<eval_cache::AttrCursor>, std::string>>
InstallableFlake::getCursor(EvalState & state, bool useEvalCache)
{
auto evalCache = openEvalCache(state,
std::make_shared<flake::LockedFlake>(lockFlake(state, flakeRef, cmd.lockFlags)),
useEvalCache);

auto root = evalCache->getRoot();

std::vector<std::pair<std::shared_ptr<eval_cache::AttrCursor>, std::string>> res;

for (auto & attrPath : getActualAttrPaths()) {
auto attr = root->findAlongAttrPath(parseAttrPath(state, attrPath));
if (attr) res.push_back({attr, attrPath});
}

return res;
}

// FIXME: extend
std::string attrRegex = R"([A-Za-z_][A-Za-z0-9-_+]*)";
static std::regex attrPathRegex(fmt(R"(%1%(\.%1%)*)", attrRegex));
10 changes: 8 additions & 2 deletions src/nix/installables.hh
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ namespace nix {
struct DrvInfo;
struct SourceExprCommand;

namespace eval_cache { class EvalCache; }
namespace eval_cache { class EvalCache; class AttrCursor; }

struct Buildable
{
@@ -57,6 +57,9 @@ struct Installable
{
return {};
}

virtual std::vector<std::pair<std::shared_ptr<eval_cache::AttrCursor>, std::string>>
getCursor(EvalState & state, bool useEvalCache);
};

struct InstallableValue : Installable
@@ -100,11 +103,14 @@ struct InstallableFlake : InstallableValue
std::vector<DerivationInfo> toDerivations() override;

std::pair<Value *, Pos> toValue(EvalState & state) override;

std::vector<std::pair<std::shared_ptr<eval_cache::AttrCursor>, std::string>>
getCursor(EvalState & state, bool useEvalCache) override;
};

ref<eval_cache::EvalCache> openEvalCache(
EvalState & state,
const flake::LockedFlake & lockedFlake,
std::shared_ptr<flake::LockedFlake> lockedFlake,
bool useEvalCache);

}
Loading