Skip to content

Instantly share code, notes, and snippets.

@nZac
Created February 21, 2018 17:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nZac/00b3db39e88b664b6121362764df7d33 to your computer and use it in GitHub Desktop.
Save nZac/00b3db39e88b664b6121362764df7d33 to your computer and use it in GitHub Desktop.
Basic NixOS Virtualbox Setup
# Original: https://nixos.wiki/wiki/NixOS_on_ZFS#How_to_install_NixOS_on_a_ZFS_root_filesystem
# Make sure to enable EFI support in VB. Settings -> System -> Enable EFI
# Add the zfs filesystem to the install environment:
nano /etc/nixos/configuration.nix
## ---8<-------------------------8<---
boot.supportedFilesystems = [ "zfs" ];
## ---8<-------------------------8<---
nixos-rebuild switch
# Load the just installed ZFS kernel module
modprobe zfs
sgdisk -n3:1M:+512M -t3:EF00 /dev/disk/by-id/scsi-SATA_disk1
sgdisk -n1:0:0 -t1:BF01 /dev/disk/by-id/scsi-SATA_disk1
zpool create -o ashift=12 \
-O atime=off -O canmount=off -O compression=lz4 -O normalization=formD \
-O mountpoint=/ -R /mnt \
rpool /dev/disk/by-id/scsi-SATA_disk1-part1
# Create the filesystems
zfs create -o mountpoint=none rpool/root
zfs create -o mountpoint=legacy rpool/root/nixos
zfs create -o mountpoint=legacy rpool/home
zfs set compression=lz4 rpool/home
# Mount the filesystems manually
mount -t zfs rpool/root/nixos /mnt
mkdir /mnt/home
mount -t zfs rpool/home /mnt/home
# Create the FAT Disk for EFI booting
mkfs.fat -F32 /dev/disk/by-id/scsi-SATA_disk1-part3
mkdir /mnt/boot
mount /dev/disk/by-id/scsi-SATA_disk1-part3 /mnt/boot
# Generate the NixOS configuration, as per the NixOS manual
nixos-generate-config --root /mnt
# Now edit the generated hardware config:
nano /mnt/etc/nixos/hardware-configuration.nix
## ---8<-------------------------8<---
# This is what you want:
fileSystems."/" =
{ device = "rpool/root/nixos";
fsType = "zfs";
};
fileSystems."/home" =
{ device = "rpool/home";
fsType = "zfs";
};
fileSystems."/boot" =
{ device = "/dev/disk/by-uuid/2222-2222";
fsType = "vfat";
};
## ---8<-------------------------8<---
# configuration.nix needs an adjustment:
nano /mnt/etc/nixos/configuration.nix
## ---8<-------------------------8<---
# This is some more of what you want:
networking.hostId = " # generate a hex value for this
boot.supportedFilesystems = [ "zfs" ];
## ---8<-------------------------8<---
# Ready to go!
nixos-install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment