nix-community / nixos-anywhere

install nixos everywhere via ssh [maintainer=@numtide]
https://nix-community.github.io/nixos-anywhere/
MIT License
1.58k stars 109 forks source link

Skip kexec if Nixos is detected? #405

Open ritiek opened 1 week ago

ritiek commented 1 week ago

Hello!

I've been trying to nixos-anywhere to a x86_64-linux target machine having 512 MB physical RAM from my host machine. The installer runs of out of memory if I first boot the target machine into the official minimal installer ISO and run nixos-anywhere from my host machine to this target machine.

So I generated a custom minimal ISO using nixos-generators with zram enabled using the following module:

{
  networking.hostName = "minimal-iso";

  users.users.root.openssh.authorizedKeys.keys = [ "my-ssh-key" ];

  services.openssh = {
    enable = true;
    startWhenNeeded = true;
    settings = {
      PermitRootLogin = "yes";
      PasswordAuthentication = false;
    };
  };

  powerManagement.cpuFreqGovernor = "performance";

  zramSwap = {
    enable = true;
    memoryPercent = 100;
  };

  nix.settings.auto-optimise-store = true;

  system.stateVersion = "24.05";
}

Building the above configuration in install-iso format generates an ISO image. Booting into this ISO on my target machine and then performing nixos-anywhere from my host machine looks to succeed now!


However, I also noticed that if build the same configuration in iso format, the resulting ISO image is much smaller; ~400 MB (vs ~1.2GB when using install-iso format).

If I boot from this image on the target machine and then perform nixos-anywhere from my host machine, the installer again runs of out memory as it seems to execute kexec by default (which seems unnecessary to me in this case as target is already booted into Nixos). The installation succeeds if I omit kexec while explicitly passing phases (--phases disko,install,reboot).

Given this, curious shouldn't it be enough to check whether the target OS is Nixos when deciding to skip kexec (no need to check whether it's an installer image on top of Nixos):

https://github.com/nix-community/nixos-anywhere/blob/3fb834da466b75300a9141f9a68869c56fbd28f3/src/nixos-anywhere.sh#L463-L466

- if [[ ${isKexec} == "y" ]] || [[ ${isInstaller} == "y" ]]; then
+ if [[ ${isKexec} == "y" ]] || [[ ${isNixos} == "y" ]]; then
sedlund commented 1 week ago

the installer images are built with all kernel modules and firmware enabled so that nixos-generate-config can probe to generate a hardware-configuration.nix