2010-10-05 19:44:40 +04:00
|
|
|
# Xen hypervisor (Dom0) support.
|
2010-09-13 02:43:45 +04:00
|
|
|
|
2014-04-14 18:26:48 +04:00
|
|
|
{ config, lib, pkgs, ... }:
|
2010-09-13 02:43:45 +04:00
|
|
|
|
2014-04-14 18:26:48 +04:00
|
|
|
with lib;
|
2010-09-13 02:43:45 +04:00
|
|
|
|
2011-09-14 22:20:50 +04:00
|
|
|
let
|
2010-09-16 19:24:46 +04:00
|
|
|
|
2011-09-14 22:20:50 +04:00
|
|
|
cfg = config.virtualisation.xen;
|
2010-09-16 19:24:46 +04:00
|
|
|
|
|
|
|
xen = pkgs.xen;
|
|
|
|
|
|
|
|
xendConfig = pkgs.writeText "xend-config.sxp"
|
|
|
|
''
|
|
|
|
(loglevel DEBUG)
|
|
|
|
(network-script network-bridge)
|
|
|
|
(vif-script vif-bridge)
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
2010-09-13 02:43:45 +04:00
|
|
|
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
2011-09-14 22:20:50 +04:00
|
|
|
virtualisation.xen.enable =
|
2010-09-13 02:43:45 +04:00
|
|
|
mkOption {
|
|
|
|
default = false;
|
|
|
|
description =
|
|
|
|
''
|
|
|
|
Setting this option enables the Xen hypervisor, a
|
|
|
|
virtualisation technology that allows multiple virtual
|
|
|
|
machines, known as <emphasis>domains</emphasis>, to run
|
|
|
|
concurrently on the physical machine. NixOS runs as the
|
|
|
|
privileged <emphasis>Domain 0</emphasis>. This option
|
|
|
|
requires a reboot to take effect.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2011-09-14 22:20:50 +04:00
|
|
|
virtualisation.xen.bootParams =
|
2010-09-13 02:43:45 +04:00
|
|
|
mkOption {
|
|
|
|
default = "";
|
|
|
|
description =
|
|
|
|
''
|
|
|
|
Parameters passed to the Xen hypervisor at boot time.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2011-09-14 22:20:50 +04:00
|
|
|
virtualisation.xen.domain0MemorySize =
|
2010-09-13 02:43:45 +04:00
|
|
|
mkOption {
|
|
|
|
default = 0;
|
|
|
|
example = 512;
|
|
|
|
description =
|
|
|
|
''
|
|
|
|
Amount of memory (in MiB) allocated to Domain 0 on boot.
|
|
|
|
If set to 0, all memory is assigned to Domain 0.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2010-09-16 19:24:46 +04:00
|
|
|
environment.systemPackages = [ xen ];
|
2010-09-13 02:43:45 +04:00
|
|
|
|
|
|
|
# Domain 0 requires a pvops-enabled kernel.
|
2013-01-30 11:43:37 +04:00
|
|
|
boot.kernelPackages = pkgs.linuxPackages_3_2_xen;
|
2010-09-13 02:43:45 +04:00
|
|
|
|
2011-09-14 22:20:50 +04:00
|
|
|
boot.kernelModules =
|
|
|
|
[ "xen_evtchn" "xen_gntdev" "xen_blkback" "xen_netback" "xen_pciback"
|
2010-10-11 21:06:49 +04:00
|
|
|
"blktap" "tun"
|
2010-09-27 20:32:42 +04:00
|
|
|
];
|
2010-09-14 15:22:50 +04:00
|
|
|
|
2010-09-13 02:43:45 +04:00
|
|
|
# The radeonfb kernel module causes the screen to go black as soon
|
|
|
|
# as it's loaded, so don't load it.
|
|
|
|
boot.blacklistedKernelModules = [ "radeonfb" ];
|
|
|
|
|
2010-12-06 12:54:08 +03:00
|
|
|
# Increase the number of loopback devices from the default (8),
|
|
|
|
# which is way too small because every VM virtual disk requires a
|
|
|
|
# loopback device.
|
|
|
|
boot.extraModprobeConfig =
|
|
|
|
''
|
|
|
|
options loop max_loop=64
|
|
|
|
'';
|
|
|
|
|
2011-09-14 22:20:50 +04:00
|
|
|
virtualisation.xen.bootParams =
|
2010-09-13 02:43:45 +04:00
|
|
|
[ "loglvl=all" "guest_loglvl=all" ] ++
|
|
|
|
optional (cfg.domain0MemorySize != 0) "dom0_mem=${toString cfg.domain0MemorySize}M";
|
|
|
|
|
|
|
|
system.extraSystemBuilderCmds =
|
|
|
|
''
|
2010-09-16 19:24:46 +04:00
|
|
|
ln -s ${xen}/boot/xen.gz $out/xen.gz
|
2010-09-13 02:43:45 +04:00
|
|
|
echo "${toString cfg.bootParams}" > $out/xen-params
|
|
|
|
'';
|
|
|
|
|
2010-09-13 02:56:54 +04:00
|
|
|
# Mount the /proc/xen pseudo-filesystem.
|
2010-09-13 19:41:38 +04:00
|
|
|
system.activationScripts.xen =
|
2010-09-13 02:56:54 +04:00
|
|
|
''
|
|
|
|
if [ -d /proc/xen ]; then
|
|
|
|
${pkgs.sysvtools}/bin/mountpoint -q /proc/xen || \
|
|
|
|
${pkgs.utillinux}/bin/mount -t xenfs none /proc/xen
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2010-09-14 15:22:50 +04:00
|
|
|
jobs.xend =
|
2013-11-09 23:06:01 +04:00
|
|
|
{ description = "Xen Control Daemon";
|
2010-09-14 15:22:50 +04:00
|
|
|
|
|
|
|
startOn = "stopped udevtrigger";
|
|
|
|
|
2011-09-14 22:20:50 +04:00
|
|
|
path =
|
|
|
|
[ pkgs.bridge_utils pkgs.gawk pkgs.iproute pkgs.nettools
|
2010-09-16 19:24:46 +04:00
|
|
|
pkgs.utillinux pkgs.bash xen pkgs.pciutils pkgs.procps
|
2010-09-14 15:22:50 +04:00
|
|
|
];
|
|
|
|
|
2011-02-10 15:27:12 +03:00
|
|
|
environment.XENCONSOLED_TRACE = "hv";
|
|
|
|
|
2011-09-14 22:20:50 +04:00
|
|
|
preStart =
|
2010-10-06 20:07:16 +04:00
|
|
|
''
|
2011-02-10 15:27:12 +03:00
|
|
|
mkdir -p /var/log/xen/console -m 0700
|
|
|
|
|
2010-10-06 20:07:16 +04:00
|
|
|
${xen}/sbin/xend start
|
2011-09-14 22:20:50 +04:00
|
|
|
|
2010-10-06 20:07:16 +04:00
|
|
|
# Wait until Xend is running.
|
|
|
|
for ((i = 0; i < 60; i++)); do echo "waiting for xend..."; ${xen}/sbin/xend status && break; done
|
|
|
|
|
|
|
|
${xen}/sbin/xend status || exit 1
|
|
|
|
'';
|
2010-09-14 15:22:50 +04:00
|
|
|
|
2010-09-16 19:24:46 +04:00
|
|
|
postStop = "${xen}/sbin/xend stop";
|
2010-09-14 15:22:50 +04:00
|
|
|
};
|
|
|
|
|
2010-10-06 20:07:16 +04:00
|
|
|
jobs.xendomains =
|
|
|
|
{ description = "Automatically starts, saves and restores Xen domains on startup/shutdown";
|
|
|
|
|
|
|
|
startOn = "started xend";
|
|
|
|
|
|
|
|
stopOn = "starting shutdown and stopping xend";
|
|
|
|
|
2012-03-18 06:10:39 +04:00
|
|
|
restartIfChanged = false;
|
|
|
|
|
2010-10-06 20:07:16 +04:00
|
|
|
path = [ pkgs.xen ];
|
|
|
|
|
|
|
|
environment.XENDOM_CONFIG = "${xen}/etc/sysconfig/xendomains";
|
|
|
|
|
2011-09-14 22:20:50 +04:00
|
|
|
preStart =
|
2010-10-06 20:07:16 +04:00
|
|
|
''
|
|
|
|
mkdir -p /var/lock/subsys -m 755
|
|
|
|
${xen}/etc/init.d/xendomains start
|
|
|
|
'';
|
|
|
|
|
|
|
|
postStop = "${xen}/etc/init.d/xendomains stop";
|
|
|
|
};
|
|
|
|
|
2012-03-22 17:02:42 +04:00
|
|
|
# To prevent a race between dhcpcd and xend's bridge setup script
|
|
|
|
# (which renames eth* to peth* and recreates eth* as a virtual
|
|
|
|
# device), start dhcpcd after xend.
|
|
|
|
jobs.dhcpcd.startOn = mkOverride 50 "started xend";
|
2010-09-14 15:58:06 +04:00
|
|
|
|
2010-09-16 19:24:46 +04:00
|
|
|
environment.etc =
|
|
|
|
[ { source = xendConfig;
|
|
|
|
target = "xen/xend-config.sxp";
|
|
|
|
}
|
|
|
|
{ source = "${xen}/etc/xen/scripts";
|
|
|
|
target = "xen/scripts";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
# Xen provides udev rules.
|
|
|
|
services.udev.packages = [ xen ];
|
|
|
|
|
|
|
|
services.udev.path = [ pkgs.bridge_utils pkgs.iproute ];
|
|
|
|
|
2010-09-13 02:43:45 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|