1# Vagrant + VirtualBox
2
3{
4 config,
5 pkgs,
6 lib,
7 ...
8}:
9
10{
11 imports = [
12 ./vagrant-guest.nix
13 ./virtualbox-image.nix
14 ];
15
16 virtualbox.params = {
17 audio = "none";
18 audioin = "off";
19 audioout = "off";
20 usb = "off";
21 usbehci = "off";
22 };
23 documentation.man.enable = false;
24 documentation.nixos.enable = false;
25
26 users.extraUsers.vagrant.extraGroups = [ "vboxsf" ];
27
28 # generate the box v1 format which is much easier to generate
29 # https://www.vagrantup.com/docs/boxes/format.html
30 image.extension = lib.mkOverride 999 "${config.image.baseName}.box";
31 system.nixos.tags = [ "vagrant" ];
32 system.build.image = lib.mkOverride 999 config.system.build.vagrantVirtualbox;
33 system.build.vagrantVirtualbox = pkgs.runCommand config.image.fileName { } ''
34 mkdir workdir
35 cd workdir
36
37 # 1. create that metadata.json file
38 echo '{"provider":"virtualbox"}' > metadata.json
39
40 # 2. create a default Vagrantfile config
41 cat <<VAGRANTFILE > Vagrantfile
42 Vagrant.configure("2") do |config|
43 config.vm.base_mac = "0800275F0936"
44 end
45 VAGRANTFILE
46
47 # 3. add the exported VM files
48 tar xvf ${config.system.build.virtualBoxOVA}/*.ova
49
50 # 4. move the ovf to the fixed location
51 mv *.ovf box.ovf
52
53 # 5. generate OVF manifest file
54 rm *.mf
55 touch box.mf
56 for fname in *; do
57 checksum=$(sha256sum $fname | cut -d' ' -f 1)
58 echo "SHA256($fname)= $checksum" >> box.mf
59 done
60
61 # 6. compress everything back together
62 tar --owner=0 --group=0 --sort=name --numeric-owner -czf $out .
63 '';
64}