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: 3473b1950a90
Choose a base ref
...
head repository: NixOS/nix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 68b43e01ddf9
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Apr 6, 2020

  1. Add FIXME

    edolstra committed Apr 6, 2020
    Copy the full SHA
    2f49453 View commit details
  2. nix flake info --json: Don't evaluate

    This makes its behaviour consistent with the non-json
    variant. Querying the outputs should be done by another command
    (e.g. 'nix search')
    edolstra committed Apr 6, 2020
    Copy the full SHA
    ce3173e View commit details
  3. nix flake info: Show resolved URL

    This is useful for finding out what a registry lookup resolves to, e.g
    
      $ nix flake info patchelf
      Resolved URL:  github:NixOS/patchelf
      Locked URL:    github:NixOS/patchelf/cd7955af31698c571c30b7a0f78e59fd624d0229
    edolstra committed Apr 6, 2020
    Copy the full SHA
    68b43e0 View commit details
Showing with 20 additions and 36 deletions.
  1. +6 −4 src/libexpr/flake/flake.cc
  2. +1 −0 src/libexpr/flake/flake.hh
  3. +2 −0 src/libfetchers/path.cc
  4. +11 −32 src/nix/flake.cc
10 changes: 6 additions & 4 deletions src/libexpr/flake/flake.cc
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ static FlakeRef lookupInFlakeCache(
return flakeRef;
}

static std::pair<fetchers::Tree, FlakeRef> fetchOrSubstituteTree(
static std::tuple<fetchers::Tree, FlakeRef, FlakeRef> fetchOrSubstituteTree(
EvalState & state,
const FlakeRef & originalRef,
std::optional<TreeInfo> treeInfo,
@@ -76,6 +76,7 @@ static std::pair<fetchers::Tree, FlakeRef> fetchOrSubstituteTree(
.storePath = std::move(storePath),
.info = *treeInfo,
},
originalRef,
originalRef
};
} catch (Error & e) {
@@ -101,7 +102,7 @@ static std::pair<fetchers::Tree, FlakeRef> fetchOrSubstituteTree(
if (treeInfo)
assert(tree.storePath == treeInfo->computeStorePath(*state.store));

return {std::move(tree), lockedRef};
return {std::move(tree), resolvedRef, lockedRef};
}

static void expectType(EvalState & state, ValueType type,
@@ -206,7 +207,7 @@ static Flake getFlake(
bool allowLookup,
FlakeCache & flakeCache)
{
auto [sourceInfo, lockedRef] = fetchOrSubstituteTree(
auto [sourceInfo, resolvedRef, lockedRef] = fetchOrSubstituteTree(
state, originalRef, treeInfo, allowLookup, flakeCache);

// Guard against symlink attacks.
@@ -217,6 +218,7 @@ static Flake getFlake(

Flake flake {
.originalRef = originalRef,
.resolvedRef = resolvedRef,
.lockedRef = lockedRef,
.sourceInfo = std::make_shared<fetchers::Tree>(std::move(sourceInfo))
};
@@ -490,7 +492,7 @@ LockedFlake lockFlake(
}

else {
auto [sourceInfo, lockedRef] = fetchOrSubstituteTree(
auto [sourceInfo, resolvedRef, lockedRef] = fetchOrSubstituteTree(
state, input.ref, {}, lockFlags.useRegistries, flakeCache);
node->inputs.insert_or_assign(id,
std::make_shared<LockedNode>(lockedRef, input.ref, sourceInfo.info, false));
1 change: 1 addition & 0 deletions src/libexpr/flake/flake.hh
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ struct FlakeInput
struct Flake
{
FlakeRef originalRef;
FlakeRef resolvedRef;
FlakeRef lockedRef;
std::optional<std::string> description;
std::shared_ptr<const fetchers::Tree> sourceInfo;
2 changes: 2 additions & 0 deletions src/libfetchers/path.cc
Original file line number Diff line number Diff line change
@@ -63,6 +63,8 @@ struct PathInput : Input
{
auto input = std::make_shared<PathInput>(*this);

// FIXME: check whether access to 'path' is allowed.

auto storePath = store->maybeParseStorePath(path);

if (storePath)
43 changes: 11 additions & 32 deletions src/nix/flake.cc
Original file line number Diff line number Diff line change
@@ -80,7 +80,8 @@ struct CmdFlakeList : EvalCommand

static void printFlakeInfo(const Store & store, const Flake & flake)
{
std::cout << fmt("URL: %s\n", flake.lockedRef.to_string());
std::cout << fmt("Resolved URL: %s\n", flake.resolvedRef.to_string());
std::cout << fmt("Locked URL: %s\n", flake.lockedRef.to_string());
std::cout << fmt("Edition: %s\n", flake.edition);
if (flake.description)
std::cout << fmt("Description: %s\n", *flake.description);
@@ -100,8 +101,11 @@ static nlohmann::json flakeToJson(const Store & store, const Flake & flake)
if (flake.description)
j["description"] = *flake.description;
j["edition"] = flake.edition;
j["url"] = flake.lockedRef.to_string();
j["originalUrl"] = flake.originalRef.to_string();
j["original"] = attrsToJson(flake.originalRef.toAttrs());
j["resolvedUrl"] = flake.resolvedRef.to_string();
j["resolved"] = attrsToJson(flake.resolvedRef.toAttrs());
j["url"] = flake.lockedRef.to_string(); // FIXME: rename to lockedUrl
j["locked"] = attrsToJson(flake.lockedRef.toAttrs());
j["info"] = flake.sourceInfo->info.toJson();
if (auto rev = flake.lockedRef.input->getRev())
@@ -153,39 +157,14 @@ struct CmdFlakeInfo : FlakeCommand, MixJSON

void run(nix::ref<nix::Store> store) override
{
if (json) {
auto state = getEvalState();
auto flake = lockFlake();

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

auto vFlake = state->allocValue();
flake::callFlake(*state, flake, *vFlake);

auto outputs = nlohmann::json::object();

enumerateOutputs(*state,
*vFlake,
[&](const std::string & name, Value & vProvide, const Pos & pos) {
auto provide = nlohmann::json::object();

if (name == "checks" || name == "packages") {
state->forceAttrs(vProvide, pos);
for (auto & aCheck : *vProvide.attrs)
provide[aCheck.name] = nlohmann::json::object();
}

outputs[name] = provide;
});

json["outputs"] = std::move(outputs);
auto flake = getFlake();
stopProgressBar();

if (json) {
auto json = flakeToJson(*store, flake);
std::cout << json.dump() << std::endl;
} else {
auto flake = getFlake();
stopProgressBar();
} else
printFlakeInfo(*store, flake);
}
}
};