Installing NixOS in a VirtualBox guest
From Nix Wiki
(Redirected from InstallingOnVirtualBox)
This pages describes how to install NixOS in a VirtualBox guest.
- Download a NixOS ISO from http://nixos.org
- Add a New Machine in VirtualBox with OS Type "Linux / Other Linux"
- Base Memory Size: 768 MB
- New Hard Disk of 8 GB
- Mount the CD-ROM with the NixOS ISO (by clicking on CD/DVD-ROM)
- Click on Settings / Advanced (or possibly System / Processor) and enable PAE/NX
- Networking: select "Attached to: NAT". Change host-interface to "en1: Airport".
- Now you can install NixOS:
$ fdisk /dev/sda (create a full partition, don't skip this step, example commands for quick setup: n,p,1,w) $ mkfs.ext4 -j -L nixos /dev/sda1 (idem) $ mount LABEL=nixos /mnt $ mkdir -p /mnt/etc/nixos $ nixos-hardware-scan > /mnt/etc/nixos/configuration.nix (for quick setup overwrite configuration.nix completely with example below) $ nano /mnt/etc/nixos/configuration.nix
(add the fileSystems. this is what my final config looks like:)
{ config, pkgs, ...} :
{
boot.loader.grub.device = "/dev/sda";
services.openssh.enable = true;
services.virtualbox.enable = true;
fileSystems = [
{ mountPoint = "/";
label = "nixos";
}
];
}
Now we're ready to install!
$ nixos-install $ reboot
Now you got a working nixos system.
[edit] SSH-ing into the box
However, you can't conveniently log in to ssh this way, so you'll need to set up port-forwarding. Doing that is explained on this site, all you have to do is create a script named "vbox-tunnel" that contains the following lines:
#!/bin/bash cd /Applications/VirtualBox.app/Contents/MacOS/ ./VBoxManage setextradata "$1" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/$2/Protocol" TCP ./VBoxManage setextradata "$1" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/$2/GuestPort" $3 ./VBoxManage setextradata "$1" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/$2/HostPort" $4
Now execute the script:
vbox-tunnel Nix sshtunnel 22 2222
You should be able to log in to Nix now by running ssh -p2222 localhost in your OS X Terminal. Enjoy!
Alternative (independent of virtual network card chosen for the guest):
VBoxManage modifyvm "Nix" --natpf1 "sshtunnel,tcp,,2222,,22"
As before, you are now able to log in to Nix by running ssh -p2222 localhost in your terminal.