thias / glim

GRUB Live ISO Multiboot
692 stars 142 forks source link

Add support for NixOS #120

Open thias opened 1 year ago

thias commented 1 year ago

Creating this for reference, since I've just tried and failed. Maybe someone else will have better luck than me...

This almost works, but gives an error about not being able to mount the GLIM filesystem on /findiso because of "device of resource busy":

# NixOS
function add_menu {
  isofile="$1"

  regexp \
    --set 1:isoname \
    --set 2:variant \
    --set 3:version \
    "^${isopath}/nixos/(nixos-([^-]+)-([0-9]+\.[0-9]+).*-([^-]+)-linux\.iso)\$" "${isofile}"
  menuentry "NixOS ${version} ${variant}" "${isofile}" "${isoname}" --class nixos {
    set isofile=$2
    set isoname=$3
    use "${isoname}"
    loop $isofile
    probe --set isolabel --label (loop)
    linux (loop)/boot/bzImage findiso=${isofile} init=/nix/store/3d6j0n5fjw1yrdpfdyy70072zm8iq04v-nixos-system-nixos-23.05.4407.80c1aab72515/init  root=LABEL=${isolabel} # boot.shell_on_fail video=hyperv_fb:1152x864 elevator=noop nohibernate splash loglevel=4 nomodeset
    initrd (loop)/boot/initrd
  }
}

for_each_sorted add_menu "$isopath"/nixos/nixos-*-linux.iso

Since the above has a very unique init= parameter, I also tried using the provided grub2 loobpack configuration. That loads the provided grub menu, but entries freeze for me:

# NixOS
function add_menu {
  isofile="$1"

  regexp \
    --set 1:isoname \
    --set 2:variant \
    --set 3:version \
    "^${isopath}/nixos/(nixos-([^-]+)-([0-9]+\.[0-9]+).*-([^-]+)-linux\.iso)\$" "${isofile}"
  menuentry "NixOS ${version} ${variant}" "${isofile}" "${isoname}" --class nixos { 
    set isofile=$2
    set isoname=$3
    use "${isoname}"
    loop $isofile
    change_root (loop)
    set iso_path=$isofile
    export iso_path
    configfile /boot/grub/loopback.cfg
    restore_root
  }
}

for_each_sorted add_menu "$isopath"/nixos/nixos-*-linux.iso

Possibly something that needs to be sanitized better.

akaihola commented 5 months ago

Hey @thias, your second configuration worked out of the box for me for nixos-rescue! I'll try the NixOS installer next.

Creating this for reference, since I've just tried and failed. Maybe someone else will have better luck than me...

[...] I also tried using the provided grub2 loobpack configuration. That loads the provided grub menu, but entries freeze for me:

# NixOS
function add_menu {
  isofile="$1"

  regexp \
    --set 1:isoname \
    --set 2:variant \
    --set 3:version \
    "^${isopath}/nixos/(nixos-([^-]+)-([0-9]+\.[0-9]+).*-([^-]+)-linux\.iso)\$" "${isofile}"
  menuentry "NixOS ${version} ${variant}" "${isofile}" "${isoname}" --class nixos { 
    set isofile=$2
    set isoname=$3
    use "${isoname}"
    loop $isofile
    change_root (loop)
    set iso_path=$isofile
    export iso_path
    configfile /boot/grub/loopback.cfg
    restore_root
  }
}

for_each_sorted add_menu "$isopath"/nixos/nixos-*-linux.iso

Possibly something that needs to be sanitized better.

onnyyonn commented 3 months ago

The second configuration worked for me. Tried it on NixOS Plasma6 24.05.