nixos/virtualbox-image: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-28 21:19:13 +02:00 committed by Jörg Thalheim
parent 217557441c
commit 7d7e294262

View File

@ -1,7 +1,4 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.virtualbox;
@ -10,51 +7,51 @@ in {
options = {
virtualbox = {
baseImageSize = mkOption {
type = with types; either (enum [ "auto" ]) int;
baseImageSize = lib.mkOption {
type = with lib.types; either (enum [ "auto" ]) int;
default = "auto";
example = 50 * 1024;
description = ''
The size of the VirtualBox base image in MiB.
'';
};
baseImageFreeSpace = mkOption {
type = with types; int;
baseImageFreeSpace = lib.mkOption {
type = with lib.types; int;
default = 30 * 1024;
description = ''
Free space in the VirtualBox base image in MiB.
'';
};
memorySize = mkOption {
type = types.int;
memorySize = lib.mkOption {
type = lib.types.int;
default = 1536;
description = ''
The amount of RAM the VirtualBox appliance can use in MiB.
'';
};
vmDerivationName = mkOption {
type = types.str;
vmDerivationName = lib.mkOption {
type = lib.types.str;
default = "nixos-ova-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}";
description = ''
The name of the derivation for the VirtualBox appliance.
'';
};
vmName = mkOption {
type = types.str;
vmName = lib.mkOption {
type = lib.types.str;
default = "${config.system.nixos.distroName} ${config.system.nixos.label} (${pkgs.stdenv.hostPlatform.system})";
description = ''
The name of the VirtualBox appliance.
'';
};
vmFileName = mkOption {
type = types.str;
vmFileName = lib.mkOption {
type = lib.types.str;
default = "nixos-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}.ova";
description = ''
The file name of the VirtualBox appliance.
'';
};
params = mkOption {
type = with types; attrsOf (oneOf [ str int bool (listOf str) ]);
params = lib.mkOption {
type = with lib.types; attrsOf (oneOf [ str int bool (listOf str) ]);
example = {
audio = "alsa";
rtcuseutc = "on";
@ -66,8 +63,8 @@ in {
Run `VBoxManage modifyvm --help` to see more options.
'';
};
exportParams = mkOption {
type = with types; listOf (oneOf [ str int bool (listOf str) ]);
exportParams = lib.mkOption {
type = with lib.types; listOf (oneOf [ str int bool (listOf str) ]);
example = [
"--vsys" "0" "--vendor" "ACME Inc."
];
@ -78,7 +75,7 @@ in {
Run `VBoxManage export --help` to see more options.
'';
};
extraDisk = mkOption {
extraDisk = lib.mkOption {
description = ''
Optional extra disk/hdd configuration.
The disk will be an 'ext4' partition on a separate file.
@ -89,26 +86,26 @@ in {
mountPoint = "/home/demo/storage";
size = 100 * 1024;
};
type = types.nullOr (types.submodule {
type = lib.types.nullOr (lib.types.submodule {
options = {
size = mkOption {
type = types.int;
size = lib.mkOption {
type = lib.types.int;
description = "Size in MiB";
};
label = mkOption {
type = types.str;
label = lib.mkOption {
type = lib.types.str;
default = "vm-extra-storage";
description = "Label for the disk partition";
};
mountPoint = mkOption {
type = types.str;
mountPoint = lib.mkOption {
type = lib.types.str;
description = "Path where to mount this disk.";
};
};
});
};
postExportCommands = mkOption {
type = types.lines;
postExportCommands = lib.mkOption {
type = lib.types.lines;
default = "";
example = ''
${pkgs.cot}/bin/cot edit-hardware "$fn" \
@ -124,8 +121,8 @@ in {
Extra commands to run after exporting the OVA to `$fn`.
'';
};
storageController = mkOption {
type = with types; attrsOf (oneOf [ str int bool (listOf str) ]);
storageController = lib.mkOption {
type = with lib.types; attrsOf (oneOf [ str int bool (listOf str) ]);
example = {
name = "SCSI";
add = "scsi";
@ -152,8 +149,8 @@ in {
config = {
virtualbox.params = mkMerge [
(mapAttrs (name: mkDefault) {
virtualbox.params = lib.mkMerge [
(lib.mapAttrs (name: lib.mkDefault) {
acpi = "on";
vram = 32;
nictype1 = "virtio";
@ -167,7 +164,7 @@ in {
usbehci = "on";
mouse = "usbtablet";
})
(mkIf (pkgs.stdenv.hostPlatform.system == "i686-linux") { pae = "on"; })
(lib.mkIf (pkgs.stdenv.hostPlatform.system == "i686-linux") { pae = "on"; })
];
system.build.virtualBoxOVA = import ../../lib/make-disk-image.nix {
@ -186,7 +183,7 @@ in {
echo "converting image to VirtualBox format..."
VBoxManage convertfromraw $diskImage disk.vdi
${optionalString (cfg.extraDisk != null) ''
${lib.optionalString (cfg.extraDisk != null) ''
echo "creating extra disk: data-disk.raw"
dataDiskImage=data-disk.raw
truncate -s ${toString cfg.extraDisk.size}M $dataDiskImage
@ -210,7 +207,7 @@ in {
VBoxManage storagectl "$vmName" ${lib.cli.toGNUCommandLineShell { } cfg.storageController}
VBoxManage storageattach "$vmName" --storagectl ${cfg.storageController.name} --port 0 --device 0 --type hdd \
--medium disk.vdi
${optionalString (cfg.extraDisk != null) ''
${lib.optionalString (cfg.extraDisk != null) ''
VBoxManage storageattach "$vmName" --storagectl ${cfg.storageController.name} --port 1 --device 0 --type hdd \
--medium data-disk.vdi
''}
@ -218,7 +215,7 @@ in {
echo "exporting VirtualBox VM..."
mkdir -p $out
fn="$out/${cfg.vmFileName}"
VBoxManage export "$vmName" --output "$fn" --options manifest ${escapeShellArgs cfg.exportParams}
VBoxManage export "$vmName" --output "$fn" --options manifest ${lib.escapeShellArgs cfg.exportParams}
${cfg.postExportCommands}
rm -v $diskImage