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