Setup NixOS (Virtualized + Haskell + Gnome3 + XMonad)
Before you get started
This is pretty out of date now... you may want to look elsewhere
Newer guides than mine (mine is a bit dated and has a lot of rough edges):
Have you looked at these?
- GitHub ❤ ~/
- Awesome dotfiles
- Real World NixOS Dotfiles
- Please let me know what else should go here...
These guidelines show how to install NixOS in VirtualBox with a bunch of stuff I find useful. Feel free to comment / fork / whatever.
DISCLAIMER: This is a rough guide that should only be used by people who are willing to check each step of the process themselves - if you mess up you can destroy your current setup, so be careful.
Why run NixOS inside VirtualBox?
- It's quick & simple and less likely to break your system.
- I tried to install NixOS directly on my MacBook Pro (2015), but couldn't manage to get the wifi firmware to work.
- If you're running OSX you can hopefully take advantage of the native power management for longer battery life, native firmware for everything etc. Stuff just works more.
- Virtualization seems like it could be pretty fast (I did notice that things felt a little bit laggy for me though, I'm still experimenting)
- These steps are setup to make it easy to switch to a native installation once you're ready.
- It may be easier to install unfree wifi firmware in virtualbox...
Intent behind this configuration
- It's my own config, intended to get me up and running quickly (i.e. it's opinionated and probably a bit hacky). Features:
- Window manager: xmonad (a highly customizable, tiling window manager)
- Haskell dev tools
- Do the minimal installation possible, it's easy to make additions, change things after you have a working installation.
- Uses native partitions - should in theory make it easy to switch to a native installation when you're ready.
- I used a variation of the steps provided by Install Linux on a MacBook Air and Installing NixOS in a VirtualBox guest.
When I set up my MacBook I made sure to turn off encryption, avoid logical volume stuff etc for the primary disk so that I wouldn't have to deal with any annoying issues when resizing my partitions.
I use two proper partitions (one for my
/ root directory containing operating system files + packages etc, one for my
/home directory containing data + projects etc) on my laptop instead of relying on virtual disks. This should in theory make it easy to browse around your computer (nothing is hidden behind a
.vdi file) or to install NixOS natively in future if you prefer to move away from VirtualBox.
Free some space (OSX specific instructions)
Open Disk Utility, click on “Macintosh HD”, add new partition, choose size (e.g., half), choose format as free space, apply. I'm not sure if this is going to work well, but it might be possible to mount the partition for home
/home that is given to NixOS in OSX and share the space that way (instead of the usual shared folders).
Download NixOS ISO
Download the Minimal 64 bit ISO
Install Homebrew + Cask + VirtualBox (OSX specific instructions)
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew tap caskroom/cask brew install brew-cask brew cask install virtualbox
Create the VM
The following steps may require
sudo. I haven't figured out how to create the
.vmdk file without
nixos_livecd=path/to/downloaded/iso # create vm VBoxManage createvm \ --name nixos \ --ostype Linux_64 \ --register # create a virtual disk for the boot loader # (since you obviously don't want to replace your native boot loader) # Recommend between 200MB-300MB according to https://wiki.archlinux.org/index.php/Partitioning#How_big_should_my_partitions_be.3F VBoxManage createhd \ --filename "$HOME/VirtualBox VMs/nixos/boot.vdi" \ --size 300 # create virtual disk/cd controller VBoxManage storagectl nixos \ --name IDE \ --add ide \ --controller PIIX4 \ --portcount 42 \ --hostiocache on \ --bootable on # attach boot disk image to VM VBoxManage storageattach nixos \ --storagectl IDE \ --type hdd \ --port 0 \ --device 0 \ --medium "$HOME/VirtualBox VMs/nixos/boot.vdi" # attach livecd VBoxManage storageattach nixos \ --storagectl IDE \ --type dvddrive \ --port 1 \ --device 0 \ --medium $nixos_livecd # attach the disk that is going to contain swap, / and /home partitions VBoxManage createhd \ --filename "$HOME/VirtualBox VMs/nixos/nixos.vmdk" \ --format VMDK # TODO: I'm not sure about the details here... you probably need more flags # bump up memory and CPU (you should probably increase this) VBoxManage modifyvm nixos --memory 1024 --cpus 2 # enable usb port VBoxManage modifyvm nixos --usb on
Create / format partitions
You may want to do create a logical volume with encryption instead, but I haven't tried this yet.
# Create boot partition gdisk /dev/sda n # new partition <enter> # default partition # <enter> # default start location <enter> # use the entire disk ef02 # type boot w # write partitions y # confirm # Create swap space, partition for /, partition for /home gdisk /dev/sdb n # new partition <enter> # default partition # <enter> # default start location +2G # maybe 2 GB swap space? 8200 # swap space n # new partition <enter> # default partition # <enter> # default start location +100G # maybe 100 GB for operating system files? 8300 # linux filesystem (this will be the root / path) n # new partition <enter> # default partition # <enter> # default start location <enter> # use all remaining space (maybe 300 GB?) 8302 # linux /home path w # write partitions y # confirm # Check that everything looks ok fdisk -l # e.g. # # Device Start End Sectors Size Type # /dev/sda1 2048 1048542 1046495 299M BIOS boot # # Device Start End Sectors Size Type # /dev/sdb1 40 xxxxxx 409600 200M EFI System # /dev/sdb2 xxxxxxxx xxxxxx xxxxxxx 32.6G Apple Core storage # /dev/sdb3 xxxxxxxx xxxxxx xxxxxxx 619.9M Apple boot # /dev/sdb4 xxxxxxxx xxxxxx xxxxxxx 2G Linux swap # /dev/sdb5 xxxxxxxx xxxxxx xxxxxxx 100G Linux filesystem # /dev/sdb6 xxxxxxxx xxxxxx xxxxxxx 300G Linux home # Format the partitions mkfs.ext2 -L boot /dev/sda1 mkswap -L swap /dev/sdb4 mkfs.ext4 -j -L nixos /dev/sdb5 mkfs.ext4 -j -L home /dev/sdb6
NixOS will generate its hardware config based on what is mounted.
swapon /dev/sdb4 mount /dev/sdb5 /mnt mkdir /mnt/home ; mount /dev/sdb6 /mnt/home mkdir /mnt/boot ; mount /dev/sda1 /mnt/boot
Minimal configuration to install NixOS
I recommend doing the minimum possible to install NixOS. It's easier to modify it with a new config after your installation is finished.
# You can do this repeatedly, it will only overwrite /mnt/etc/nixos/hardware-configuration.nix not /mnt/etc/nixos/configuration.nix nixos-generate-config --root /mnt
boot.loader.grub.device = "/dev/sda"; # Carefull! this should be the virtual boot disk we created before, not your real disk!
Copy a configuration of your choice
/etc/nixos/configuration.nix and use
nixos-rebuild switch to update the system-wide configuration - try not to do anything that should be done as a user (I.e. avoid acting as
sudo whenever possible).
Switch to or roll your own full-fledged configuration of your choice (see configuration.nix below)
Configurations I sometimes look at
- dwm + apple trackpad (profile.nix)
- gnome3 + select variation for 2 different machines (laptop vs desktop)
- xmonad repos / xmonad gists / xmonad #nixos / xmonad issues
- gnome3 repos / gnome3 gists / gnome3 #nixos / gnome3 issues
- lightdm repos / lightdm gists / lightdm #nixos / lightdm issues
- gdm repos / gdm gists / gdm #nixos / gdm issues
- macbook repos / macbook gists / macbook #nixos / macbook issues
- lxde repos / lxde gists / lxde #nixos / lxde issues
- yi repos / yi gists / yi #nixos / yi issues
- vim repos / vim gists / vim #nixos / vim issues
- emacs repos / emacs gists / emacs #nixos / emacs issues
- chromium repos / chromium gists / chromium #nixos / chromium issues
- chrome repos / chrome gists / chrome #nixos / chrome issues
- firefox repos / firefox gists / firefox #nixos / firefox issues