Merge pull request #8859 from edolstra/tarball-last-modified
Tarball trees: Propagate lastModified
This commit is contained in:
commit
5b5f56a9d4
|
@ -20,8 +20,8 @@ Link: <flakeref>; rel="immutable"
|
||||||
|
|
||||||
(Note the required `<` and `>` characters around *flakeref*.)
|
(Note the required `<` and `>` characters around *flakeref*.)
|
||||||
|
|
||||||
*flakeref* must be a tarball flakeref. It can contain flake attributes
|
*flakeref* must be a tarball flakeref. It can contain the tarball flake attributes
|
||||||
such as `narHash`, `rev` and `revCount`. If `narHash` is included, its
|
`narHash`, `rev`, `revCount` and `lastModified`. If `narHash` is included, its
|
||||||
value must be the NAR hash of the unpacked tarball (as computed via
|
value must be the NAR hash of the unpacked tarball (as computed via
|
||||||
`nix hash path`). Nix checks the contents of the returned tarball
|
`nix hash path`). Nix checks the contents of the returned tarball
|
||||||
against the `narHash` attribute. The `rev` and `revCount` attributes
|
against the `narHash` attribute. The `rev` and `revCount` attributes
|
||||||
|
|
|
@ -232,7 +232,7 @@ struct CurlInputScheme : InputScheme
|
||||||
if (type != inputType()) return {};
|
if (type != inputType()) return {};
|
||||||
|
|
||||||
// FIXME: some of these only apply to TarballInputScheme.
|
// FIXME: some of these only apply to TarballInputScheme.
|
||||||
std::set<std::string> allowedNames = {"type", "url", "narHash", "name", "unpack", "rev", "revCount"};
|
std::set<std::string> allowedNames = {"type", "url", "narHash", "name", "unpack", "rev", "revCount", "lastModified"};
|
||||||
for (auto & [name, value] : attrs)
|
for (auto & [name, value] : attrs)
|
||||||
if (!allowedNames.count(name))
|
if (!allowedNames.count(name))
|
||||||
throw Error("unsupported %s input attribute '%s'", *type, name);
|
throw Error("unsupported %s input attribute '%s'", *type, name);
|
||||||
|
@ -310,6 +310,9 @@ struct TarballInputScheme : CurlInputScheme
|
||||||
input = immutableInput;
|
input = immutableInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result.lastModified && !input.attrs.contains("lastModified"))
|
||||||
|
input.attrs.insert_or_assign("lastModified", uint64_t(result.lastModified));
|
||||||
|
|
||||||
return {result.tree.storePath, std::move(input)};
|
return {result.tree.storePath, std::move(input)};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,6 +9,7 @@ rm -rf $tarroot
|
||||||
mkdir -p $tarroot
|
mkdir -p $tarroot
|
||||||
cp dependencies.nix $tarroot/default.nix
|
cp dependencies.nix $tarroot/default.nix
|
||||||
cp config.nix dependencies.builder*.sh $tarroot/
|
cp config.nix dependencies.builder*.sh $tarroot/
|
||||||
|
touch -d '@1000000000' $tarroot $tarroot/*
|
||||||
|
|
||||||
hash=$(nix hash path $tarroot)
|
hash=$(nix hash path $tarroot)
|
||||||
|
|
||||||
|
@ -36,6 +37,8 @@ test_tarball() {
|
||||||
nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file:///does-not-exist/must-remain-unused/$tarball; narHash = \"$hash\"; })"
|
nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file:///does-not-exist/must-remain-unused/$tarball; narHash = \"$hash\"; })"
|
||||||
expectStderr 102 nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"sha256-xdKv2pq/IiwLSnBBJXW8hNowI4MrdZfW+SYqDQs7Tzc=\"; })" | grep 'NAR hash mismatch in input'
|
expectStderr 102 nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"sha256-xdKv2pq/IiwLSnBBJXW8hNowI4MrdZfW+SYqDQs7Tzc=\"; })" | grep 'NAR hash mismatch in input'
|
||||||
|
|
||||||
|
[[ $(nix eval --impure --expr "(fetchTree file://$tarball).lastModified") = 1000000000 ]]
|
||||||
|
|
||||||
nix-instantiate --strict --eval -E "!((import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; })) ? submodules)" >&2
|
nix-instantiate --strict --eval -E "!((import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; })) ? submodules)" >&2
|
||||||
nix-instantiate --strict --eval -E "!((import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; })) ? submodules)" 2>&1 | grep 'true'
|
nix-instantiate --strict --eval -E "!((import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; })) ? submodules)" 2>&1 | grep 'true'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue