Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

Support for NixOS #63

Open
ashkitten opened this issue Apr 5, 2017 · 10 comments
Open

Support for NixOS #63

ashkitten opened this issue Apr 5, 2017 · 10 comments
Assignees

Comments

@ashkitten
Copy link

Not sure how to approach it. Unlike a "normal" Linux distro, NixOS uses the hash of the build process (or something like that, I don't understand fully how everything works yet) to specify the directory where things should be, for instance the init is stored (for the current version at least) in /nix/store/g5qa0gq6fhqfs56sckyx56d1002i59iw-nixos-system-nixos-17.03.889.9626bc7db7/init. Is there a way to get the linux options from the iso at boot time? Or do we have to make a new boot entry for each and every separate iso?

@aguslr aguslr self-assigned this Apr 6, 2017
@aguslr
Copy link
Owner

aguslr commented Apr 6, 2017

Hello @ashyon,

To load the boot options from NixOS ISO at boot time you can use syslinux_configfile but, even if they were loaded, we need to pass some parameters to the kernel so it knows to boot from the ISO file.

The closest thing I've found for NixOS is this entry in their mailing list which is far from ideal.

@ob7
Copy link

ob7 commented Apr 14, 2017

I've been trying to get NixOS to boot for the past 12 hours!!! Never gets past stage 1, as it can't find the root iso filesystem and mount it to /dev/root

@aguslr
Copy link
Owner

aguslr commented Apr 14, 2017

Hi @ob7. To make it work, I'd suggest contacting the developers at their IRC channel and see if they can help with this.

@ob7
Copy link

ob7 commented Apr 15, 2017

I think I need some kind of live initrd image to make it work. I couldn't get the Debian DVD installer to load using the normal initrm file but instead I had to swap it out with the one used for the debian live iso to get through a full Debian installation from the DVD with no network booted from my multiboot USB.

Will have to do some reading.

@baconicsynergy
Copy link

I also am in favor of supporting NixOS

@tmplt
Copy link

tmplt commented Jan 17, 2018

I am also in favor also. I'll try my hand at this.

@tmplt
Copy link

tmplt commented Jan 17, 2018

From an initial look at it, a boot parameter with a /nix/store hash must be supplied, and this cannot be derived from the iso's file name. It could be hard-coded, but I don't think we want that; it will break with every NixOS release.

@tmplt
Copy link

tmplt commented Jan 18, 2018

With the isolinux.cfg

SERIAL 0 38400
TIMEOUT 100
UI vesamenu.c32
MENU TITLE NixOS
MENU BACKGROUND /isolinux/background.png
DEFAULT boot

LABEL boot
MENU LABEL NixOS 17.09.1483.d0f0657ca0 Installer
LINUX /boot/bzImage
APPEND init=/nix/store/k2dd07cmp1iixhljc600qkii4kd528d9-nixos-system-nixos-17.09.1483.d0f0657ca0/init root=LABEL=NIXOS_ISO boot.shell_on_fail loglevel=4
INITRD /boot/initrd

# A variant to boot with 'nomodeset'
LABEL boot-nomodeset
MENU LABEL NixOS 17.09.1483.d0f0657ca0 Installer (nomodeset)
LINUX /boot/bzImage
APPEND init=/nix/store/k2dd07cmp1iixhljc600qkii4kd528d9-nixos-system-nixos-17.09.1483.d0f0657ca0/init root=LABEL=NIXOS_ISO boot.shell_on_fail loglevel=4 nomodeset
INITRD /boot/initrd

# A variant to boot with 'copytoram'
LABEL boot-copytoram
MENU LABEL NixOS 17.09.1483.d0f0657ca0 Installer (copytoram)
LINUX /boot/bzImage
APPEND init=/nix/store/k2dd07cmp1iixhljc600qkii4kd528d9-nixos-system-nixos-17.09.1483.d0f0657ca0/init root=LABEL=NIXOS_ISO boot.shell_on_fail loglevel=4 copytoram
INITRD /boot/initrd

# A variant to boot with verbose logging to the console
LABEL boot-nomodeset
MENU LABEL NixOS 17.09.1483.d0f0657ca0 Installer (debug)
LINUX /boot/bzImage
APPEND init=/nix/store/k2dd07cmp1iixhljc600qkii4kd528d9-nixos-system-nixos-17.09.1483.d0f0657ca0/init root=LABEL=NIXOS_ISO boot.shell_on_fail loglevel=4 loglevel=7
INITRD /boot/initrd
LABEL memtest
MENU LABEL Memtest86+
LINUX /boot/memtest.bin
APPEND 

I have the following nixos.d/minimal-generic.cfg as test:

for isofile in $isopath/nixos-minimal-*-linux.iso; do
  if [ -e "$isofile" ]; then
    regexp --set=isoname "$isopath/(.*)" "$isofile"
    submenu "$isoname ->" "$isofile" {
      iso_path="$2"
      loopback loop "$iso_path"
      root=(loop)
      menuentry "NixOS Installer" {
        bootoptions="init=/nix/store/k2dd07cmp1iixhljc600qkii4kd528d9-nixos-system-nixos-17.09.1483.d0f0657ca0/init root=LABEL=NIXOS_ISO boot.shell_on_fail loglevel=4"
        linux /boot/bzImage $bootoptions
        initrd /boot/initrd
      }
    }
  fi
done

It boots, but State 1 fails waiting for /dev/root to appear. An old NixOS issue mentions labeling the USB device as NIXOS_ISO fixed the issue, but is this not what the boot option root=LABEL=NIXOS_ISO does?

@573
Copy link

573 commented Aug 27, 2019

Basically following this guide with the above config worked.
If the isos live on a non-linux partition type i. e. fat32 (i. e. you wanted to reuse the partition for more diverse purpose) there could still be a problem with that approach.

@573
Copy link

573 commented Jan 29, 2020

@tmplt I can confirm that I was now able to boot a nixos iso using multibootusb by doing the as follows but let me first state my assumptions:
the stick i am using has three partitions, two of them (efi and data, data is where the isos are stored) formatted as fat, the boot partition linux.

the bootoptions used in the mbusb.d/nixos.d/generic.cfg file are stolen from the iso file I was going to use, loop mount or 7zip-open it for that task, i. e. nixos-minimal-19.09.1861.eb65d1dae62-x86_64-linux.iso/EFI/boot/grub.cfg
Of importance here seemed the root=LABEL=NIXOS_ISO, meaning that I labeled (i. e. using mlabel on linux) my usbsticks data partition NIXOS_ISO.
Also I found out that it seems needed currently to copy the nixos-minimal-19.09.1861.eb65d1dae62-x86_64-linux.iso/nix-store.squashfs file to the usbsticks root, thus it can be found in stage 1 of the boot process.

for isofile in $isopath/nixos-minimal-*-linux.iso; do
  if [ -e "$isofile" ]; then
    regexp --set=isoname "$isopath/(.*)" "$isofile"
    submenu "$isoname ->" "$isofile" {
      iso_path="$2"
      loopback loop "$iso_path"
      root=(loop)
      menuentry "NixOS Installer" {
        bootoptions="init=/nix/store/8v4s9yd1p4lqxbv0vbimihxf4d977xa2-nixos-system-nixos-19.09.1861.eb65d1dae62/init  root=LABEL=NIXOS_ISO boot.shell_on_fail loglevel=4 findiso=nixos-minimal-19.09.1861.eb65d1dae62-x86_64-linux.iso"
        linux /boot/bzImage $bootoptions
        initrd /boot/initrd
      }
    }
  fi
done

In case you wanna work that out further, see as well https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/system/boot/stage-1-init.sh#L136 as a reference.

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

No branches or pull requests

6 participants