nixos/lib/qemu-flags: rename to qemu-common
The current name is misleading: it doesn't contain cli arguments, but several constants and utility functions related to qemu. This commit also removes the use of `with import ...` for clarity.
This commit is contained in:
@@ -4,15 +4,14 @@
|
|||||||
, # Ignored
|
, # Ignored
|
||||||
config ? null
|
config ? null
|
||||||
, # Nixpkgs, for qemu, lib and more
|
, # Nixpkgs, for qemu, lib and more
|
||||||
pkgs
|
pkgs, lib
|
||||||
, # !!! See comment about args in lib/modules.nix
|
, # !!! See comment about args in lib/modules.nix
|
||||||
specialArgs ? {}
|
specialArgs ? {}
|
||||||
, # NixOS configuration to add to the VMs
|
, # NixOS configuration to add to the VMs
|
||||||
extraConfigurations ? []
|
extraConfigurations ? []
|
||||||
}:
|
}:
|
||||||
|
|
||||||
with pkgs.lib;
|
with lib;
|
||||||
with import ../lib/qemu-flags.nix { inherit pkgs; };
|
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
|
|
||||||
@@ -93,8 +92,9 @@ rec {
|
|||||||
"${config.networking.hostName}\n"));
|
"${config.networking.hostName}\n"));
|
||||||
|
|
||||||
virtualisation.qemu.options =
|
virtualisation.qemu.options =
|
||||||
flip concatMap interfacesNumbered
|
let qemu-common = import ../lib/qemu-common.nix { inherit lib pkgs; };
|
||||||
({ fst, snd }: qemuNICFlags snd fst m.snd);
|
in flip concatMap interfacesNumbered
|
||||||
|
({ fst, snd }: qemu-common.qemuNICFlags snd fst m.snd);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
# QEMU flags shared between various Nix expressions.
|
# QEMU-related utilities shared between various Nix expressions.
|
||||||
{ pkgs }:
|
{ lib, pkgs }:
|
||||||
|
|
||||||
let
|
let
|
||||||
zeroPad = n:
|
zeroPad = n:
|
||||||
pkgs.lib.optionalString (n < 16) "0" +
|
lib.optionalString (n < 16) "0" +
|
||||||
(if n > 255
|
(if n > 255
|
||||||
then throw "Can't have more than 255 nets or nodes!"
|
then throw "Can't have more than 255 nets or nodes!"
|
||||||
else pkgs.lib.toHexString n);
|
else lib.toHexString n);
|
||||||
in
|
in
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
@@ -217,7 +217,7 @@ rec {
|
|||||||
nodes = qemu_pkg:
|
nodes = qemu_pkg:
|
||||||
let
|
let
|
||||||
build-vms = import ./build-vms.nix {
|
build-vms = import ./build-vms.nix {
|
||||||
inherit system pkgs minimal specialArgs;
|
inherit system lib pkgs minimal specialArgs;
|
||||||
extraConfigurations = extraConfigurations ++ [(
|
extraConfigurations = extraConfigurations ++ [(
|
||||||
{
|
{
|
||||||
virtualisation.qemu.package = qemu_pkg;
|
virtualisation.qemu.package = qemu_pkg;
|
||||||
@@ -257,7 +257,6 @@ rec {
|
|||||||
inherit test driver driverInteractive nodes;
|
inherit test driver driverInteractive nodes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
abortForFunction = functionName: abort ''The ${functionName} function was
|
abortForFunction = functionName: abort ''The ${functionName} function was
|
||||||
removed because it is not an essential part of the NixOS testing
|
removed because it is not an essential part of the NixOS testing
|
||||||
infrastructure. It had no usage in NixOS or Nixpkgs and it had no designated
|
infrastructure. It had no usage in NixOS or Nixpkgs and it had no designated
|
||||||
|
|||||||
@@ -4,7 +4,10 @@
|
|||||||
{ options, config, lib, pkgs, ... }:
|
{ options, config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
with import ../../lib/qemu-flags.nix { inherit pkgs; };
|
|
||||||
|
let
|
||||||
|
qemu-common = import ../../lib/qemu-common.nix { inherit lib pkgs; };
|
||||||
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -12,8 +15,8 @@ with import ../../lib/qemu-flags.nix { inherit pkgs; };
|
|||||||
|
|
||||||
systemd.services.backdoor =
|
systemd.services.backdoor =
|
||||||
{ wantedBy = [ "multi-user.target" ];
|
{ wantedBy = [ "multi-user.target" ];
|
||||||
requires = [ "dev-hvc0.device" "dev-${qemuSerialDevice}.device" ];
|
requires = [ "dev-hvc0.device" "dev-${qemu-common.qemuSerialDevice}.device" ];
|
||||||
after = [ "dev-hvc0.device" "dev-${qemuSerialDevice}.device" ];
|
after = [ "dev-hvc0.device" "dev-${qemu-common.qemuSerialDevice}.device" ];
|
||||||
script =
|
script =
|
||||||
''
|
''
|
||||||
export USER=root
|
export USER=root
|
||||||
@@ -30,7 +33,7 @@ with import ../../lib/qemu-flags.nix { inherit pkgs; };
|
|||||||
|
|
||||||
cd /tmp
|
cd /tmp
|
||||||
exec < /dev/hvc0 > /dev/hvc0
|
exec < /dev/hvc0 > /dev/hvc0
|
||||||
while ! exec 2> /dev/${qemuSerialDevice}; do sleep 0.1; done
|
while ! exec 2> /dev/${qemu-common.qemuSerialDevice}; do sleep 0.1; done
|
||||||
echo "connecting to host..." >&2
|
echo "connecting to host..." >&2
|
||||||
stty -F /dev/hvc0 raw -echo # prevent nl -> cr/nl conversion
|
stty -F /dev/hvc0 raw -echo # prevent nl -> cr/nl conversion
|
||||||
echo
|
echo
|
||||||
@@ -42,7 +45,7 @@ with import ../../lib/qemu-flags.nix { inherit pkgs; };
|
|||||||
# Prevent agetty from being instantiated on the serial device, since it
|
# Prevent agetty from being instantiated on the serial device, since it
|
||||||
# interferes with the backdoor (writes to it will randomly fail
|
# interferes with the backdoor (writes to it will randomly fail
|
||||||
# with EIO). Likewise for hvc0.
|
# with EIO). Likewise for hvc0.
|
||||||
systemd.services."serial-getty@${qemuSerialDevice}".enable = false;
|
systemd.services."serial-getty@${qemu-common.qemuSerialDevice}".enable = false;
|
||||||
systemd.services."serial-getty@hvc0".enable = false;
|
systemd.services."serial-getty@hvc0".enable = false;
|
||||||
|
|
||||||
# Only set these settings when the options exist. Some tests (e.g. those
|
# Only set these settings when the options exist. Some tests (e.g. those
|
||||||
@@ -57,7 +60,7 @@ with import ../../lib/qemu-flags.nix { inherit pkgs; };
|
|||||||
# we avoid defining consoles if not possible.
|
# we avoid defining consoles if not possible.
|
||||||
# TODO: refactor such that test-instrumentation can import qemu-vm
|
# TODO: refactor such that test-instrumentation can import qemu-vm
|
||||||
# or declare virtualisation.qemu.console option in a module that's always imported
|
# or declare virtualisation.qemu.console option in a module that's always imported
|
||||||
consoles = [ qemuSerialDevice ];
|
consoles = [ qemu-common.qemuSerialDevice ];
|
||||||
package = lib.mkDefault pkgs.qemu_test;
|
package = lib.mkDefault pkgs.qemu_test;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -88,7 +91,7 @@ with import ../../lib/qemu-flags.nix { inherit pkgs; };
|
|||||||
# Panic if an error occurs in stage 1 (rather than waiting for
|
# Panic if an error occurs in stage 1 (rather than waiting for
|
||||||
# user intervention).
|
# user intervention).
|
||||||
boot.kernelParams =
|
boot.kernelParams =
|
||||||
[ "console=${qemuSerialDevice}" "panic=1" "boot.panic_on_fail" ];
|
[ "console=${qemu-common.qemuSerialDevice}" "panic=1" "boot.panic_on_fail" ];
|
||||||
|
|
||||||
# `xwininfo' is used by the test driver to query open windows.
|
# `xwininfo' is used by the test driver to query open windows.
|
||||||
environment.systemPackages = [ pkgs.xorg.xwininfo ];
|
environment.systemPackages = [ pkgs.xorg.xwininfo ];
|
||||||
|
|||||||
@@ -10,10 +10,10 @@
|
|||||||
{ config, lib, pkgs, options, ... }:
|
{ config, lib, pkgs, options, ... }:
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
with import ../../lib/qemu-flags.nix { inherit pkgs; };
|
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
|
qemu-common = import ../../lib/qemu-common.nix { inherit lib pkgs; };
|
||||||
|
|
||||||
cfg = config.virtualisation;
|
cfg = config.virtualisation;
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ let
|
|||||||
'')}
|
'')}
|
||||||
|
|
||||||
# Start QEMU.
|
# Start QEMU.
|
||||||
exec ${qemuBinary qemu} \
|
exec ${qemu-common.qemuBinary qemu} \
|
||||||
-name ${config.system.name} \
|
-name ${config.system.name} \
|
||||||
-m ${toString config.virtualisation.memorySize} \
|
-m ${toString config.virtualisation.memorySize} \
|
||||||
-smp ${toString config.virtualisation.cores} \
|
-smp ${toString config.virtualisation.cores} \
|
||||||
@@ -549,7 +549,7 @@ in
|
|||||||
consoles = mkOption {
|
consoles = mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
default = let
|
default = let
|
||||||
consoles = [ "${qemu-flags.qemuSerialDevice},115200n8" "tty0" ];
|
consoles = [ "${qemu-common.qemuSerialDevice},115200n8" "tty0" ];
|
||||||
in if cfg.graphics then consoles else reverseList consoles;
|
in if cfg.graphics then consoles else reverseList consoles;
|
||||||
example = [ "console=tty1" ];
|
example = [ "console=tty1" ];
|
||||||
description = ''
|
description = ''
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ with import ../lib/testing-python.nix { inherit system pkgs; };
|
|||||||
with pkgs.lib;
|
with pkgs.lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
qemu-flags = import ../lib/qemu-flags.nix { inherit pkgs; };
|
qemu-common = import ../lib/qemu-common.nix { inherit (pkgs) lib pkgs; };
|
||||||
|
|
||||||
router = { config, pkgs, lib, ... }:
|
router = { config, pkgs, lib, ... }:
|
||||||
with pkgs.lib;
|
with pkgs.lib;
|
||||||
@@ -42,7 +42,7 @@ let
|
|||||||
machines = flip map vlanIfs (vlan:
|
machines = flip map vlanIfs (vlan:
|
||||||
{
|
{
|
||||||
hostName = "client${toString vlan}";
|
hostName = "client${toString vlan}";
|
||||||
ethernetAddress = qemu-flags.qemuNicMac vlan 1;
|
ethernetAddress = qemu-common.qemuNicMac vlan 1;
|
||||||
ipAddress = "192.168.${toString vlan}.2";
|
ipAddress = "192.168.${toString vlan}.2";
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
}:
|
}:
|
||||||
|
|
||||||
with pkgs;
|
with pkgs;
|
||||||
with import ../../../nixos/lib/qemu-flags.nix { inherit pkgs; };
|
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
|
qemu-common = import ../../../nixos/lib/qemu-common.nix { inherit lib pkgs; };
|
||||||
|
|
||||||
qemu = pkgs.qemu_kvm;
|
qemu = pkgs.qemu_kvm;
|
||||||
|
|
||||||
@@ -192,13 +192,13 @@ rec {
|
|||||||
export PATH=/bin:/usr/bin:${coreutils}/bin
|
export PATH=/bin:/usr/bin:${coreutils}/bin
|
||||||
echo "Starting interactive shell..."
|
echo "Starting interactive shell..."
|
||||||
echo "(To run the original builder: \$origBuilder \$origArgs)"
|
echo "(To run the original builder: \$origBuilder \$origArgs)"
|
||||||
exec ${busybox}/bin/setsid ${bashInteractive}/bin/bash < /dev/${qemuSerialDevice} &> /dev/${qemuSerialDevice}
|
exec ${busybox}/bin/setsid ${bashInteractive}/bin/bash < /dev/${qemu-common.qemuSerialDevice} &> /dev/${qemu-common.qemuSerialDevice}
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|
||||||
qemuCommandLinux = ''
|
qemuCommandLinux = ''
|
||||||
${qemuBinary qemu} \
|
${qemu-common.qemuBinary qemu} \
|
||||||
-nographic -no-reboot \
|
-nographic -no-reboot \
|
||||||
-device virtio-rng-pci \
|
-device virtio-rng-pci \
|
||||||
-virtfs local,path=${storeDir},security_model=none,mount_tag=store \
|
-virtfs local,path=${storeDir},security_model=none,mount_tag=store \
|
||||||
@@ -206,7 +206,7 @@ rec {
|
|||||||
''${diskImage:+-drive file=$diskImage,if=virtio,cache=unsafe,werror=report} \
|
''${diskImage:+-drive file=$diskImage,if=virtio,cache=unsafe,werror=report} \
|
||||||
-kernel ${kernel}/${img} \
|
-kernel ${kernel}/${img} \
|
||||||
-initrd ${initrd}/initrd \
|
-initrd ${initrd}/initrd \
|
||||||
-append "console=${qemuSerialDevice} panic=1 command=${stage2Init} out=$out mountDisk=$mountDisk loglevel=4" \
|
-append "console=${qemu-common.qemuSerialDevice} panic=1 command=${stage2Init} out=$out mountDisk=$mountDisk loglevel=4" \
|
||||||
$QEMU_OPTS
|
$QEMU_OPTS
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user