summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorThomas Strobel <ts468@cam.ac.uk>2015-01-29 09:58:28 +0100
committerThomas Strobel <ts468@cam.ac.uk>2015-02-25 23:30:44 +0100
commit3d4fbb874cbc3d5d179e9fab0f7099e95b34d960 (patch)
treee6c082d788372f2539176a52ba3c191f35cdc384 /nixos
parent7cc7e9b64a3b4e23fd8d23e84d87cdb787155de7 (diff)
downloadnixpkgs-3d4fbb874cbc3d5d179e9fab0f7099e95b34d960.tar
nixpkgs-3d4fbb874cbc3d5d179e9fab0f7099e95b34d960.tar.gz
nixpkgs-3d4fbb874cbc3d5d179e9fab0f7099e95b34d960.tar.bz2
nixpkgs-3d4fbb874cbc3d5d179e9fab0f7099e95b34d960.tar.lz
nixpkgs-3d4fbb874cbc3d5d179e9fab0f7099e95b34d960.tar.xz
nixpkgs-3d4fbb874cbc3d5d179e9fab0f7099e95b34d960.tar.zst
nixpkgs-3d4fbb874cbc3d5d179e9fab0f7099e95b34d960.zip
Update: add new Xen versions + update NixOS Xen modules
Versions of XEN:
- Xen 4.5
- Xen 4.5 + XenServer patches
- Xen 4.4.1
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/module-list.nix2
-rw-r--r--nixos/modules/virtualisation/xen-dom0.nix259
-rw-r--r--nixos/modules/virtualisation/xen-domU.nix5
3 files changed, 190 insertions, 76 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index c41ae69c1ac..a19f49387ab 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -432,5 +432,5 @@
   ./virtualisation/openvswitch.nix
   ./virtualisation/parallels-guest.nix
   ./virtualisation/virtualbox-guest.nix
-  #./virtualisation/xen-dom0.nix
+  ./virtualisation/xen-dom0.nix
 ]
diff --git a/nixos/modules/virtualisation/xen-dom0.nix b/nixos/modules/virtualisation/xen-dom0.nix
index f3a24c5cf25..157da76d752 100644
--- a/nixos/modules/virtualisation/xen-dom0.nix
+++ b/nixos/modules/virtualisation/xen-dom0.nix
@@ -5,18 +5,8 @@
 with lib;
 
 let
-
   cfg = config.virtualisation.xen;
-
   xen = pkgs.xen;
-
-  xendConfig = pkgs.writeText "xend-config.sxp"
-    ''
-      (loglevel DEBUG)
-      (network-script network-bridge)
-      (vif-script vif-bridge)
-    '';
-
 in
 
 {
@@ -58,23 +48,60 @@ in
           '';
       };
 
+    virtualisation.xen.bridge =
+      mkOption {
+        default = "xenbr0";
+        description =
+          ''
+            Create a bridge for the Xen domUs to connect to.
+          '';
+      };
+
+    virtualisation.xen.stored =
+      mkOption {
+        default = "${pkgs.xen}/bin/oxenstored";
+        description =
+          ''
+            Xen Store daemon to use.
+          '';
+      };
+
+    virtualisation.xen.trace =
+      mkOption {
+        default = false;
+        description =
+          ''
+            Enable Xen tracing.
+          '';
+      };
   };
 
 
   ###### implementation
 
   config = mkIf cfg.enable {
+    assertions = [ {
+      assertion = pkgs.stdenv.isx86_64;
+      message = "Xen currently not supported on ${pkgs.stdenv.system}";
+    } {
+      assertion = config.boot.loader.grub.enable && (config.boot.loader.grub.efiSupport == false);
+      message = "Xen currently does not support EFI boot";
+    } ];
 
     environment.systemPackages = [ xen ];
 
-    # Domain 0 requires a pvops-enabled kernel.
-    boot.kernelPackages = pkgs.linuxPackages_3_2_xen;
+    # Make sure Domain 0 gets the required configuration
+    #boot.kernelPackages = pkgs.boot.kernelPackages.override { features={xen_dom0=true;}; };
 
     boot.kernelModules =
-      [ "xen_evtchn" "xen_gntdev" "xen_blkback" "xen_netback" "xen_pciback"
-        "blktap" "tun"
+      [ "xen-evtchn" "xen-gntdev" "xen-gntalloc" "xen-blkback" "xen-netback"
+        "xen-pciback" "evtchn" "gntdev" "netbk" "blkbk" "xen-scsibk"
+        "usbbk" "pciback" "xen-acpi-processor" "blktap2" "tun" "netxen_nic"
+        "xen_wdt" "xen-acpi-processor" "xen-privcmd" "xen-scsiback"
+        "xenfs"
       ];
 
+
     # The radeonfb kernel module causes the screen to go black as soon
     # as it's loaded, so don't load it.
     boot.blacklistedKernelModules = [ "radeonfb" ];
@@ -87,8 +114,8 @@ in
         options loop max_loop=64
       '';
 
-    virtualisation.xen.bootParams =
-      [ "loglvl=all" "guest_loglvl=all" ] ++
+    virtualisation.xen.bootParams = [] ++
+      optionals cfg.trace [ "loglvl=all" "guest_loglvl=all" ] ++
       optional (cfg.domain0MemorySize != 0) "dom0_mem=${toString cfg.domain0MemorySize}M";
 
     system.extraSystemBuilderCmds =
@@ -101,71 +128,36 @@ in
     system.activationScripts.xen =
       ''
         if [ -d /proc/xen ]; then
-            ${pkgs.sysvtools}/bin/mountpoint -q /proc/xen || \
+            ${pkgs.kmod}/bin/modprobe xenfs 2> /dev/null
+            ${pkgs.utillinux}/bin/mountpoint -q /proc/xen || \
                 ${pkgs.utillinux}/bin/mount -t xenfs none /proc/xen
         fi
       '';
 
-    jobs.xend =
-      { description = "Xen Control Daemon";
-
-        startOn = "stopped udevtrigger";
-
-        path =
-          [ pkgs.bridge-utils pkgs.gawk pkgs.iproute pkgs.nettools
-            pkgs.utillinux pkgs.bash xen pkgs.pciutils pkgs.procps
-          ];
-
-        environment.XENCONSOLED_TRACE = "hv";
-
-        preStart =
-          ''
-            mkdir -p /var/log/xen/console -m 0700
-
-            ${xen}/sbin/xend start
-
-            # 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
-          '';
-
-        postStop = "${xen}/sbin/xend stop";
-      };
-
-    jobs.xendomains =
-      { description = "Automatically starts, saves and restores Xen domains on startup/shutdown";
-
-        startOn = "started xend";
-
-        stopOn = "starting shutdown and stopping xend";
-
-        restartIfChanged = false;
-        
-        path = [ pkgs.xen ];
-
-        environment.XENDOM_CONFIG = "${xen}/etc/sysconfig/xendomains";
-
-        preStart =
-          ''
-            mkdir -p /var/lock/subsys -m 755
-            ${xen}/etc/init.d/xendomains start
-          '';
-
-        postStop = "${xen}/etc/init.d/xendomains stop";
-      };
+    # Domain 0 requires a pvops-enabled kernel.
+    system.requiredKernelConfig = with config.lib.kernelConfig;
+      [ (isYes "XEN")
+        (isYes "X86_IO_APIC")
+        (isYes "ACPI")
+        (isYes "XEN_DOM0")
+        (isYes "PCI_XEN")
+        (isYes "XEN_DEV_EVTCHN")
+        (isYes "XENFS")
+        (isYes "XEN_COMPAT_XENFS")
+        (isYes "XEN_SYS_HYPERVISOR")
+        (isYes "XEN_GNTDEV")
+        (isYes "XEN_BACKEND")
+        (isModule "XEN_NETDEV_BACKEND")
+        (isModule "XEN_BLKDEV_BACKEND")
+        (isModule "XEN_PCIDEV_BACKEND")
+        (isYes "XEN_BALLOON")
+        (isYes "XEN_SCRUB_PAGES")
+      ];
 
-    # 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";
 
     environment.etc =
-      [ { source = xendConfig;
-          target = "xen/xend-config.sxp";
-        }
-        { source = "${xen}/etc/xen/scripts";
-          target = "xen/scripts";
+      [ { source = "${xen}/etc/xen/xl.conf";
+          target = "xen/xl.conf";
         }
       ];
 
@@ -174,6 +166,125 @@ in
 
     services.udev.path = [ pkgs.bridge-utils pkgs.iproute ];
 
+    systemd.services.xen-store = {
+      description = "Xen Store Daemon";
+      wantedBy = [ "multi-user.target" ];
+      after = [ "network.target" "xen-store.socket" ];
+      requires = [ "xen-store.socket" ];
+      preStart = ''
+        export XENSTORED_ROOTDIR="/var/lib/xenstored"
+        rm -f "$XENSTORED_ROOTDIR"/tdb* &>/dev/null
+
+        mkdir -p /var/run
+        ${optionalString cfg.trace "mkdir -p /var/log/xen"}
+        grep -q control_d /proc/xen/capabilities
+        '';
+      serviceConfig.ExecStart = ''
+        ${cfg.stored}${optionalString cfg.trace " -T /var/log/xen/xenstored-trace.log"} --no-fork
+        '';
+      postStart = ''
+        time=0
+        timeout=30
+        # Wait for xenstored to actually come up, timing out after 30 seconds
+        while [ $time -lt $timeout ] && ! `${pkgs.xen}/bin/xenstore-read -s / >/dev/null 2>&1` ; do
+            time=$(($time+1))
+            sleep 1
+        done
+
+        # Exit if we timed out
+        if ! [ $time -lt $timeout ] ; then
+            echo "Could not start Xenstore Daemon"
+            exit 1
+        fi
+
+        ${pkgs.xen}/bin/xenstore-write "/local/domain/0/name" "Domain-0"
+        ${pkgs.xen}/bin/xenstore-write "/local/domain/0/domid" 0
+        '';
+    };
+
+    systemd.sockets.xen-store = {
+      description = "XenStore Socket for userspace API";
+      wantedBy = [ "sockets.target" ];
+      socketConfig = {
+        ListenStream = [ "/var/run/xenstored/socket" "/var/run/xenstored/socket_ro" ];
+        SocketMode = "0660";
+        SocketUser = "root";
+        SocketGroup = "root";
+      };
+    };
+
+
+    systemd.services.xen-console = {
+      description = "Xen Console Daemon";
+      wantedBy = [ "multi-user.target" ];
+      after = [ "xen-store.service" ];
+      preStart = ''
+        mkdir -p /var/run/xen
+        ${optionalString cfg.trace "mkdir -p /var/log/xen"}
+        grep -q control_d /proc/xen/capabilities
+        '';
+      serviceConfig = {
+        ExecStart = ''
+          ${pkgs.xen}/bin/xenconsoled${optionalString cfg.trace " --log=all --log-dir=/var/log/xen"}
+          '';
+      };
+    };
+
+
+    systemd.services.xen-qemu = {
+      description = "Xen Qemu Daemon";
+      wantedBy = [ "multi-user.target" ];
+      after = [ "xen-console.service" ];
+      serviceConfig.ExecStart = ''
+        ${pkgs.xen}/lib/xen/bin/qemu-system-i386 -xen-domid 0 -xen-attach -name dom0 -nographic -M xenpv \
+           -monitor /dev/null -serial /dev/null -parallel /dev/null
+        '';
+    };
+
+
+    systemd.services.xen-watchdog = {
+      description = "Xen Watchdog Daemon";
+      wantedBy = [ "multi-user.target" ];
+      after = [ "xen-qemu.service" ];
+      serviceConfig.ExecStart = "${pkgs.xen}/bin/xenwatchdogd 30 15";
+      serviceConfig.Type = "forking";
+      serviceConfig.RestartSec = "1";
+      serviceConfig.Restart = "on-failure";
+    };
+
+
+    systemd.services.xen-bridge = {
+      description = "Xen bridge";
+      wantedBy = [ "multi-user.target" ];
+      before = [ "xen-domains.service" ];
+      serviceConfig.RemainAfterExit = "yes";
+      serviceConfig.ExecStart = ''
+        ${pkgs.bridge-utils}/bin/brctl addbr ${cfg.bridge}
+        ${pkgs.inetutils}/bin/ifconfig ${cfg.bridge} up
+        '';
+      serviceConfig.ExecStop = ''
+        ${pkgs.inetutils}/bin/ifconfig ${cfg.bridge} down
+        ${pkgs.bridge-utils}/bin/brctl delbr ${cfg.bridge}
+        '';
+    };
+
+    systemd.services.xen-domains = {
+      description = "Xen domains - automatically starts, saves and restores Xen domains";
+      wantedBy = [ "multi-user.target" ];
+      after = [ "xen-bridge.service" "xen-qemu.service" ];
+      ## 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.
+      before = [ "dhcpd.service" ];
+      restartIfChanged = false;
+      serviceConfig.RemainAfterExit = "yes";
+      path = [ pkgs.xen ];
+      environment.XENDOM_CONFIG = "${pkgs.xen}/etc/sysconfig/xendomains";
+      preStart = "mkdir -p /var/lock/subsys -m 755";
+      serviceConfig.ExecStart = "${pkgs.xen}/etc/init.d/xendomains start";
+      serviceConfig.ExecStop = "${pkgs.xen}/etc/init.d/xendomains stop";
+    };
+
   };
 
 }
diff --git a/nixos/modules/virtualisation/xen-domU.nix b/nixos/modules/virtualisation/xen-domU.nix
index 48358966934..2db3190ad13 100644
--- a/nixos/modules/virtualisation/xen-domU.nix
+++ b/nixos/modules/virtualisation/xen-domU.nix
@@ -9,7 +9,10 @@
   boot.loader.grub.device = "nodev";
   boot.loader.grub.extraPerEntryConfig = "root (hd0)";
 
-  boot.initrd.kernelModules = [ "xen-blkfront" ];
+  boot.initrd.kernelModules =
+    [ "xen-blkfront" "xen-tpmfront" "xen-kbdfront" "xen-fbfront"
+      "xen-netfront" "xen-pcifront" "xen-scsifront"
+    ];
 
   # Send syslog messages to the Xen console.
   services.syslogd.tty = "hvc0";