You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm running nix copy in runInLinuxVM, and notice that for any nontrivial closures, the VM will run out of memory during the copying process. I left it set at the default 512 megabytes. I could obviously increase the amount of memory the VM is given, but that doesn't scale for copying complex derivations with many dependencies.
I suggest adding an option to only load and copy the contents of the paths one at a time, or even better, a way to specify an upper bound on the memory to be used while copying.
Reacted by Jonathan Coates, Peter Kolloch, AleXoundOS, Simonas Kazlauskas, bhipple, rszyma, Nicolas Vizzari-Trinquier and Bas van den Wollenberg
I'm encountering this issue with a single path — nix copy, nix-store --import, and a number of other commands I've tried all fail to import the path. Would be great to know if there's any way at all I can import it…
I see commits purporting to address this for a number of different cases, but none concerning uploading to a S3 bucket. Trying to copy a 2.8GB store path to a S3 bucket took nearly 4GB of memory and more than twenty minutes of 100% CPU. Has that been fixed?
FWIW I too am another big-upload-to-S3 guy using nix copy 😄
It would surprise me if aws-sdk-cpp didn't support it, given that S3 supports almost arbitrarily large objects and multi-part uploads. If someone figured out how to implement it, would you accept the PR?
Have imports to the nix store (nix copy, nix-store --import, ...) implemented entirely in a streaming fashion.
Reproducing
A somewhat simple reproducer I whipped up to experiment:
dd if=/dev/zero of=large-file bs=1M count=5120
large_file_store_path=$(nix-store --add large-file)
nix-store --export "$large_file_store_path"> large-file-closure
# Each time you repeat this you will see a 5GiB in RAM consumption during the import
nix-store --delete "$large_file_store_path"
nix-store --import < large-file-closure
In this part of the method, the entire file is parsed once (via parseDump) and at the same time the whole string is saved in memory via TeeSource and StringSink (any read from TeeSourceappends to StringSink).
Then the rest of the function will actually add to the nix store, redoing the parsing+dumping done previously but from the string saved in the previous part and writing to disk.
I'm not familiar with how Nix is implemented but I'm guessing it probably could be done in a streaming fashion ? One big thing stands in the way though:
The narHash is precomputed and seem to be the main reason for buffering the whole string. See this line
For local-store only it's probably unnecessary (the hash ends up checked later, but since the source is the same, of course it will always work barring memory corruption)
For non-local-stores (I'm guessing daemon & remote ?) the hash must be sent first so that it can be checked on the receiving side (and I don't think it's possible to do away with it given we like the integrity guarantees of Nix)
As said above I'm not all that familiar with the Nix codebase so I can't say if that's a fixable issue or not. I may also have gotten stuff wrong because of this so don't hesitate to correct my understanding!
Reacted by AriFordsham, Lucas Romero and Nathaniel Wesley Filardo
nix copy (via addToStore) is implemented in a streaming fashion and does use constant memory with new enough nix - as are uploads to binary caches. import/export still buffers though yeah
Activity
copumpkin commentedon Nov 15, 2017
Intuitively it feels that it should be possible for it to run in constant memory. What am I missing?
lheckemann commentedon Feb 23, 2018
I'm encountering this issue with a single path —
nix copy,nix-store --import, and a number of other commands I've tried all fail to import the path. Would be great to know if there's any way at all I can import it…LisannaAtHome commentedon Mar 17, 2018
Possibly related to #1969 ? Looks like some patches have gone in recently that might improve things here: 48662d1 3e6b194
Make 'nix copy --to daemon' run in constant memory (daemon side)
Make LocalBinaryCacheStore::narFromPath() run in constant memory
Make HttpBinaryCacheStore::narFromPath() run in constant memory
Ralith commentedon Apr 2, 2018
I see commits purporting to address this for a number of different cases, but none concerning uploading to a S3 bucket. Trying to copy a 2.8GB store path to a S3 bucket took nearly 4GB of memory and more than twenty minutes of 100% CPU. Has that been fixed?
Make LocalBinaryCacheStore::narFromPath() run in constant memory
Make HttpBinaryCacheStore::narFromPath() run in constant memory
andrewchambers commentedon Apr 8, 2018
Hitting this issue trying to do something like - nixos-rebuild build ; nix copy ./result --to ssh://low_ram_machine
@dtzWill will those experimental changes help with ssh copy?
edolstra commentedon Apr 12, 2018
@Ralith I'm probably not going to make S3BinaryCacheStore do uploads in constant space. It might not even be supported by aws-sdk-cpp.
I assume the 100% CPU is caused by compression, which you can disable.
copumpkin commentedon Apr 12, 2018
FWIW I too am another big-upload-to-S3 guy using
nix copy😄It would surprise me if aws-sdk-cpp didn't support it, given that S3 supports almost arbitrarily large objects and multi-part uploads. If someone figured out how to implement it, would you accept the PR?
Ralith commentedon Apr 13, 2018
It seems very strange that it would take twenty minutes on my i7-4980HQ, even so. 2.8GB is big but it's not that big.
55 remaining items
tshakah commentedon Nov 7, 2024
I'm getting this copying a closure from an arm builder onto a Pi Zero, which has 512mb of ram. This is on nix 2.18.8
poliorcetics commentedon Apr 25, 2025
Continuing on @nh2 search of 7 years ago:
Goal
Have imports to the nix store (
nix copy,nix-store --import, ...) implemented entirely in a streaming fashion.Reproducing
A somewhat simple reproducer I whipped up to experiment:
Causes
We enter through
nix-store --import:nix/src/nix-store/nix-store.cc
Line 1142 in 3f811c2
nix/src/nix-store/nix-store.cc
Line 732 in 3f811c2
We reach
Store::importhPathshere.In this part of the method, the entire file is parsed once (via
parseDump) and at the same time the whole string is saved in memory viaTeeSourceandStringSink(any read fromTeeSourceappends toStringSink).Then the rest of the function will actually add to the nix store, redoing the parsing+dumping done previously but from the string saved in the previous part and writing to disk.
I'm not familiar with how Nix is implemented but I'm guessing it probably could be done in a streaming fashion ? One big thing stands in the way though:
The
narHashis precomputed and seem to be the main reason for buffering the whole string. See this lineAs said above I'm not all that familiar with the Nix codebase so I can't say if that's a fixable issue or not. I may also have gotten stuff wrong because of this so don't hesitate to correct my understanding!
tomberek commentedon Aug 13, 2026
Closing as stale. Re-open if needed.
nwf commentedon Aug 13, 2026
At a very quick glance, things have not changed on
masterin a way that would invalidate #1681 (comment) observations. Please consider re-opening.xokdvium commentedon Aug 13, 2026
nix copy (via addToStore) is implemented in a streaming fashion and does use constant memory with new enough nix - as are uploads to binary caches. import/export still buffers though yeah
nh2 commentedon Aug 13, 2026
Reopening. I think this bug should only be closed once it's actually fixed and that can be shown by providing the according maxresident memory usage.
poliorcetics commentedon Aug 15, 2026
xokdvium commentedon Aug 15, 2026
That is not the NAR format - but rather the export/import bespoke serialisation. And notably, nix copy doesn't use it.