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