1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-19 10:50:24 -04:00

Respect the narHash attribute in more input types

call-flake.nix now passes node.info.narHash to fetchTree. This ensures
that dirty Git trees work even in pure mode.
This commit is contained in:
Eelco Dolstra 2020-04-02 19:04:33 +02:00
parent 78ad5b3d91
commit a6ff66b658
6 changed files with 12 additions and 9 deletions

View file

@ -8,7 +8,10 @@ let
builtins.mapAttrs
(key: node:
let
sourceInfo = if key == lockFile.root then rootSrc else fetchTree (removeAttrs node.locked ["dir"]);
sourceInfo =
if key == lockFile.root
then rootSrc
else fetchTree ({ inherit (node.info) narHash; } // removeAttrs node.locked ["dir"]);
subdir = if key == lockFile.root then rootSubdir else node.locked.dir or "";
flake = import (sourceInfo + (if subdir != "" then "/" else "") + subdir + "/flake.nix");
inputs = builtins.mapAttrs (inputName: key: allNodes.${key}) (node.inputs or {});

View file

@ -29,8 +29,10 @@ std::unique_ptr<Input> inputFromURL(const std::string & url)
std::unique_ptr<Input> inputFromAttrs(const Attrs & attrs)
{
auto attrs2(attrs);
attrs2.erase("narHash");
for (auto & inputScheme : *inputSchemes) {
auto res = inputScheme->inputFromAttrs(attrs);
auto res = inputScheme->inputFromAttrs(attrs2);
if (res) {
if (auto narHash = maybeGetStrAttr(attrs, "narHash"))
// FIXME: require SRI hash.

View file

@ -39,7 +39,7 @@ struct GitInput : Input
bool isImmutable() const override
{
return (bool) rev;
return (bool) rev || narHash;
}
std::optional<std::string> getRef() const override { return ref; }

View file

@ -33,7 +33,7 @@ struct GitHubInput : Input
bool isImmutable() const override
{
return (bool) rev;
return (bool) rev || narHash;
}
std::optional<std::string> getRef() const override { return ref; }

View file

@ -33,7 +33,7 @@ struct MercurialInput : Input
bool isImmutable() const override
{
return (bool) rev;
return (bool) rev || narHash;
}
std::optional<std::string> getRef() const override { return ref; }

View file

@ -205,9 +205,7 @@ struct TarballInput : Input
{
Attrs attrs;
attrs.emplace("url", url.to_string());
if (narHash)
attrs.emplace("narHash", narHash->to_string(SRI));
else if (hash)
if (hash)
attrs.emplace("hash", hash->to_string(SRI));
return attrs;
}
@ -260,7 +258,7 @@ struct TarballInputScheme : InputScheme
if (maybeGetStrAttr(attrs, "type") != "tarball") return {};
for (auto & [name, value] : attrs)
if (name != "type" && name != "url" && name != "hash" && name != "narHash")
if (name != "type" && name != "url" && name != "hash")
throw Error("unsupported tarball input attribute '%s'", name);
auto input = std::make_unique<TarballInput>(parseURL(getStrAttr(attrs, "url")));