| 
									
										
										
										
											2010-10-05 15:44:40 +00:00
										 |  |  | # Xen hypervisor (Dom0) support. | 
					
						
							| 
									
										
										
										
											2010-09-12 22:43:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | { config, lib, pkgs, ... }: | 
					
						
							| 
									
										
										
										
											2010-09-12 22:43:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | with lib; | 
					
						
							| 
									
										
										
										
											2010-09-12 22:43:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | let | 
					
						
							|  |  |  |   cfg = config.virtualisation.xen; | 
					
						
							| 
									
										
										
										
											2010-09-16 15:24:46 +00:00
										 |  |  | in | 
					
						
							| 
									
										
										
										
											2010-09-12 22:43:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   ###### interface | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   options = { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  |     virtualisation.xen.enable = | 
					
						
							| 
									
										
										
										
											2010-09-12 22:43:45 +00: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. | 
					
						
							|  |  |  |           '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-03 17:46:57 +00:00
										 |  |  |     virtualisation.xen.package = mkOption { | 
					
						
							|  |  |  |       type = types.package; | 
					
						
							|  |  |  |       defaultText = "pkgs.xen"; | 
					
						
							|  |  |  |       example = literalExample "pkgs.xen-light"; | 
					
						
							|  |  |  |       description = ''
 | 
					
						
							|  |  |  |         The package used for Xen binary. | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtualisation.xen.qemu = mkOption { | 
					
						
							|  |  |  |       type = types.path; | 
					
						
							| 
									
										
										
										
											2017-03-11 00:09:22 +01:00
										 |  |  |       defaultText = "\${pkgs.xen}/lib/xen/bin/qemu-system-i386"; | 
					
						
							| 
									
										
										
										
											2017-03-03 17:46:57 +00:00
										 |  |  |       example = literalExample "''${pkgs.qemu_xen-light}/bin/qemu-system-i386"; | 
					
						
							|  |  |  |       description = ''
 | 
					
						
							|  |  |  |         The qemu binary to use for Dom-0 backend. | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtualisation.xen.qemu-package = mkOption { | 
					
						
							|  |  |  |       type = types.package; | 
					
						
							|  |  |  |       defaultText = "pkgs.xen"; | 
					
						
							|  |  |  |       example = literalExample "pkgs.qemu_xen-light"; | 
					
						
							|  |  |  |       description = ''
 | 
					
						
							|  |  |  |         The package with qemu binaries for xendomains. | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  |     virtualisation.xen.bootParams = | 
					
						
							| 
									
										
										
										
											2010-09-12 22:43:45 +00:00
										 |  |  |       mkOption { | 
					
						
							|  |  |  |         default = ""; | 
					
						
							|  |  |  |         description = | 
					
						
							|  |  |  |           ''
 | 
					
						
							|  |  |  |             Parameters passed to the Xen hypervisor at boot time. | 
					
						
							|  |  |  |           '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  |     virtualisation.xen.domain0MemorySize = | 
					
						
							| 
									
										
										
										
											2010-09-12 22:43:45 +00: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. | 
					
						
							|  |  |  |           '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-23 13:36:32 +02:00
										 |  |  |     virtualisation.xen.bridge = { | 
					
						
							|  |  |  |         name = mkOption { | 
					
						
							|  |  |  |           default = "xenbr0"; | 
					
						
							|  |  |  |           description = ''
 | 
					
						
							|  |  |  |               Name of bridge the Xen domUs connect to. | 
					
						
							|  |  |  |             '';
 | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         address = mkOption { | 
					
						
							|  |  |  |           type = types.str; | 
					
						
							|  |  |  |           default = "172.16.0.1"; | 
					
						
							|  |  |  |           description = ''
 | 
					
						
							|  |  |  |             IPv4 address of the bridge. | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |           '';
 | 
					
						
							| 
									
										
										
										
											2015-06-23 13:36:32 +02:00
										 |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         prefixLength = mkOption { | 
					
						
							|  |  |  |           type = types.addCheck types.int (n: n >= 0 && n <= 32); | 
					
						
							|  |  |  |           default = 16; | 
					
						
							|  |  |  |           description = ''
 | 
					
						
							|  |  |  |             Subnet mask of the bridge interface, specified as the number of | 
					
						
							|  |  |  |             bits in the prefix (<literal>24</literal>). | 
					
						
							|  |  |  |             A DHCP server will provide IP addresses for the whole, remaining | 
					
						
							|  |  |  |             subnet. | 
					
						
							|  |  |  |           '';
 | 
					
						
							|  |  |  |         }; | 
					
						
							| 
									
										
										
										
											2017-04-30 06:50:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         forwardDns = mkOption { | 
					
						
							|  |  |  |           default = false; | 
					
						
							|  |  |  |           description = ''
 | 
					
						
							|  |  |  |             If set to <literal>true</literal>, the DNS queries from the | 
					
						
							|  |  |  |             hosts connected to the bridge will be forwarded to the DNS | 
					
						
							|  |  |  |             servers specified in /etc/resolv.conf . | 
					
						
							|  |  |  |             '';
 | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtualisation.xen.stored = | 
					
						
							|  |  |  |       mkOption { | 
					
						
							| 
									
										
										
										
											2015-03-05 12:46:50 +01:00
										 |  |  |         type = types.path; | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |         description = | 
					
						
							|  |  |  |           ''
 | 
					
						
							| 
									
										
										
										
											2015-03-04 12:05:04 +01:00
										 |  |  |             Xen Store daemon to use. Defaults to oxenstored of the xen package. | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |           '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-04 08:31:40 +00:00
										 |  |  |     virtualisation.xen.domains = { | 
					
						
							|  |  |  |         extraConfig = mkOption { | 
					
						
							|  |  |  |           type = types.string; | 
					
						
							|  |  |  |           default = ""; | 
					
						
							|  |  |  |           description = | 
					
						
							|  |  |  |             ''
 | 
					
						
							|  |  |  |               Options defined here will override the defaults for xendomains. | 
					
						
							|  |  |  |               The default options can be seen in the file included from | 
					
						
							|  |  |  |               /etc/default/xendomains. | 
					
						
							|  |  |  |             '';
 | 
					
						
							|  |  |  |           }; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |     virtualisation.xen.trace = | 
					
						
							|  |  |  |       mkOption { | 
					
						
							|  |  |  |         default = false; | 
					
						
							|  |  |  |         description = | 
					
						
							|  |  |  |           ''
 | 
					
						
							|  |  |  |             Enable Xen tracing. | 
					
						
							|  |  |  |           '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2010-09-12 22:43:45 +00:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ###### implementation | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   config = mkIf cfg.enable { | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |     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"; | 
					
						
							|  |  |  |     } ]; | 
					
						
							| 
									
										
										
										
											2010-09-12 22:43:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-23 23:22:29 +00:00
										 |  |  |     virtualisation.xen.package = mkDefault pkgs.xen; | 
					
						
							|  |  |  |     virtualisation.xen.qemu = mkDefault "${pkgs.xen}/lib/xen/bin/qemu-system-i386"; | 
					
						
							|  |  |  |     virtualisation.xen.qemu-package = mkDefault pkgs.xen; | 
					
						
							| 
									
										
										
										
											2017-03-03 17:46:57 +00:00
										 |  |  |     virtualisation.xen.stored = mkDefault "${cfg.package}/bin/oxenstored"; | 
					
						
							| 
									
										
										
										
											2015-03-05 12:46:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-03 17:46:57 +00:00
										 |  |  |     environment.systemPackages = [ cfg.package ]; | 
					
						
							| 
									
										
										
										
											2010-09-12 22:43:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |     # Make sure Domain 0 gets the required configuration | 
					
						
							|  |  |  |     #boot.kernelPackages = pkgs.boot.kernelPackages.override { features={xen_dom0=true;}; }; | 
					
						
							| 
									
										
										
										
											2010-09-12 22:43:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  |     boot.kernelModules = | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |       [ "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" | 
					
						
							| 
									
										
										
										
											2010-09-27 16:32:42 +00:00
										 |  |  |       ]; | 
					
						
							| 
									
										
										
										
											2010-09-14 11:22:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-15 12:19:38 +02:00
										 |  |  |     # The xenfs module is needed in system.activationScripts.xen, but | 
					
						
							|  |  |  |     # the modprobe command there fails silently. Include xenfs in the | 
					
						
							|  |  |  |     # initrd as a work around. | 
					
						
							|  |  |  |     boot.initrd.kernelModules = [ "xenfs" ]; | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-12 22:43:45 +00: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 09:54:08 +00: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 | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |     virtualisation.xen.bootParams = [] ++ | 
					
						
							|  |  |  |       optionals cfg.trace [ "loglvl=all" "guest_loglvl=all" ] ++ | 
					
						
							| 
									
										
										
										
											2010-09-12 22:43:45 +00:00
										 |  |  |       optional (cfg.domain0MemorySize != 0) "dom0_mem=${toString cfg.domain0MemorySize}M"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     system.extraSystemBuilderCmds = | 
					
						
							|  |  |  |       ''
 | 
					
						
							| 
									
										
										
										
											2017-03-03 17:46:57 +00:00
										 |  |  |         ln -s ${cfg.package}/boot/xen.gz $out/xen.gz | 
					
						
							| 
									
										
										
										
											2010-09-12 22:43:45 +00:00
										 |  |  |         echo "${toString cfg.bootParams}" > $out/xen-params | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-12 22:56:54 +00:00
										 |  |  |     # Mount the /proc/xen pseudo-filesystem. | 
					
						
							| 
									
										
										
										
											2010-09-13 15:41:38 +00:00
										 |  |  |     system.activationScripts.xen = | 
					
						
							| 
									
										
										
										
											2010-09-12 22:56:54 +00:00
										 |  |  |       ''
 | 
					
						
							|  |  |  |         if [ -d /proc/xen ]; then | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |             ${pkgs.kmod}/bin/modprobe xenfs 2> /dev/null | 
					
						
							|  |  |  |             ${pkgs.utillinux}/bin/mountpoint -q /proc/xen || \ | 
					
						
							| 
									
										
										
										
											2010-09-12 22:56:54 +00:00
										 |  |  |                 ${pkgs.utillinux}/bin/mount -t xenfs none /proc/xen | 
					
						
							|  |  |  |         fi | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |     # 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") | 
					
						
							|  |  |  |       ]; | 
					
						
							| 
									
										
										
										
											2010-10-06 16:07:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-14 11:58:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-16 15:24:46 +00:00
										 |  |  |     environment.etc = | 
					
						
							| 
									
										
										
										
											2017-03-03 17:46:57 +00:00
										 |  |  |       [ { source = "${cfg.package}/etc/xen/xl.conf"; | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |           target = "xen/xl.conf"; | 
					
						
							| 
									
										
										
										
											2010-09-16 15:24:46 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-03-03 17:46:57 +00:00
										 |  |  |         { source = "${cfg.package}/etc/xen/scripts"; | 
					
						
							| 
									
										
										
										
											2015-06-08 19:56:37 +02:00
										 |  |  |           target = "xen/scripts"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-05-04 08:31:40 +00:00
										 |  |  |         { text = ''
 | 
					
						
							|  |  |  |             source ${cfg.package}/etc/default/xendomains | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             ${cfg.domains.extraConfig} | 
					
						
							|  |  |  |           '';
 | 
					
						
							| 
									
										
										
										
											2015-07-15 12:19:38 +02:00
										 |  |  |           target = "default/xendomains"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-09-16 15:24:46 +00:00
										 |  |  |       ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Xen provides udev rules. | 
					
						
							| 
									
										
										
										
											2017-03-03 17:46:57 +00:00
										 |  |  |     services.udev.packages = [ cfg.package ]; | 
					
						
							| 
									
										
										
										
											2010-09-16 15:24:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-20 21:43:09 +01:00
										 |  |  |     services.udev.path = [ pkgs.bridge-utils pkgs.iproute ]; | 
					
						
							| 
									
										
										
										
											2010-09-16 15:24:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |     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 | 
					
						
							| 
									
										
										
										
											2015-07-15 12:19:38 +02:00
										 |  |  |         mkdir -p /var/log/xen # Running xl requires /var/log/xen and /var/lib/xen, | 
					
						
							|  |  |  |         mkdir -p /var/lib/xen # so we create them here unconditionally. | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |         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 | 
					
						
							| 
									
										
										
										
											2017-03-03 17:46:57 +00:00
										 |  |  |         while [ $time -lt $timeout ] && ! `${cfg.package}/bin/xenstore-read -s / >/dev/null 2>&1` ; do | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |             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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-03 17:46:57 +00:00
										 |  |  |         ${cfg.package}/bin/xenstore-write "/local/domain/0/name" "Domain-0" | 
					
						
							|  |  |  |         ${cfg.package}/bin/xenstore-write "/local/domain/0/domid" 0 | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |         '';
 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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 = ''
 | 
					
						
							| 
									
										
										
										
											2017-03-03 17:46:57 +00:00
										 |  |  |           ${cfg.package}/bin/xenconsoled${optionalString cfg.trace " --log=all --log-dir=/var/log/xen"} | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |           '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     systemd.services.xen-qemu = { | 
					
						
							|  |  |  |       description = "Xen Qemu Daemon"; | 
					
						
							|  |  |  |       wantedBy = [ "multi-user.target" ]; | 
					
						
							|  |  |  |       after = [ "xen-console.service" ]; | 
					
						
							|  |  |  |       serviceConfig.ExecStart = ''
 | 
					
						
							| 
									
										
										
										
											2017-03-03 17:46:57 +00:00
										 |  |  |         ${cfg.qemu} -xen-attach -xen-domid 0 -name dom0 -M xenpv \ | 
					
						
							|  |  |  |            -nographic -monitor /dev/null -serial /dev/null -parallel /dev/null | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |         '';
 | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     systemd.services.xen-watchdog = { | 
					
						
							|  |  |  |       description = "Xen Watchdog Daemon"; | 
					
						
							|  |  |  |       wantedBy = [ "multi-user.target" ]; | 
					
						
							|  |  |  |       after = [ "xen-qemu.service" ]; | 
					
						
							| 
									
										
										
										
											2017-03-03 17:46:57 +00:00
										 |  |  |       serviceConfig.ExecStart = "${cfg.package}/bin/xenwatchdogd 30 15"; | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |       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" ]; | 
					
						
							| 
									
										
										
										
											2015-06-23 13:36:32 +02:00
										 |  |  |       preStart = ''
 | 
					
						
							|  |  |  |         mkdir -p /var/run/xen | 
					
						
							|  |  |  |         touch /var/run/xen/dnsmasq.pid | 
					
						
							|  |  |  |         touch /var/run/xen/dnsmasq.etherfile | 
					
						
							|  |  |  |         touch /var/run/xen/dnsmasq.leasefile | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         IFS='-' read -a data <<< `${pkgs.sipcalc}/bin/sipcalc ${cfg.bridge.address}/${toString cfg.bridge.prefixLength} | grep Usable\ range` | 
					
						
							|  |  |  |         export XEN_BRIDGE_IP_RANGE_START="${"\${data[1]//[[:blank:]]/}"}" | 
					
						
							|  |  |  |         export XEN_BRIDGE_IP_RANGE_END="${"\${data[2]//[[:blank:]]/}"}" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         IFS='-' read -a data <<< `${pkgs.sipcalc}/bin/sipcalc ${cfg.bridge.address}/${toString cfg.bridge.prefixLength} | grep Network\ address` | 
					
						
							|  |  |  |         export XEN_BRIDGE_NETWORK_ADDRESS="${"\${data[1]//[[:blank:]]/}"}" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-28 07:48:51 +00:00
										 |  |  |         IFS='-' read -a data <<< `${pkgs.sipcalc}/bin/sipcalc ${cfg.bridge.address}/${toString cfg.bridge.prefixLength} | grep Network\ mask` | 
					
						
							|  |  |  |         export XEN_BRIDGE_NETMASK="${"\${data[1]//[[:blank:]]/}"}" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-23 13:36:32 +02:00
										 |  |  |         echo "${cfg.bridge.address} host gw dns" > /var/run/xen/dnsmasq.hostsfile | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cat <<EOF > /var/run/xen/dnsmasq.conf | 
					
						
							|  |  |  |         no-daemon | 
					
						
							|  |  |  |         pid-file=/var/run/xen/dnsmasq.pid | 
					
						
							|  |  |  |         interface=${cfg.bridge.name} | 
					
						
							|  |  |  |         except-interface=lo | 
					
						
							|  |  |  |         bind-interfaces | 
					
						
							|  |  |  |         auth-zone=xen.local,$XEN_BRIDGE_NETWORK_ADDRESS/${toString cfg.bridge.prefixLength} | 
					
						
							|  |  |  |         domain=xen.local | 
					
						
							|  |  |  |         addn-hosts=/var/run/xen/dnsmasq.hostsfile | 
					
						
							|  |  |  |         expand-hosts | 
					
						
							|  |  |  |         strict-order | 
					
						
							|  |  |  |         no-hosts | 
					
						
							|  |  |  |         bogus-priv | 
					
						
							| 
									
										
										
										
											2017-04-30 06:50:28 +00:00
										 |  |  |         ${optionalString (!cfg.bridge.forwardDns) ''
 | 
					
						
							|  |  |  |           no-resolv | 
					
						
							|  |  |  |           no-poll | 
					
						
							|  |  |  |           auth-server=dns.xen.local,${cfg.bridge.name} | 
					
						
							|  |  |  |         ''}
 | 
					
						
							| 
									
										
										
										
											2015-06-23 13:36:32 +02:00
										 |  |  |         filterwin2k | 
					
						
							|  |  |  |         clear-on-reload | 
					
						
							|  |  |  |         domain-needed | 
					
						
							|  |  |  |         dhcp-hostsfile=/var/run/xen/dnsmasq.etherfile | 
					
						
							|  |  |  |         dhcp-authoritative | 
					
						
							| 
									
										
										
										
											2016-10-26 16:26:01 +00:00
										 |  |  |         dhcp-range=$XEN_BRIDGE_IP_RANGE_START,$XEN_BRIDGE_IP_RANGE_END | 
					
						
							| 
									
										
										
										
											2015-06-23 13:36:32 +02:00
										 |  |  |         dhcp-no-override | 
					
						
							|  |  |  |         no-ping | 
					
						
							|  |  |  |         dhcp-leasefile=/var/run/xen/dnsmasq.leasefile | 
					
						
							|  |  |  |         EOF | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # DHCP | 
					
						
							| 
									
										
										
										
											2016-10-25 07:27:05 +00:00
										 |  |  |         ${pkgs.iptables}/bin/iptables -w -I INPUT  -i ${cfg.bridge.name} -p tcp -s $XEN_BRIDGE_NETWORK_ADDRESS/${toString cfg.bridge.prefixLength} --sport 68 --dport 67 -j ACCEPT | 
					
						
							|  |  |  |         ${pkgs.iptables}/bin/iptables -w -I INPUT  -i ${cfg.bridge.name} -p udp -s $XEN_BRIDGE_NETWORK_ADDRESS/${toString cfg.bridge.prefixLength} --sport 68 --dport 67 -j ACCEPT | 
					
						
							| 
									
										
										
										
											2015-06-23 13:36:32 +02:00
										 |  |  |         # DNS | 
					
						
							| 
									
										
										
										
											2016-10-25 07:27:05 +00:00
										 |  |  |         ${pkgs.iptables}/bin/iptables -w -I INPUT  -i ${cfg.bridge.name} -p tcp -d ${cfg.bridge.address} --dport 53 -m state --state NEW,ESTABLISHED -j ACCEPT | 
					
						
							|  |  |  |         ${pkgs.iptables}/bin/iptables -w -I INPUT  -i ${cfg.bridge.name} -p udp -d ${cfg.bridge.address} --dport 53 -m state --state NEW,ESTABLISHED -j ACCEPT | 
					
						
							| 
									
										
										
										
											2015-06-23 13:36:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         ${pkgs.bridge-utils}/bin/brctl addbr ${cfg.bridge.name} | 
					
						
							|  |  |  |         ${pkgs.inetutils}/bin/ifconfig ${cfg.bridge.name} ${cfg.bridge.address} | 
					
						
							| 
									
										
										
										
											2017-04-28 07:48:51 +00:00
										 |  |  |         ${pkgs.inetutils}/bin/ifconfig ${cfg.bridge.name} netmask $XEN_BRIDGE_NETMASK | 
					
						
							| 
									
										
										
										
											2015-06-23 13:36:32 +02:00
										 |  |  |         ${pkgs.inetutils}/bin/ifconfig ${cfg.bridge.name} up | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  |       serviceConfig.ExecStart = "${pkgs.dnsmasq}/bin/dnsmasq --conf-file=/var/run/xen/dnsmasq.conf"; | 
					
						
							|  |  |  |       postStop = ''
 | 
					
						
							| 
									
										
										
										
											2017-05-11 09:40:59 +00:00
										 |  |  |         IFS='-' read -a data <<< `${pkgs.sipcalc}/bin/sipcalc ${cfg.bridge.address}/${toString cfg.bridge.prefixLength} | grep Network\ address` | 
					
						
							|  |  |  |         export XEN_BRIDGE_NETWORK_ADDRESS="${"\${data[1]//[[:blank:]]/}"}" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-23 13:36:32 +02:00
										 |  |  |         ${pkgs.inetutils}/bin/ifconfig ${cfg.bridge.name} down | 
					
						
							|  |  |  |         ${pkgs.bridge-utils}/bin/brctl delbr ${cfg.bridge.name} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # DNS | 
					
						
							| 
									
										
										
										
											2016-10-25 07:27:05 +00:00
										 |  |  |         ${pkgs.iptables}/bin/iptables -w -D INPUT  -i ${cfg.bridge.name} -p udp -d ${cfg.bridge.address} --dport 53 -m state --state NEW,ESTABLISHED -j ACCEPT | 
					
						
							|  |  |  |         ${pkgs.iptables}/bin/iptables -w -D INPUT  -i ${cfg.bridge.name} -p tcp -d ${cfg.bridge.address} --dport 53 -m state --state NEW,ESTABLISHED -j ACCEPT | 
					
						
							| 
									
										
										
										
											2015-06-23 13:36:32 +02:00
										 |  |  |         # DHCP | 
					
						
							| 
									
										
										
										
											2017-05-11 09:40:59 +00:00
										 |  |  |         ${pkgs.iptables}/bin/iptables -w -D INPUT  -i ${cfg.bridge.name} -p udp -s $XEN_BRIDGE_NETWORK_ADDRESS/${toString cfg.bridge.prefixLength} --sport 68 --dport 67 -j ACCEPT | 
					
						
							|  |  |  |         ${pkgs.iptables}/bin/iptables -w -D INPUT  -i ${cfg.bridge.name} -p tcp -s $XEN_BRIDGE_NETWORK_ADDRESS/${toString cfg.bridge.prefixLength} --sport 68 --dport 67 -j ACCEPT | 
					
						
							| 
									
										
										
										
											2015-06-23 13:36:32 +02:00
										 |  |  |       '';
 | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-09 15:08:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |     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"; | 
					
						
							| 
									
										
										
										
											2017-03-03 17:46:57 +00:00
										 |  |  |       path = [ cfg.package cfg.qemu-package ]; | 
					
						
							|  |  |  |       environment.XENDOM_CONFIG = "${cfg.package}/etc/sysconfig/xendomains"; | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |       preStart = "mkdir -p /var/lock/subsys -m 755"; | 
					
						
							| 
									
										
										
										
											2017-03-03 17:46:57 +00:00
										 |  |  |       serviceConfig.ExecStart = "${cfg.package}/etc/init.d/xendomains start"; | 
					
						
							|  |  |  |       serviceConfig.ExecStop = "${cfg.package}/etc/init.d/xendomains stop"; | 
					
						
							| 
									
										
										
										
											2015-01-29 09:58:28 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-12 22:43:45 +00:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |