8

I installed NixOS 18.03 from Ubuntu on another partition following the NixOS manual's "2.4. Installing from another Linux distribution" section. Everything went fine, but I did a couple idiotic things [?], namely:

  • Forgot to add the extra GRUB boot loader entry for the Ubuntu installation before nixos-install. Added it as an afterthought after install, and did a reboot (of course, no Ubuntu entry)

  • Did not enable any networking in configuration.nix, and ended up with no network configuration commands after reboot to connect to wifi. The catch 22 is that nixos-rebuild switch requires a network connection, so I couldn't finalize any changes.

So my thinking was that I can boot from a NixOS Live CD (17.03),connect to our wifi and somehow rebuild the config of the installation.

It is more than possible that I am missing something essential, have incorrect assumptions above etc; fairly new at nix and NixOS.


EDIT: I forgot to include how my partitions are set up and what I tried before successfully installing NixOS.

Partitions (mountpoints from Ubuntu):

sda
├─sda1         ntfs     Recovery              # some Win7 artifact
├─sda2         vfat               /boot/efi
├─sda3         vfat     NIXBOOT               # boot partition (esp, boot)
├─sda4         ext4     onyx                  # NixOS data
├─sda5         swap                           # Ubuntu swap
│ └─cryptswap1 swap               [SWAP]
├─sda6         ext4                           # (Arch install)
├─sda7         ext4               /           # Ubuntu install
├─sda8         swap     nixswap   
└─sda9         ext4     home      

I didn't want to mess up the Ubuntu boot partition, so I created another one (/dev/sda3). My plan was to later include a menu entry in Ubuntu's GRUB for NixOS, but for now, install, reboot and test booting NixOS from GRUB console (set root=..., linux ..., initrd ..., boot)

sudo PATH="$PATH" NIX_PATH="$NIX_PATH" `which nixos-install` --root /mnt --no-bootloader

After reboot, I couldn't see anything on the NixOS boot partition. Went back to Ubunut, installed without --no-bootloader, remembered to add an entry for Ubuntu and reboot. (It was only after this that I realized that systemd-boot and GRUB are two completely different things...)


UPDATE: I was able to get back to Ubuntu by selecting the Ubuntu boot partition as an alternative boot device in BIOS, and the usual GRUB menu came up. I may just redo the install with the right config.

2
  • 1
    Use chroot to edit the configuration and rebuild. wiki.archlinux.org/index.php/Change_root#Using_chroot
    – Mio Rin
    May 28, 2018 at 15:32
  • In the end it was easier to just re-install NixOS, and the outdated NixOS chroot articles seemed intimidating, but I just realized that nixos-enter does just that. (It is also invoked by nixos-install when installing the boot loader.)
    – toraritte
    May 29, 2018 at 19:25

2 Answers 2

7

The simplest way to go is to install from the LiveCD.

nixos-generate-config will regenerate the hardware config, but if it finds configuration.nix already exists it will leave it alone. And nixos-install is designed such that it can be safely executed as many times as needed.

This means you can follow the main installation guide using the filesystem (and configuration) you already created for NixOS and just continue where you left off.

Some things to be mindful of:

  • NixOS will install systemd-boot by default on EFI systems. So you'll end up with a new EFI executable along side the ones you already have.
  • nixos-install will also attempt to set systemd-boot as the default boot manager. I believe you can disable this by setting boot.loader.efi.canTouchEfiVariables to false in configuration.nix
  • I recommend installing NixOS with a basic config; For example, setup networking, users, and install a text editor but not much else. The reason is that the LiveCD uses a Nix store which is held in RAM. Your system will be first installed to this RAM-backed Nix store and then copied to disk. Once installed and bootable you can safely proceed with the rest of the configuration.
3
  • Thanks for the great answer! A quick question (and I can ask this in a separate one if you like): based on your first tip, I could have just mounted to the existing boot partition (i.e., /dev/sda2) and nixos-install would only have added another EFI executable, correct? And if boot.loader.efi.canTouchEfiVariables had been set to false, I could've just used Ubuntu's GRUB and have an extra entry set up for NixOS?
    – toraritte
    May 29, 2018 at 2:53
  • 1
    Yep, that's correct. I've dual-booted NixOS with both MacOS and Windows 10 and in both cases I shared the same ESP (EFI partition). Setting boot.loader.efi.canTouchEfiVariables to false should tells the installer to leave your current boot manager (GRUB2) as the default. Then it's a matter of adding systemd-boot to GRUB2 as an item. Another way, especially if you have a lot of systems, is to install rEFInd and let it be the default. rEFInd checks your ESP for EFI executables and lists them, so you don't have to keep adding menu entries. May 29, 2018 at 17:07
1

Adding this answer for completeness sake: in theory, @Mioriin's suggestion above of chrooting would be the correct answer, that could be achieved by the command nixos-enter.

From Ubuntu, with the NixOS partitions mounted to /mnt:

$ sudo $(which nixos-enter)
...
[root@nixos:/]# nixos-rebuild switch

In practice, this did not work, because networking wouldn't work (probably because my configuration.nix was missing the right setup in the first place), and got a bunch of error messages:

warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
error: file 'nixpkgs/nixos' was not found in the Nix search path (add it using $NIX_PATH or -I), at (string):1:13
System has not been booted with systemd as init system (PID 1). Can't operate.
building Nix...
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
error: file 'nixpkgs/nixos' was not found in the Nix search path (add it using $NIX_PATH or -I)
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)
warning: unable to download 'https://cache.nixos.org/nix-cache-info': Couldn't resolve host name (6); retrying in 293 ms
^Cwarning: download of 'https://cache.nixos.org/nix-cache-info' was interrupted
don't know how to build these paths:
  /nix/store/z6avpvg24f6d1br2sr6qlphsq3h4d91v-nix-2.0.2
error: interrupted by the user
warning: don't know how to get latest Nix

In the end, @Emmanuel Rosa's answer is right one, especially because (as he points it out) nixos-install can be safely executed multiple times.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .