# Nix Installation and Memory Issues

**URL:** https://discourse.nixos.org/t/nix-installation-and-memory-issues/16334
**Category:** Help
**Created:** [November 30, 2021, 1:40am UTC](https://discourse.nixos.org/t/nix-installation-and-memory-issues/16334 "2021-11-30T01:40:45Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jeff-hykin](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jeff-hykin/32/2827_2.png) [@jeff-hykin](https://discourse.nixos.org/u/jeff-hykin)
#### Post date: [November 30, 2021, 1:40am UTC](https://discourse.nixos.org/t/nix-installation-and-memory-issues/16334/1 "2021-11-30T01:40:46Z")

</div>

I’ve had nix on all my machines for a while, and I’ve even had nix on this machine.  
I’ll list the things I’ve tried at the bottom, but this image is a good summary of all attempts

 ![Screen Shot 2021-11-29 at 7.15.04 PM](https://discourse.nixos.org/uploads/default/original/2X/2/20ba9b76b6748cade04204b3596cf32fb563081e.png)

- I hit a weird bug of saying its out of storage even though there was \>8Gb left.
- I decided to reinstall nix to try and fix the problem
  - For Linux I have a very comprehensive [uninstall script](https://github.com/jeff-hykin/virkshop/blob/6e7d54e5d16b14b4eedcba9a6f15bd8893c419db/virkshop/mixins/nix/internals/uninstall_nix#L92) (users/groups/services/files/processes)
  - I run it every time, and I also clear all ENV vars related to nix before trying a fresh install

- I’ve installed
  - Multi user
  - Single user (2.4)
  - Single user (2.38)
  - A [dockerized version](https://github.com/holochain/holonix/blob/313b848b526193261feeac9a7e2a60f00796813b/docker/Dockerfile.ubuntu)

All of them result in strange and very similar issues. Sometimes `nix-env -i cowsay` will be killed by the system (as in `Killed` is the only thing printed), sometimes it noisily runs out of ram, and last it will sometimes give me the original error where it gets to the build stage and then says there’s no-space available despite the server having 8.6Gb of free storage. The docker container gets repeated “GC Warning” issues during the installation phase.

I installed nix on this machine at least a year ago, and I have no idea what’s causing it to suddently fail. I’ve power cycled, killed/stopped all non-system-vital processes and services, and purged every reminant of nix from the machine. Has any one hit similar issues recently?

---

<div class="post-metadata">

### Author: ![jeff-hykin](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jeff-hykin/32/2827_2.png) [@jeff-hykin](https://discourse.nixos.org/u/jeff-hykin)
#### Post date: [November 30, 2021, 2:07am UTC](https://discourse.nixos.org/t/nix-installation-and-memory-issues/16334/2 "2021-11-30T02:07:01Z")

</div>

Well thanks to some more trouble shooting, the question has now become “why does nix need more than half a Gig of ram just to install cowsay”. I cofirmed on normal machine running docker that having less than two gigs of ram sometimes produces the similar results, increasing the ram to 3Gb with 1 Gb of swap in Docker lets me reliably install cowsay.

My server is just a lightweight static file server with 1Gb of ram, but I had used nix to manage dependencies. I’m not sure what changed that makes it consume more ram. Adding 4Gb of swap seemed to do the trick. Nice guide [here](https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04) for anyone also hitting this issue.

 ![Screen Shot 2021-11-29 at 8.01.35 PM](https://discourse.nixos.org/uploads/default/original/2X/c/c91bdcec5b854783768a86a5c9df5e2ffea12ff4.png)

---

<div class="post-metadata">

### Author: ![pennae](https://discourse.nixos.org/user_avatar/discourse.nixos.org/pennae/32/4474_2.png) [@pennae](https://discourse.nixos.org/u/pennae)
#### Post date: [November 30, 2021, 2:14am UTC](https://discourse.nixos.org/t/nix-installation-and-memory-issues/16334/3 "2021-11-30T02:14:58Z")

</div>

running just `nix-env -i` requires looking through all packages to match that name, which is very expensive as you’ve noted. `nix-env -iA nixpkgs.cowsay` installs the same package but uses a fraction of the resources to do it, since you’re giving the exact attribute path (`-A`) to the derivation.

---

<div class="post-metadata">

### Author: ![jeff-hykin](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jeff-hykin/32/2827_2.png) [@jeff-hykin](https://discourse.nixos.org/u/jeff-hykin)
#### Post date: [November 30, 2021, 3:31am UTC](https://discourse.nixos.org/t/nix-installation-and-memory-issues/16334/4 "2021-11-30T03:31:19Z")

</div>

> [@pennae](#):
>
> running just `nix-env -i` requires looking through all packages to match that name, which is very expensive as you’ve noted. `nix-env -iA nixpkgs.cowsay` installs the same package but uses a fraction of the resources to do it, since you’re giving the exact attribute path ( `-A` ) to the derivation.

Thank you! I’ll test this out and compare memory usage next time I’m pushing to the server
