Skip to content

Instantly share code, notes, and snippets.

@danbst
Created June 7, 2017 17:59
Show Gist options
  • Save danbst/92c5c445bcb6096b307d206960e1a490 to your computer and use it in GitHub Desktop.
Save danbst/92c5c445bcb6096b307d206960e1a490 to your computer and use it in GitHub Desktop.

Switching NixOS architecture (32bit -> 64bit)

There are rumors, that you can switch from system architecture just adding 1 configuration option:

nixpkgs.system = "x86_64-linux"

and running nixos-rebuild boot && reboot.

I've used 32-bit on my netbook, but recently I've trapped into sutuation where I need 64-bit system. I've set the above option in configuration.nix... and got tons of errors.

Long story short, Nix tries to build itself and activate new 64bit configuration using 64bit tools. But hey, we are 32bit, we can't use 64bit tools (specifically, perl executable)!

So here is an algorithm to properly switch architecture:

  • Change your linux kernel to 64bit one first. I've done it like this:

    boot.kernelPackages = (import <nixpkgs> { system = "x86_64-linux"; }).linuxPackages;
    

    I expect that to be in binary cache, so you won't build it.

  • nixos-rebuild boot && reboot

  • After reboot remove that option and add

    nixpkgs.system = "x86_64-linux";
    

    to change userspace from 32bit to 64bit.

  • nixos-rebuild switch (no reboot required). Be ready to redownload everything from binary cache! You may still want to do reboot to restart some services (but maybe systemd has an option to restart all of userspace without cold reboot?).

But in case you switch from 64-bit to 32-bit, rumors are correct. Simply change nixpkgs.system = "i686-linux"; && nixos-rebuild switch && reboot

== What to do when no kernel binary available ==

The above algorithm relies on 64-bit kernel availability in binary cache. Which may not be a case when you have some kernel tweaks (kernel config, kernel patches, etc). Be sure that your NIX_PATH points to some stable or very recent channel, so binary availability won't be a problem.

Otherwise, you're still not in trouble:

  1. Apply your tweaks only after you switched kernel to 64-bit (so you'll rebuild 64-bit kernel in 64-bit system, because you can)

  2. Use the more complicated approach from this issue report It requires a USB (or CD-ROM) with NixOS

  3. Build a kernel in another machine and then copy back the result. NixOS has support for this:

    nixos-rebuild boot --build-host 10.0.0.100 # where 10.0.0.100 is a SSH accessible 64-bit system

    Or use distributed Nix build feature.

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