nixos/virtualbox: Adds more options to virtualbox-image.nix (#42699)

* nixos/virtualbox: Adds more options to virtualbox-image.nix

Previously you could only set the size of the disk.

This change adds the ability to change the amount of memory
that the image gets, along with the name / derivation name /
file name for the VM.

* Incorporates some review feedback

authored by Dave Laing and committed by xeji 4d5371f3 b34a147e

+32 -4
+32 -4
nixos/modules/virtualisation/virtualbox-image.nix
··· 17 The size of the VirtualBox base image in MiB. 18 ''; 19 }; 20 }; 21 }; 22 23 config = { 24 system.build.virtualBoxOVA = import ../../lib/make-disk-image.nix { 25 - name = "nixos-ova-${config.system.nixos.label}-${pkgs.stdenv.system}"; 26 27 inherit pkgs lib config; 28 partitionTableType = "legacy"; ··· 37 VBoxManage internalcommands createrawvmdk -filename disk.vmdk -rawdisk $diskImage 38 39 echo "creating VirtualBox VM..." 40 - vmName="NixOS ${config.system.nixos.label} (${pkgs.stdenv.system})" 41 VBoxManage createvm --name "$vmName" --register \ 42 --ostype ${if pkgs.stdenv.system == "x86_64-linux" then "Linux26_64" else "Linux26"} 43 VBoxManage modifyvm "$vmName" \ 44 - --memory 1536 --acpi on --vram 32 \ 45 ${optionalString (pkgs.stdenv.system == "i686-linux") "--pae on"} \ 46 --nictype1 virtio --nic1 nat \ 47 --audiocontroller ac97 --audio alsa \ ··· 53 54 echo "exporting VirtualBox VM..." 55 mkdir -p $out 56 - fn="$out/nixos-${config.system.nixos.label}-${pkgs.stdenv.system}.ova" 57 VBoxManage export "$vmName" --output "$fn" 58 59 rm -v $diskImage
··· 17 The size of the VirtualBox base image in MiB. 18 ''; 19 }; 20 + memorySize = mkOption { 21 + type = types.int; 22 + default = 1536; 23 + description = '' 24 + The amount of RAM the VirtualBox appliance can use in MiB. 25 + ''; 26 + }; 27 + vmDerivationName = mkOption { 28 + type = types.str; 29 + default = "nixos-ova-${config.system.nixos.label}-${pkgs.stdenv.system}"; 30 + description = '' 31 + The name of the derivation for the VirtualBox appliance. 32 + ''; 33 + }; 34 + vmName = mkOption { 35 + type = types.str; 36 + default = "NixOS ${config.system.nixos.label} (${pkgs.stdenv.system})"; 37 + description = '' 38 + The name of the VirtualBox appliance. 39 + ''; 40 + }; 41 + vmFileName = mkOption { 42 + type = types.str; 43 + default = "nixos-${config.system.nixos.label}-${pkgs.stdenv.system}.ova"; 44 + description = '' 45 + The file name of the VirtualBox appliance. 46 + ''; 47 + }; 48 }; 49 }; 50 51 config = { 52 system.build.virtualBoxOVA = import ../../lib/make-disk-image.nix { 53 + name = cfg.vmDerivationName; 54 55 inherit pkgs lib config; 56 partitionTableType = "legacy"; ··· 65 VBoxManage internalcommands createrawvmdk -filename disk.vmdk -rawdisk $diskImage 66 67 echo "creating VirtualBox VM..." 68 + vmName="${cfg.vmName}"; 69 VBoxManage createvm --name "$vmName" --register \ 70 --ostype ${if pkgs.stdenv.system == "x86_64-linux" then "Linux26_64" else "Linux26"} 71 VBoxManage modifyvm "$vmName" \ 72 + --memory ${toString cfg.memorySize} --acpi on --vram 32 \ 73 ${optionalString (pkgs.stdenv.system == "i686-linux") "--pae on"} \ 74 --nictype1 virtio --nic1 nat \ 75 --audiocontroller ac97 --audio alsa \ ··· 81 82 echo "exporting VirtualBox VM..." 83 mkdir -p $out 84 + fn="$out/${cfg.vmFileName}" 85 VBoxManage export "$vmName" --output "$fn" 86 87 rm -v $diskImage