Skip to content

Instantly share code, notes, and snippets.

@j-keck
Last active November 5, 2024 08:38
Show Gist options
  • Save j-keck/a85118e2f3e3dba1d1ce234acf131fd7 to your computer and use it in GitHub Desktop.
Save j-keck/a85118e2f3e3dba1d1ce234acf131fd7 to your computer and use it in GitHub Desktop.
nixos as bhyve guest

create a vm

root@main:~ # vm create -t debian -s 100G nixos
root@main:~ # vm iso /stuff/downloads/nixos-graphical-18.03.132192.ce0d9d638de-x86_64-linux.iso 
root@main:~ # vm -f install nixos nixos-graphical-18.03.132192.ce0d9d638de-x86_64-linux.iso

boot the image

determine the 'init' executable path from '(cd0)/isolinux/isolinux.cfg'. look for a line which start's with: 'APPEND init=/nix/store/.....'


grub> cat (cd0)/isolinux/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 18.03.132192.ce0d9d638de Installer
LINUX /boot/bzImage
APPEND init=/nix/store/g0g54c7aqrb2vizl5qb2fcyf6pqs6x32-nixos-system-nixos-18.03.132192.ce0d9d638de/init root=LABEL=NIXOS_ISO boot.shell_on_fail loglevel=4
INITRD /boot/initrd
.....

grub> # linux (cd0)/boot/bzImage <USE THE VALUE FROM YOUR 'APPEND' LINE !!!!>
grub> linux (cd0)/boot/bzImage init=/nix/store/g0g54c7aqrb2vizl5qb2fcyf6pqs6x32-nixos-system-nixos-18.03.132192.ce0d9d638de/init root=LABEL=NIXOS_ISO boot.shell_on_fail loglevel=4
grub> initrd (cd0)/boot/initrd
grub> boot

install nixos

note: i use a swapfile and i use only one partition

setup

[root@nixos:~]# parted -s /dev/sda -a optimal -- mkpart primary ext4 1 -1s
[root@nixos:~]# mkfs.ext4 /dev/sda1 
[root@nixos:~]# mount /dev/sda1 /mnt/
[root@nixos:~]# nixos-generate-config --root /mnt/

optional: add a swapfile if you have not enough ram

[root@nixos:~]# dd if=/dev/zero of=/mnt/swapfile bs=1M count=1000
[root@nixos:~]# chmod 0600 /mnt/swapfile
[root@nixos:~]# mkswap /mnt/swapfile
[root@nixos:~]# swapon /mnt/swapfile

configuration

add the following snippets to /mnt/etc/nixos/configuration.nix

boot.loader.grub.device = "/dev/sda";

swapDevices = [ { device = "/swapfile"; size = 1024; } ];

install

[root@nixos:~]# nixos-install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment