diff options
Diffstat (limited to 'nixos/modules/virtualisation')
-rw-r--r-- | nixos/modules/virtualisation/amazon-grow-partition.nix | 24 | ||||
-rw-r--r-- | nixos/modules/virtualisation/amazon-image.nix | 4 | ||||
-rw-r--r-- | nixos/modules/virtualisation/brightbox-image.nix | 2 | ||||
-rw-r--r-- | nixos/modules/virtualisation/containers.nix | 29 | ||||
-rw-r--r-- | nixos/modules/virtualisation/grow-partition.nix | 43 | ||||
-rw-r--r-- | nixos/modules/virtualisation/qemu-opts | 4 | ||||
-rw-r--r-- | nixos/modules/virtualisation/virtualbox-host.nix | 11 | ||||
-rw-r--r-- | nixos/modules/virtualisation/virtualbox-image.nix | 28 |
8 files changed, 88 insertions, 57 deletions
diff --git a/nixos/modules/virtualisation/amazon-grow-partition.nix b/nixos/modules/virtualisation/amazon-grow-partition.nix deleted file mode 100644 index 69b80d900bad..000000000000 --- a/nixos/modules/virtualisation/amazon-grow-partition.nix +++ /dev/null @@ -1,24 +0,0 @@ -# This module automatically grows the root partition on Amazon EC2 HVM -# instances. This allows an instance to be created with a bigger root -# filesystem than provided by the AMI. - -{ config, lib, pkgs, ... }: - -{ - config = lib.mkIf config.ec2.hvm { - boot.initrd.extraUtilsCommands = '' - copy_bin_and_libs ${pkgs.gawk}/bin/gawk - copy_bin_and_libs ${pkgs.gnused}/bin/sed - copy_bin_and_libs ${pkgs.utillinux}/sbin/sfdisk - cp -v ${pkgs.cloud-utils}/bin/growpart $out/bin/growpart - ln -s sed $out/bin/gnused - ''; - - boot.initrd.postDeviceCommands = '' - if [ -e /dev/xvda ] && [ -e /dev/xvda1 ]; then - TMPDIR=/run sh $(type -P growpart) /dev/xvda 1 - udevadm settle - fi - ''; - }; -} diff --git a/nixos/modules/virtualisation/amazon-image.nix b/nixos/modules/virtualisation/amazon-image.nix index ebf398fa266f..f9c3f2e53adc 100644 --- a/nixos/modules/virtualisation/amazon-image.nix +++ b/nixos/modules/virtualisation/amazon-image.nix @@ -11,10 +11,12 @@ with lib; let cfg = config.ec2; in { - imports = [ ../profiles/headless.nix ./ec2-data.nix ./amazon-grow-partition.nix ./amazon-init.nix ]; + imports = [ ../profiles/headless.nix ./ec2-data.nix ./grow-partition.nix ./amazon-init.nix ]; config = { + virtualisation.growPartition = cfg.hvm; + fileSystems."/" = { device = "/dev/disk/by-label/nixos"; autoResize = true; diff --git a/nixos/modules/virtualisation/brightbox-image.nix b/nixos/modules/virtualisation/brightbox-image.nix index 760a7100c6e0..ab49d8871f85 100644 --- a/nixos/modules/virtualisation/brightbox-image.nix +++ b/nixos/modules/virtualisation/brightbox-image.nix @@ -20,7 +20,7 @@ in postVM = '' - PATH=$PATH:${stdenv.lib.makeBinPath [ pkgs.gnutar pkgs.gzip ]} + PATH=$PATH:${lib.makeBinPath [ pkgs.gnutar pkgs.gzip ]} pushd $out ${pkgs.qemu_kvm}/bin/qemu-img convert -c -O qcow2 $diskImageBase nixos.qcow2 rm $diskImageBase diff --git a/nixos/modules/virtualisation/containers.nix b/nixos/modules/virtualisation/containers.nix index d83841452f95..413aa94339f1 100644 --- a/nixos/modules/virtualisation/containers.nix +++ b/nixos/modules/virtualisation/containers.nix @@ -340,6 +340,20 @@ in A specification of the desired configuration of this container, as a NixOS module. ''; + type = lib.mkOptionType { + name = "Toplevel NixOS config"; + merge = loc: defs: (import ../../lib/eval-config.nix { + inherit system; + modules = + let extraConfig = + { boot.isContainer = true; + networking.hostName = mkDefault name; + networking.useDHCP = false; + }; + in [ extraConfig ] ++ (map (x: x.value) defs); + prefix = [ "containers" name ]; + }).config; + }; }; path = mkOption { @@ -410,18 +424,9 @@ in } // networkOptions; config = mkMerge - [ (mkIf options.config.isDefined { - path = (import ../../lib/eval-config.nix { - inherit system; - modules = - let extraConfig = - { boot.isContainer = true; - networking.hostName = mkDefault name; - networking.useDHCP = false; - }; - in [ extraConfig config.config ]; - prefix = [ "containers" name ]; - }).config.system.build.toplevel; + [ + (mkIf options.config.isDefined { + path = config.config.system.build.toplevel; }) ]; })); diff --git a/nixos/modules/virtualisation/grow-partition.nix b/nixos/modules/virtualisation/grow-partition.nix new file mode 100644 index 000000000000..abc2e766959e --- /dev/null +++ b/nixos/modules/virtualisation/grow-partition.nix @@ -0,0 +1,43 @@ +# This module automatically grows the root partition on virtual machines. +# This allows an instance to be created with a bigger root filesystem +# than provided by the machine image. + +{ config, lib, pkgs, ... }: + +with lib; + +{ + + options = { + + virtualisation.growPartition = mkOption { + type = types.bool; + default = true; + }; + + }; + + config = mkIf config.virtualisation.growPartition { + + boot.initrd.extraUtilsCommands = '' + copy_bin_and_libs ${pkgs.gawk}/bin/gawk + copy_bin_and_libs ${pkgs.gnused}/bin/sed + copy_bin_and_libs ${pkgs.utillinux}/sbin/sfdisk + copy_bin_and_libs ${pkgs.utillinux}/sbin/lsblk + cp -v ${pkgs.cloud-utils}/bin/growpart $out/bin/growpart + ln -s sed $out/bin/gnused + ''; + + boot.initrd.postDeviceCommands = '' + rootDevice="${config.fileSystems."/".device}" + if [ -e "$rootDevice" ]; then + rootDevice="$(readlink -f "$rootDevice")" + parentDevice="$(lsblk -npo PKNAME "$rootDevice")" + TMPDIR=/run sh $(type -P growpart) "$parentDevice" "''${rootDevice#$parentDevice}" + udevadm settle + fi + ''; + + }; + +} diff --git a/nixos/modules/virtualisation/qemu-opts b/nixos/modules/virtualisation/qemu-opts deleted file mode 100644 index f06a5136608a..000000000000 --- a/nixos/modules/virtualisation/qemu-opts +++ /dev/null @@ -1,4 +0,0 @@ - -device virtio-serial \ - -chardev socket,id=charconsole0,path=/tmp/nixos-socket,server,nowait \ - #-device virtconsole,chardev=charconsole0,id=console0 \ - -device virtserialport,chardev=chardev=charconsole0,id=serial0 diff --git a/nixos/modules/virtualisation/virtualbox-host.nix b/nixos/modules/virtualisation/virtualbox-host.nix index 5fb472ebfc32..ce4abecd6762 100644 --- a/nixos/modules/virtualisation/virtualbox-host.nix +++ b/nixos/modules/virtualisation/virtualbox-host.nix @@ -5,7 +5,7 @@ with lib; let cfg = config.virtualisation.virtualbox.host; virtualbox = config.boot.kernelPackages.virtualbox.override { - inherit (cfg) enableHardening; + inherit (cfg) enableHardening headless; }; in @@ -47,6 +47,15 @@ in </para></important> ''; }; + + headless = mkOption { + type = types.bool; + default = false; + description = '' + Use VirtualBox installation without GUI and Qt dependency. Useful to enable on servers + and when virtual machines are controlled only via SSH. + ''; + }; }; config = mkIf cfg.enable (mkMerge [{ diff --git a/nixos/modules/virtualisation/virtualbox-image.nix b/nixos/modules/virtualisation/virtualbox-image.nix index fab59b2525a5..b6a5b3e4788d 100644 --- a/nixos/modules/virtualisation/virtualbox-image.nix +++ b/nixos/modules/virtualisation/virtualbox-image.nix @@ -8,6 +8,8 @@ let in { + imports = [ ./grow-partition.nix ]; + options = { virtualbox = { baseImageSize = mkOption { @@ -29,22 +31,15 @@ in { partitioned = true; diskSize = cfg.baseImageSize; - configFile = pkgs.writeText "configuration.nix" - '' - { - imports = [ <nixpkgs/nixos/modules/virtualisation/virtualbox-image.nix> ]; - } - ''; - postVM = '' - echo "creating VirtualBox disk image..." - ${pkgs.vmTools.qemu}/bin/qemu-img convert -f raw -O vdi $diskImage disk.vdi - rm $diskImage - - echo "creating VirtualBox VM..." export HOME=$PWD export PATH=${pkgs.linuxPackages.virtualbox}/bin:$PATH + + echo "creating VirtualBox pass-through disk wrapper (no copying invovled)..." + VBoxManage internalcommands createrawvmdk -filename disk.vmdk -rawdisk $diskImage + + echo "creating VirtualBox VM..." vmName="NixOS ${config.system.nixosLabel} (${pkgs.stdenv.system})" VBoxManage createvm --name "$vmName" --register \ --ostype ${if pkgs.stdenv.system == "x86_64-linux" then "Linux26_64" else "Linux26"} @@ -57,19 +52,24 @@ in { --usb on --mouse usbtablet VBoxManage storagectl "$vmName" --name SATA --add sata --portcount 4 --bootable on --hostiocache on VBoxManage storageattach "$vmName" --storagectl SATA --port 0 --device 0 --type hdd \ - --medium disk.vdi + --medium disk.vmdk echo "exporting VirtualBox VM..." mkdir -p $out fn="$out/nixos-${config.system.nixosLabel}-${pkgs.stdenv.system}.ova" VBoxManage export "$vmName" --output "$fn" + rm -v $diskImage + mkdir -p $out/nix-support echo "file ova $fn" >> $out/nix-support/hydra-build-products ''; }; - fileSystems."/".device = "/dev/disk/by-label/nixos"; + fileSystems."/" = { + device = "/dev/disk/by-label/nixos"; + autoResize = true; + }; boot.loader.grub.device = "/dev/sda"; |