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