1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 00:11:17 +02:00

Add setting to warn about copying/hashing large paths

This is useful for diagnosing whether an evaluation is copying large
paths to the store. Example:

   $ nix build .#packages.x86_64-linux.default --large-path-warning-threshold 1000000
   warning: copied large path '/home/eelco/Dev/nix-master/' to the store (6271792 bytes)
   warning: copied large path '«github:NixOS/nixpkgs/b550fe4b4776908ac2a861124307045f8e717c8e?narHash=sha256-7kkJQd4rZ%2BvFrzWu8sTRtta5D1kBG0LSRYAfhtmMlSo%3D»/' to the store (155263768 bytes)
   warning: copied large path '«github:libgit2/libgit2/45fd9ed7ae1a9b74b957ef4f337bc3c8b3df01b5?narHash=sha256-oX4Z3S9WtJlwvj0uH9HlYcWv%2Bx1hqp8mhXl7HsLu2f0%3D»/' to the store (22175416 bytes)
   warning: copied large path '/nix/store/z985088mcd6w23qwdlirsinnyzayagki-source' to the store (5885872 bytes)
This commit is contained in:
Eelco Dolstra 2024-05-07 19:25:44 +02:00
parent d8559cad8d
commit dbe1b51580
9 changed files with 54 additions and 15 deletions

View file

@ -169,7 +169,9 @@ std::pair<StorePath, Hash> StoreDirConfig::computeStorePath(
const StorePathSet & references,
PathFilter & filter) const
{
auto h = hashPath(path, method.getFileIngestionMethod(), hashAlgo, filter);
auto [h, size] = hashPath(path, method.getFileIngestionMethod(), hashAlgo, filter);
if (size && *size >= settings.largePathWarningThreshold)
warn("hashed large path '%s' (%d bytes)", path, *size);
return {
makeFixedOutputPathFromCA(
name,
@ -210,7 +212,11 @@ StorePath Store::addToStore(
auto source = sinkToSource([&](Sink & sink) {
dumpPath(path, sink, fsm, filter);
});
return addToStoreFromDump(*source, name, fsm, method, hashAlgo, references, repair);
LengthSource lengthSource(*source);
auto storePath = addToStoreFromDump(lengthSource, name, fsm, method, hashAlgo, references, repair);
if (lengthSource.total >= settings.largePathWarningThreshold)
warn("copied large path '%s' to the store (%d bytes)", path, lengthSource.total);
return storePath;
}
void Store::addMultipleToStore(