2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2012-02-25 22:36:00 +01:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2012-02-25 22:36:00 +01:00
|
|
|
|
2014-08-04 11:29:51 +02:00
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.virtualbox;
|
|
|
|
|
|
|
|
in {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
virtualbox = {
|
|
|
|
baseImageSize = mkOption {
|
2015-09-28 14:31:19 +02:00
|
|
|
type = types.int;
|
2018-10-28 00:53:54 +02:00
|
|
|
default = 50 * 1024;
|
2014-08-04 11:29:51 +02:00
|
|
|
description = ''
|
2015-09-28 14:31:19 +02:00
|
|
|
The size of the VirtualBox base image in MiB.
|
2014-08-04 11:29:51 +02:00
|
|
|
'';
|
|
|
|
};
|
2018-07-11 19:45:10 +02:00
|
|
|
memorySize = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 1536;
|
|
|
|
description = ''
|
|
|
|
The amount of RAM the VirtualBox appliance can use in MiB.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
vmDerivationName = mkOption {
|
|
|
|
type = types.str;
|
2018-08-20 21:11:29 +02:00
|
|
|
default = "nixos-ova-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}";
|
2018-07-11 19:45:10 +02:00
|
|
|
description = ''
|
|
|
|
The name of the derivation for the VirtualBox appliance.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
vmName = mkOption {
|
|
|
|
type = types.str;
|
2018-08-20 21:11:29 +02:00
|
|
|
default = "NixOS ${config.system.nixos.label} (${pkgs.stdenv.hostPlatform.system})";
|
2018-07-11 19:45:10 +02:00
|
|
|
description = ''
|
|
|
|
The name of the VirtualBox appliance.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
vmFileName = mkOption {
|
|
|
|
type = types.str;
|
2018-08-20 21:11:29 +02:00
|
|
|
default = "nixos-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}.ova";
|
2018-07-11 19:45:10 +02:00
|
|
|
description = ''
|
|
|
|
The file name of the VirtualBox appliance.
|
|
|
|
'';
|
|
|
|
};
|
2014-08-04 11:29:51 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
2016-03-15 13:34:41 +01:00
|
|
|
system.build.virtualBoxOVA = import ../../lib/make-disk-image.nix {
|
2018-07-11 19:45:10 +02:00
|
|
|
name = cfg.vmDerivationName;
|
2016-03-15 13:34:41 +01:00
|
|
|
|
2015-09-28 14:31:19 +02:00
|
|
|
inherit pkgs lib config;
|
2017-12-07 01:00:21 +01:00
|
|
|
partitionTableType = "legacy";
|
2015-09-28 14:31:19 +02:00
|
|
|
diskSize = cfg.baseImageSize;
|
|
|
|
|
|
|
|
postVM =
|
|
|
|
''
|
2016-03-15 13:34:41 +01:00
|
|
|
export HOME=$PWD
|
2016-09-13 07:24:58 +02:00
|
|
|
export PATH=${pkgs.virtualbox}/bin:$PATH
|
2016-08-27 04:01:51 +02:00
|
|
|
|
2018-10-28 00:53:54 +02:00
|
|
|
echo "creating VirtualBox pass-through disk wrapper (no copying involved)..."
|
2016-08-27 04:01:51 +02:00
|
|
|
VBoxManage internalcommands createrawvmdk -filename disk.vmdk -rawdisk $diskImage
|
|
|
|
|
|
|
|
echo "creating VirtualBox VM..."
|
2018-07-11 19:45:10 +02:00
|
|
|
vmName="${cfg.vmName}";
|
2016-03-15 13:34:41 +01:00
|
|
|
VBoxManage createvm --name "$vmName" --register \
|
2018-08-20 21:11:29 +02:00
|
|
|
--ostype ${if pkgs.stdenv.hostPlatform.system == "x86_64-linux" then "Linux26_64" else "Linux26"}
|
2016-03-15 13:34:41 +01:00
|
|
|
VBoxManage modifyvm "$vmName" \
|
2018-07-11 19:45:10 +02:00
|
|
|
--memory ${toString cfg.memorySize} --acpi on --vram 32 \
|
2018-08-20 21:11:29 +02:00
|
|
|
${optionalString (pkgs.stdenv.hostPlatform.system == "i686-linux") "--pae on"} \
|
2016-03-15 13:34:41 +01:00
|
|
|
--nictype1 virtio --nic1 nat \
|
2018-10-28 00:53:54 +02:00
|
|
|
--audiocontroller ac97 --audio alsa --audioout on \
|
2016-03-15 13:34:41 +01:00
|
|
|
--rtcuseutc on \
|
2018-10-28 00:53:54 +02:00
|
|
|
--usb on --usbehci on --mouse usbtablet
|
2016-03-15 13:34:41 +01:00
|
|
|
VBoxManage storagectl "$vmName" --name SATA --add sata --portcount 4 --bootable on --hostiocache on
|
|
|
|
VBoxManage storageattach "$vmName" --storagectl SATA --port 0 --device 0 --type hdd \
|
2016-08-27 04:01:51 +02:00
|
|
|
--medium disk.vmdk
|
2016-03-15 13:34:41 +01:00
|
|
|
|
|
|
|
echo "exporting VirtualBox VM..."
|
|
|
|
mkdir -p $out
|
2018-07-11 19:45:10 +02:00
|
|
|
fn="$out/${cfg.vmFileName}"
|
2018-10-28 00:53:54 +02:00
|
|
|
VBoxManage export "$vmName" --output "$fn" --options manifest
|
2016-03-15 13:34:41 +01:00
|
|
|
|
2016-08-28 12:31:55 +02:00
|
|
|
rm -v $diskImage
|
|
|
|
|
2016-03-15 13:34:41 +01:00
|
|
|
mkdir -p $out/nix-support
|
|
|
|
echo "file ova $fn" >> $out/nix-support/hydra-build-products
|
2015-09-28 14:31:19 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-01-26 12:21:42 +01:00
|
|
|
fileSystems."/" = {
|
|
|
|
device = "/dev/disk/by-label/nixos";
|
|
|
|
autoResize = true;
|
2019-03-25 03:37:58 +01:00
|
|
|
fsType = "ext4";
|
2016-01-26 12:21:42 +01:00
|
|
|
};
|
2015-09-28 14:31:19 +02:00
|
|
|
|
2018-01-06 14:52:51 +01:00
|
|
|
boot.growPartition = true;
|
2014-08-04 11:29:51 +02:00
|
|
|
boot.loader.grub.device = "/dev/sda";
|
2015-09-28 14:31:19 +02:00
|
|
|
|
2019-04-21 05:03:22 +02:00
|
|
|
swapDevices = [{
|
2019-03-13 02:24:44 +01:00
|
|
|
device = "/var/swap";
|
|
|
|
size = 2048;
|
2019-04-21 05:03:22 +02:00
|
|
|
}];
|
2019-03-13 02:24:44 +01:00
|
|
|
|
2015-09-02 04:54:31 +02:00
|
|
|
virtualisation.virtualbox.guest.enable = true;
|
2015-09-28 14:31:19 +02:00
|
|
|
|
2014-08-04 11:29:51 +02:00
|
|
|
};
|
2012-02-25 22:36:00 +01:00
|
|
|
}
|