Install VirtualBox on NixOS


I use VirtualBox to do almost all of my development. I rarely install programming environments on my host machine. I have recently switched to using NixOS, so I needed to figure out how to install VirtualBox on NixOS.

Installing VirtualBox is relatively straight-forward on NixOS, but there are a few things to watch out for if you want to use the Oracle Extension Pack.

The following instructions are for NixOS version 18.03.

Installing VirtualBox normally

It is easy to install VirtualBox.

First, add the setting to your /etc/nixos/configuration.nix:

Then, rebuild:

This will install the VirtualBox executable and kernel modules.1

Running VirtualBox will bring up the VirtualBox application as expected.

Note that you do not need to add virtualbox to your environment.systemPackages. The setting will make sure this happens automatically.

Installing VirtualBox with the Oracle Extension Pack

(Note: these instructions are for NixOS 18.03. Instructions for 18.09 and up can be found here. Versions of NixOS before 18.03 may or may not work.)

Installing VirtualBox with the Oracle Extension Pack is a little more difficult.

First, you need to add the enableExtensionPack setting to your configuration.nix:

Then, run nixos-rebuild switch:

This should fail with a message like the following:

In order to use the extension pack, you need to comply with the VirtualBox Personal Use
and Evaluation License (PUEL) available at:

Once you have read and if you agree with the license, please use the
following command and re-run the installation:



This is saying that you must manually download the Oracle Extension Pack.

It can be downloaded with the command provided:

After downloading the Extension Pack, run nixos-rebuild switch again. It should succeed this time.

Unfortunately, the VirtualBox derivation is setup in such a way that enabling the Extension Pack causes VirtualBox to be recompiled from source. This takes quite a while. You are not able to make use of a binary cache.

Also, there is currently no way to automate the downloading of the Extension Pack. You will have to manually download it every time you update VirtualBox.

I think this is quite an unfortunate situation. As an end-user, I love NixOS because of the ability to run one command to have my entire system setup. I created an issue about this on the nixpkgs Github, but there does not currently seem to be any solution to this problem[^3].

Installing VirtualBox from unstable

It would be nice to be able to install VirtualBox from the nixos-unstable channel.

However, I have not been able to figure this out. I have created a question on Stack Overflow, as well as a related issue on Github, but this has not yet been resolved.

For now, it does not look like there is any way to install VirtualBox from unstable.


Installing VirtualBox is quite simple on NixOS. Just one line in your configuration.nix. However, installing the Oracle Extension Pack requires some manual work.


  1. It could be possible that a reboot is required after running nixos-rebuild switch, if the VirtualBox kernel modules are being built for a kernel different from the one you are currently running. In most cases a reboot will not be required.

tags: nixos