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
Unfortunately Nix is not a simple package manager: it implements a lazy purely functional language, the evaluation of which uses a lot of memory. It has some design issues that make it hard to reduce memory usage (in particular the use of a monolithic pkgs set combined with the .override feature makes garbage collection largely ineffective).
Also, Nixpkgs has seen a lot of growth such that evaluation now takes > 3 times as much memory as two years ago (https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qa.allocations). (This may also be a result of the use of certain new abstractions in Nixpkgs, e.g. stdenv.mkDerivation is a lot more complicated than two years ago.)
When upgrading to NixOS 18.03 I had to add 6Gb swap on my laptop with 4Gb RAM to be able install some packages like KiCAD for example :(
Installation takes about 1.5 hours because using swap.
Of couse I also configured zram, because without zram I wont be able to complete installation.
The future of Nix on the middle/low-end systems in the mist...
@vcunat I already use distributed build a some time ago because my laptop not so much powerful. Also I relocated /tmp on a disk But it don't helps to reduce memory usage.
@katyo: what kind of command do you use? If it's nix-env, be sure to use one with -A selectors, to save on performance (and it's saner in other ways, too).
Ran into the same issue on a device with 8GB memory:
nonroot@box $ nix search mkpasswd
GC Warning: Failed to expand heap by 402653184 bytes
warning: using cached results; pass '-u' to update the cache
Attribute name: nixpkgs.perlPackages.StringMkPasswd
Package name: perl-String-MkPasswd
Version: 0.05
Description:
Attribute name: nixpkgs.mkpasswd
Package name: mkpasswd
Version: 5.3.0
Description: Overfeatured front-end to crypt, from the Debian whois package
nonroot@box $ nix-env -i mkpasswd
GC Warning: Failed to expand heap by 402653184 bytes
I also happened occasionally that my system simply started hanging out of the blue, which I suspect was caused by system.autoUpgrade.enable = true; which might suffer from a related issue - disabled it for now to see whether it still happens.
Also, Nixpkgs has seen a lot of growth such that evaluation now takes > 3 times as much memory as two years ago
This may also be a result of the use of certain new abstractions in Nixpkgs, e.g. `stdenv.mkDerivation` is a lot more complicated than two years ago.
I read changes of the significant bumps in that graph that were not immediately fixed several revisions later and all but the very last one were either changes to haskell packages or melpa. So my guess would be that we now have ~3x more packages in release.nix that two years ago, not that `stdenv.mkDerivation` became 3x slower.
The very latest bump is interesting, though, I'm not sure what causes it, it's either #44423 or #44517, bisecting now.
I think a much more useful metric would be "nix-env -qa avg allocations per result produced", not the absolute value.
@edolstra can you give a status update? are there plans to fix the design problems? Maybe is the effort with flakes related? This seem to be a big issue considering that the project should grow in terms of package count.
Reacted by dukebarman, Newskooler, AleXoundOS, Meghan Denny, PedroRegisPOAR, Nikolay Artamonov, John Kiril Swenson and Tolki
I am just getting started with nix and following the Nix manual.
On chapter 9, one of the suggested lines to execute is this nix-env -qa, so when I run it I get the same error:
some_user@some_server:~$ nix-env -qa
GC Warning: Failed to expand heap by 16777216 bytes
...
GC Warning: Failed to expand heap by 16777216 bytes
GC Warning: Failed to expand heap by 262144 bytes
GC Warning: Out of Memory! Heap size: 500 MiB. Returning NULL!
error: out of memory
I am experiencing the same issue on a freshly installed Nix (I did not install any packages, just followed the manual linked above).
Does nix have minimum server requirements? If yes, what are they?
P.S. I also run out of memory with commands for specific packages as well such as nix-env -qa firefox or even package installation like nix-env -i subversion
Does nix have minimum server requirements? If yes, what are they?
I'm not very experienced, but I think it's 3 GiB RAM nowadays (if not evaluating/building nix expressions remotely, i.e. run nixos-rebuild --target-host HOST from another machine).
P.S. I also run out of memory with commands for specific packages as well such as nix-env -qa firefox or even package installation like nix-env -i subversion
P.S.
It may sound quite contradictory (and regardless of the RAM usage) but nix-env is very unlikely the tool you want to provision your server with. As it does not comprise the best of declarative features NixOS can provide. Perhaps, it's one of the reasons nix-env can receive less care and performance fixes.
I was thinking of using nix-env to install some dependencies on my machines as I often juggle between Linux and Mac OS and nixpkgs is by far the most up-to-date packages repository as well as making clean installs compared to brew.
But like many people here nix-env crashes my 1Gb servers and forces me to fallback to other package managers with outdated/missing packages.
Is there any way to limit the RAM usage of nix-env somehow, particularly when only installing binary packages with specific versions?
A simple work around is to just use a swap. Which can be done with a few commands. I do this all the time on a server with 0 issues.
Yes, I could make it work with the -A option or using a swap, but nix-env --install xxx crashing any machine without access to 4Gb+ of RAM + swap still feels like a bug more than a feature.
I definitely have very little knowledge about the nix system as a whole so I'm unsure as to where the RAM usage is coming from. If it's linked to data structures within the nix programming language taking up too much RAM, could using sqlite and querying it instead of storing packages information in RAM help? Sorry if that's a stupid idea.
-i without -A is something that has not aged well… but even -iA or building a profile with buildEnv is still expensive.
On my VPS I define a toolset using an expression with buildEnv, evaluate it locally on my laptop, and then do closure-copying.
For some things I actually fetch the build data from Hydra, and then do stuff by output path (not attribute or name), which won't work except via substituters, but as I am asking Hydra for what is the latest stuff available in the cache…
I have been also running into this memory issue on a opensuse tumbleweed machine with nix installed. Installing packages worked using the -iA flag, but how to update them?
Running nix-channel --update and nix-env --upgrade has the same memory problems. And there is no nixos-rebuild or home-manager available, as those are the other suggested upgrade options.
@mdehollander nix-env is pretty much the worst in terms of anything, including memory usage, I think. If you want to use imperative package management, you could try nix profile, because it implements updates in a way that doesn't have to evaluate the entire nixpkgs and also isn't very fragile (nix-env stores packages as their package names instead of attr path which is not good since those don't have an index and aren't even necessarily unique).
Otherwise, if you want to do declarative package management and don't want to use home manager, I suppose you could make an env yourself with pkgs.buildEnv along with a rebuild script to build the expression for it and link it to a known path. Then add its bin to the PATH environment. The expression might look something like this:
let
pkgs = import <nixpkgs> {};
in pkgs.buildEnv {
name = "path";
paths = with pkgs; [
nix
zsh
# more packages
];
pathsToLink = ["/bin"]; # plus anything else you might want
}
I'm also hitting this issue with nix-review, that uses nix-env under the hood… 11Gb of RAM used for a really basic package, even before compilation starts. Is there any alternative here or plans to fix this?
Reacted by PassiveLemon, Josef Hofer, Tom Oostveen, Timo Triebensky and Maxwell Anderson
stops bad side effects like locking up the system and killing the terminal it's running in. The process itself still gets killed sometimes but works the second time. It may also reduce the actual memory usage, possibly by forcing garbage collection to happy earlier? Alternative commands still seems like a better workaround.
nix-env -qaP '*' --description as described in NixOS manual consumes over 6 GB of memory. Memory is not released until you hit 'q' to quit terminal output pager (more/less).
I wanted to try Nix by installing it in virtual machine with 4 GB dedicated ram to try it for Haskell instead of plain Cabal/Stack, but this looks impractical. Running entire Gnome consumes around 1.2 GB and running nix-env triggered OOM killing entire Gnome as well. dnf list | less on Fedora for comparison might consume around 176 MB (seen in Gnome System Monitor).
Activity
edolstra commentedon Apr 9, 2018
Unfortunately Nix is not a simple package manager: it implements a lazy purely functional language, the evaluation of which uses a lot of memory. It has some design issues that make it hard to reduce memory usage (in particular the use of a monolithic
pkgsset combined with the.overridefeature makes garbage collection largely ineffective).Also, Nixpkgs has seen a lot of growth such that evaluation now takes > 3 times as much memory as two years ago (https://hydra.nixos.org/job/nixpkgs/trunk/metrics/metric/nix-env.qa.allocations). (This may also be a result of the use of certain new abstractions in Nixpkgs, e.g.
stdenv.mkDerivationis a lot more complicated than two years ago.)katyo commentedon May 30, 2018
When upgrading to NixOS 18.03 I had to add 6Gb swap on my laptop with 4Gb RAM to be able install some packages like KiCAD for example :(
Installation takes about 1.5 hours because using swap.
Of couse I also configured zram, because without zram I wont be able to complete installation.
The future of Nix on the middle/low-end systems in the mist...
vcunat commentedon May 30, 2018
@katyo: I suspect your case is because there were no binaries for it, nix tried to build it locally, and
/tmp/in now in RAM by default.katyo commentedon May 31, 2018
@vcunat I already use distributed build a some time ago because my laptop not so much powerful. Also I relocated /tmp on a disk But it don't helps to reduce memory usage.
vcunat commentedon May 31, 2018
@katyo: what kind of command do you use? If it's
nix-env, be sure to use one with-Aselectors, to save on performance (and it's saner in other ways, too).eliasp commentedon Jul 16, 2018
Ran into the same issue on a device with 8GB memory:
I also happened occasionally that my system simply started hanging out of the blue, which I suspect was caused by
system.autoUpgrade.enable = true;which might suffer from a related issue - disabled it for now to see whether it still happens.vcunat commentedon Jul 16, 2018
@eliasp: almost all people really want to prefer
-Afor nix-env. You gotso you just
nix-env -iA nixpkgs.mkpasswd. I haven't seennixos-rebuildsuffering from this, as it uses attributes "inside".oxij commentedon Aug 18, 2018
davidak commentedon Jul 31, 2019
@edolstra can you give a status update? are there plans to fix the design problems? Maybe is the effort with flakes related? This seem to be a big issue considering that the project should grow in terms of package count.
chrissound commentedon Oct 12, 2019
@vcunat many thanks for the suggestion to use
nix-env -iA. Perhaps we can mention as a message whennix-envruns out of memory?newskooler commentedon May 5, 2020
I am just getting started with nix and following the Nix manual.
On chapter 9, one of the suggested lines to execute is this
nix-env -qa, so when I run it I get the same error:I am experiencing the same issue on a freshly installed Nix (I did not install any packages, just followed the manual linked above).
For more info:
I am running a 1GB RAM 1VCPU server.
Does nix have minimum server requirements? If yes, what are they?
P.S. I also run out of memory with commands for specific packages as well such as
nix-env -qa firefoxor even package installation likenix-env -i subversionAleXoundOS commentedon May 6, 2020
I'm not very experienced, but I think it's 3 GiB RAM nowadays (if not evaluating/building nix expressions remotely, i.e. run
nixos-rebuild --target-host HOSTfrom another machine).P.S.
It may sound quite contradictory (and regardless of the RAM usage) but
nix-envis very unlikely the tool you want to provision your server with. As it does not comprise the best of declarative features NixOS can provide. Perhaps, it's one of the reasonsnix-envcan receive less care and performance fixes.20 remaining items
chrissound commentedon Apr 17, 2023
A simple work around is to just use a swap. Which can be done with a few commands. I do this all the time on a server with 0 issues.
mrtolkien commentedon Apr 17, 2023
Yes, I could make it work with the
-Aoption or using a swap, butnix-env --install xxxcrashing any machine without access to 4Gb+ of RAM + swap still feels like a bug more than a feature.I definitely have very little knowledge about the nix system as a whole so I'm unsure as to where the RAM usage is coming from. If it's linked to data structures within the nix programming language taking up too much RAM, could using sqlite and querying it instead of storing packages information in RAM help? Sorry if that's a stupid idea.
7c6f434c commentedon Apr 17, 2023
-iwithout-Ais something that has not aged well… but even-iAor building a profile withbuildEnvis still expensive.On my VPS I define a toolset using an expression with
buildEnv, evaluate it locally on my laptop, and then do closure-copying.For some things I actually fetch the build data from Hydra, and then do stuff by output path (not attribute or name), which won't work except via substituters, but as I am asking Hydra for what is the latest stuff available in the cache…
eode commentedon Jul 9, 2023
Is it planned to fix this?
mdehollander commentedon Aug 26, 2023
I have been also running into this memory issue on a opensuse tumbleweed machine with nix installed. Installing packages worked using the
-iAflag, but how to update them?Running
nix-channel --updateandnix-env --upgradehas the same memory problems. And there is nonixos-rebuildorhome-manageravailable, as those are the other suggested upgrade options.dblsaiko commentedon Aug 28, 2023
@mdehollander nix-env is pretty much the worst in terms of anything, including memory usage, I think. If you want to use imperative package management, you could try nix profile, because it implements updates in a way that doesn't have to evaluate the entire nixpkgs and also isn't very fragile (nix-env stores packages as their package names instead of attr path which is not good since those don't have an index and aren't even necessarily unique).
Otherwise, if you want to do declarative package management and don't want to use home manager, I suppose you could make an env yourself with pkgs.buildEnv along with a rebuild script to build the expression for it and link it to a known path. Then add its bin to the PATH environment. The expression might look something like this:
nixos-discourse commentedon Jan 8, 2024
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/reduce-nix-env-u-memory-usage/37954/2
tobiasBora commentedon Feb 23, 2024
I'm also hitting this issue with nix-review, that uses nix-env under the hood… 11Gb of RAM used for a really basic package, even before compilation starts. Is there any alternative here or plans to fix this?
mikedlr commentedon Aug 20, 2025
I found that running like this
stops bad side effects like locking up the system and killing the terminal it's running in. The process itself still gets killed sometimes but works the second time. It may also reduce the actual memory usage, possibly by forcing garbage collection to happy earlier? Alternative commands still seems like a better workaround.
eode commentedon Aug 25, 2025
mirpa29 commentedon Jan 1, 2026
nix-env -qaP '*' --descriptionas described in NixOS manual consumes over 6 GB of memory. Memory is not released until you hit 'q' to quit terminal output pager (more/less).I wanted to try Nix by installing it in virtual machine with 4 GB dedicated ram to try it for Haskell instead of plain Cabal/Stack, but this looks impractical. Running entire Gnome consumes around 1.2 GB and running nix-env triggered OOM killing entire Gnome as well.
dnf list | lesson Fedora for comparison might consume around 176 MB (seen in Gnome System Monitor).eode commentedon Jan 2, 2026
ancient.