Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos-install/nixos-rebuild fails with "Out of memory" on systems with 512MB RAM #85148

Closed
sasoiliev opened this issue Apr 13, 2020 · 8 comments

Comments

@sasoiliev
Copy link

Describe the bug
512MB of RAM seem to be insufficient for a successful NixOS installation via the installer. Bumping the memory size of the VM from the steps to reproduce below ends up in a successful installation, but bringing the memory back down to 512MB renders the VM unable to do nixos-rebuild switch (fails with error: unable to fork: Cannot allocate memory).

Even though 512MB is quite low by today's standards, there are still use cases where you don't really need more than that (e.g., I discovered this while building a VM that will act as a Wireguard VPN endpoint for a couple of boxes doing just routing between them).

I didn't find any requirements in the NixOS Manual regarding the amount of memory needed. I would suggest adding this in the documentation at minimum. (I can try to submit a PR if the project maintainers agree with my suggestion.)

(Apologies if this is a known problem, I couldn't find an existing issue describing it.)

To Reproduce
Steps to reproduce the behavior:

  1. Create a qemu disk image: qemu-img create /tmp/nixos.img 8G
  2. Start a qemu VM with 512MB RAM and the NixOS minimal ISO: qemu-kvm -m 512M -drive file=/tmp/nixos.img -cdrom ~/Downloads/nixos-minimal-19.09.1957.57c35c63004-x86_64-linux.iso
  3. Create a Linux partition through sudo fdisk
  4. Create a filesystem: sudo mkfs.ext4 /dev/sda1
  5. Mount the partition under /mnt: sudo mount /dev/sda1 /mnt
  6. Generate the NixOS config: sudo nixos-generate-config --root /mnt
  7. Set the GRUB boot device - in /mnt/etc/nixos/configuration.nix uncomment the boot.loader.grub.device setting
  8. Run the installer: sudo nixos-install --root /mnt

Actual behavior
The installation fails with:

building the configuration in /mnt/etc/nixos/configuration.nix...
[  103.481160] Out of memory: Kill process 891 (nix) score 749 or sacrifice child
[  103.481676] Killed process 891 (nix) total-vm:494588kB, anon-rss:371860kB, file-rss:0kB, shmem-rss:8kB
/run/current-system/sw/bin/nixos-install: line 99:   891 Killed                       ...

Expected behavior
The NixOS installer completes successfully.

Metadata

- system: `"x86_64-linux"`
- host os: `Linux 4.19.98, NixOS, 19.09.1957.57c35c63004 (Loris)`
- multi-user: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.3.2`
- channels(root): `"nixos-19.09.1957.57c35c63004"`
- nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
@eadwu
Copy link
Member

eadwu commented Apr 13, 2020

Have you tried using swap?

@sasoiliev
Copy link
Author

@eadwu, fair enough. Documenting the minimum requirements for building a NixOS configuration is still worthwhile IMO.

@ghost
Copy link

ghost commented Apr 14, 2020

Thanks for the detailed description. I agree we should have some documentation on the minimum system requirements for evaluating a normal NixOS config.

However there are ways around this. You can actually install NixOS without running a rebuild on the target.

  • Boot the NixOS ISO or kexec a NixOS netboot image
  • Set up ssh access
  • Do partitioning, formatting and mounting
  • On another NixOS computer:
    • ssh root@target "nixos-generate-config --root /mnt --show-hardware-config" > ./hardware-configuration.nix
    • Write a configuration for the new machine in ./configuration.nix and make sure it imports ./hardware-configuration.nix
    • nixos-rebuild build -I nixos-config=./configuration.nix
    • nix-store --export $(nix-store -qR result) | ssh root@target "nix-store --import --store /mnt"
    • ssh root@target "nixos-install --system $(readlink result)"
  • reboot the target machine
  • profit

Future rebuilds can be done with nixos-rebuild switch --target-host root@target --build-host localhost -I nixos-config=./configuration.

@lheckemann
Copy link
Member

https://discourse.nixos.org/t/adding-nixos-entry-to-libosinfo-recommended-resources/6441/ somewhat related to system requirements documentation

@stale
Copy link

stale bot commented Oct 12, 2020

Hello, I'm a bot and I thank you in the name of the community for opening this issue.

To help our human contributors focus on the most-relevant reports, I check up on old issues to see if they're still relevant. This issue has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

The community would appreciate your effort in checking if the issue is still valid. If it isn't, please close it.

If the issue persists, and you'd like to remove the stale label, you simply need to leave a comment. Your comment can be as simple as "still important to me". If you'd like it to get more attention, you can ask for help by searching for maintainers and people that previously touched related code and @ mention them in a comment. You can use Git blame or GitHub's web interface on the relevant files to find them.

Lastly, you can always ask for help at our Discourse Forum or at #nixos' IRC channel.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 12, 2020
@raidenovich
Copy link
Contributor

I'm having this issue with 16 gb of ram, probably a bug

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/building-nixos-on-lower-end-systems/51914/1

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Sep 10, 2024
@eclairevoyant
Copy link
Contributor

eclairevoyant commented Sep 10, 2024

I'm having this issue with 16 gb of ram, probably a bug

Depends what you're building and what your nix settings are.
This is either an RTM moment or the same as #320528, depending on what your scenario is.
Closing this as the main discussion is happening on the other issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants