From 3473b1950a90d596a3baa080fdfdb080f55a5cc0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 3 Apr 2020 21:36:21 +0200 Subject: [PATCH 1/4] Fix tests.githubFlakes evaluation --- tests/github-flakes.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/github-flakes.nix b/tests/github-flakes.nix index 195772ca7..02b78ffe0 100644 --- a/tests/github-flakes.nix +++ b/tests/github-flakes.nix @@ -44,7 +44,7 @@ let dir=NixOS-nixpkgs-${nixpkgs.shortRev} cp -prd ${nixpkgs} $dir # Set the correct timestamp in the tarball. - find $dir -print0 | xargs -0 touch -t ${builtins.substring 0 12 nixpkgs.lastModified}.${builtins.substring 12 2 nixpkgs.lastModified} -- + find $dir -print0 | xargs -0 touch -t ${builtins.substring 0 12 nixpkgs.lastModifiedDate}.${builtins.substring 12 2 nixpkgs.lastModifiedDate} -- tar cfz $out/tarball/${nixpkgs.rev} $dir --hard-dereference mkdir -p $out/commits @@ -128,7 +128,7 @@ makeTest ( $github->succeed("systemctl stop httpd.service"); my $date = $client->succeed("nix flake info nixpkgs --json | jq -M .lastModified"); - strftime("%Y%m%d%H%M%S", gmtime($date)) eq "${nixpkgs.lastModified}" or die "time mismatch"; + strftime("%Y%m%d%H%M%S", gmtime($date)) eq "${nixpkgs.lastModifiedDate}" or die "time mismatch"; $client->succeed("nix build nixpkgs#hello"); From 2f494531b7811b45f6b76787f225495a14d28a7f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 6 Apr 2020 14:28:37 +0200 Subject: [PATCH 2/4] Add FIXME --- src/libfetchers/path.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libfetchers/path.cc b/src/libfetchers/path.cc index 037404726..7c7e20f4e 100644 --- a/src/libfetchers/path.cc +++ b/src/libfetchers/path.cc @@ -63,6 +63,8 @@ struct PathInput : Input { auto input = std::make_shared(*this); + // FIXME: check whether access to 'path' is allowed. + auto storePath = store->maybeParseStorePath(path); if (storePath) From ce3173edc15ad704c5083baba09b7bcdb99d5104 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 6 Apr 2020 14:39:47 +0200 Subject: [PATCH 3/4] 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') --- src/nix/flake.cc | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 93dbb9601..03bb9fe37 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -153,39 +153,14 @@ struct CmdFlakeInfo : FlakeCommand, MixJSON void run(nix::ref store) override { + auto flake = getFlake(); + stopProgressBar(); + 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 json = flakeToJson(*store, flake); std::cout << json.dump() << std::endl; - } else { - auto flake = getFlake(); - stopProgressBar(); + } else printFlakeInfo(*store, flake); - } } }; From 68b43e01ddf990182c87a924d647dc7aa93b34f7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 6 Apr 2020 14:56:13 +0200 Subject: [PATCH 4/4] 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 --- src/libexpr/flake/flake.cc | 10 ++++++---- src/libexpr/flake/flake.hh | 1 + src/nix/flake.cc | 8 ++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc index f23c53a82..86bb05b5d 100644 --- a/src/libexpr/flake/flake.cc +++ b/src/libexpr/flake/flake.cc @@ -46,7 +46,7 @@ static FlakeRef lookupInFlakeCache( return flakeRef; } -static std::pair fetchOrSubstituteTree( +static std::tuple fetchOrSubstituteTree( EvalState & state, const FlakeRef & originalRef, std::optional treeInfo, @@ -76,6 +76,7 @@ static std::pair fetchOrSubstituteTree( .storePath = std::move(storePath), .info = *treeInfo, }, + originalRef, originalRef }; } catch (Error & e) { @@ -101,7 +102,7 @@ static std::pair 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(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(lockedRef, input.ref, sourceInfo.info, false)); diff --git a/src/libexpr/flake/flake.hh b/src/libexpr/flake/flake.hh index 88e386be0..7ee9bbe76 100644 --- a/src/libexpr/flake/flake.hh +++ b/src/libexpr/flake/flake.hh @@ -28,6 +28,7 @@ struct FlakeInput struct Flake { FlakeRef originalRef; + FlakeRef resolvedRef; FlakeRef lockedRef; std::optional description; std::shared_ptr sourceInfo; diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 03bb9fe37..e79f4129a 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -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())