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
This commit is contained in:
parent
b34a147eef
commit
4d5371f373
@ -17,12 +17,40 @@ in {
|
|||||||
The size of the VirtualBox base image in MiB.
|
The size of the VirtualBox base image in MiB.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
memorySize = mkOption {
|
||||||
|
type = types.int;
|
||||||
|
default = 1536;
|
||||||
|
description = ''
|
||||||
|
The amount of RAM the VirtualBox appliance can use in MiB.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
vmDerivationName = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "nixos-ova-${config.system.nixos.label}-${pkgs.stdenv.system}";
|
||||||
|
description = ''
|
||||||
|
The name of the derivation for the VirtualBox appliance.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
vmName = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "NixOS ${config.system.nixos.label} (${pkgs.stdenv.system})";
|
||||||
|
description = ''
|
||||||
|
The name of the VirtualBox appliance.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
vmFileName = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "nixos-${config.system.nixos.label}-${pkgs.stdenv.system}.ova";
|
||||||
|
description = ''
|
||||||
|
The file name of the VirtualBox appliance.
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
system.build.virtualBoxOVA = import ../../lib/make-disk-image.nix {
|
system.build.virtualBoxOVA = import ../../lib/make-disk-image.nix {
|
||||||
name = "nixos-ova-${config.system.nixos.label}-${pkgs.stdenv.system}";
|
name = cfg.vmDerivationName;
|
||||||
|
|
||||||
inherit pkgs lib config;
|
inherit pkgs lib config;
|
||||||
partitionTableType = "legacy";
|
partitionTableType = "legacy";
|
||||||
@ -37,11 +65,11 @@ in {
|
|||||||
VBoxManage internalcommands createrawvmdk -filename disk.vmdk -rawdisk $diskImage
|
VBoxManage internalcommands createrawvmdk -filename disk.vmdk -rawdisk $diskImage
|
||||||
|
|
||||||
echo "creating VirtualBox VM..."
|
echo "creating VirtualBox VM..."
|
||||||
vmName="NixOS ${config.system.nixos.label} (${pkgs.stdenv.system})"
|
vmName="${cfg.vmName}";
|
||||||
VBoxManage createvm --name "$vmName" --register \
|
VBoxManage createvm --name "$vmName" --register \
|
||||||
--ostype ${if pkgs.stdenv.system == "x86_64-linux" then "Linux26_64" else "Linux26"}
|
--ostype ${if pkgs.stdenv.system == "x86_64-linux" then "Linux26_64" else "Linux26"}
|
||||||
VBoxManage modifyvm "$vmName" \
|
VBoxManage modifyvm "$vmName" \
|
||||||
--memory 1536 --acpi on --vram 32 \
|
--memory ${toString cfg.memorySize} --acpi on --vram 32 \
|
||||||
${optionalString (pkgs.stdenv.system == "i686-linux") "--pae on"} \
|
${optionalString (pkgs.stdenv.system == "i686-linux") "--pae on"} \
|
||||||
--nictype1 virtio --nic1 nat \
|
--nictype1 virtio --nic1 nat \
|
||||||
--audiocontroller ac97 --audio alsa \
|
--audiocontroller ac97 --audio alsa \
|
||||||
@ -53,7 +81,7 @@ in {
|
|||||||
|
|
||||||
echo "exporting VirtualBox VM..."
|
echo "exporting VirtualBox VM..."
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
fn="$out/nixos-${config.system.nixos.label}-${pkgs.stdenv.system}.ova"
|
fn="$out/${cfg.vmFileName}"
|
||||||
VBoxManage export "$vmName" --output "$fn"
|
VBoxManage export "$vmName" --output "$fn"
|
||||||
|
|
||||||
rm -v $diskImage
|
rm -v $diskImage
|
||||||
|
Loading…
x
Reference in New Issue
Block a user