/
Installing NixOS in a VirtualBox guest.page
84 lines (61 loc) · 3.22 KB
/
Installing NixOS in a VirtualBox guest.page
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
This pages describes how to install NixOS in a VirtualBox guest.
- Download a NixOS ISO from <http://nixos.org/releases/nixos/>
- 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
- Click on Settings / Advanced (or possibly System / Acceleration) and
enable "VT-x/AMD-V" acceleration
- 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
$ nixos-generate-config --root /mnt (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](/w/index.php?title=Installing_NixOS_in_a_VirtualBox_guest&action=edit§ion=1 "Edit section: SSH-ing into the box")] 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.
[[edit](/w/index.php?title=Installing_NixOS_in_a_VirtualBox_guest&action=edit§ion=2 "Edit section: Vagrant boxes")] Vagrant boxes
-------------------------------------------------------------------------------------------------------------------------------------
Alternatively you can also use packer to generate vagrant boxes. Both
packer and vagrant aren't available in the nixpkgs repo yet but it can
be a good way to test out NixOS on another OS.
The build instructions and code are available there:
<https://github.com/zimbatm/nixbox>