| 
									
										
										
										
											2012-02-25 20:10:53 +00:00
										 |  |  | # Module for VirtualBox guests. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | { config, lib, pkgs, ... }: | 
					
						
							| 
									
										
										
										
											2010-09-07 13:28:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | with lib; | 
					
						
							| 
									
										
										
										
											2010-09-07 13:28:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | let | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-13 12:17:32 +02:00
										 |  |  |   cfg = config.virtualisation.virtualbox.guest; | 
					
						
							| 
									
										
										
										
											2011-09-19 13:20:09 +00:00
										 |  |  |   kernel = config.boot.kernelPackages; | 
					
						
							| 
									
										
										
										
											2010-09-07 13:28:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | in | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ###### interface | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-04 22:06:14 +01:00
										 |  |  |   options.virtualisation.virtualbox.guest = { | 
					
						
							|  |  |  |     enable = mkOption { | 
					
						
							|  |  |  |       default = false; | 
					
						
							|  |  |  |       type = types.bool; | 
					
						
							|  |  |  |       description = "Whether to enable the VirtualBox service and other guest additions."; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     x11 = mkOption { | 
					
						
							|  |  |  |       default = true; | 
					
						
							|  |  |  |       type = types.bool; | 
					
						
							|  |  |  |       description = "Whether to enable x11 graphics"; | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2010-09-07 13:28:17 +00:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-07 13:28:17 +00:00
										 |  |  |   ###### implementation | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-04 22:06:14 +01:00
										 |  |  |   config = mkIf cfg.enable (mkMerge [{ | 
					
						
							|  |  |  |     assertions = [{ | 
					
						
							| 
									
										
										
										
											2014-05-05 14:58:51 -04:00
										 |  |  |       assertion = pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64; | 
					
						
							| 
									
										
										
										
											2018-08-20 15:11:29 -04:00
										 |  |  |       message = "Virtualbox not currently supported on ${pkgs.stdenv.hostPlatform.system}"; | 
					
						
							| 
									
										
										
										
											2016-12-04 22:06:14 +01:00
										 |  |  |     }]; | 
					
						
							| 
									
										
										
										
											2010-09-07 13:28:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-25 20:10:53 +00:00
										 |  |  |     environment.systemPackages = [ kernel.virtualboxGuestAdditions ]; | 
					
						
							| 
									
										
										
										
											2011-08-09 19:53:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-19 13:20:09 +00:00
										 |  |  |     boot.extraModulePackages = [ kernel.virtualboxGuestAdditions ]; | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-20 00:29:20 +02:00
										 |  |  |     boot.supportedFilesystems = [ "vboxsf" ]; | 
					
						
							|  |  |  |     boot.initrd.supportedFilesystems = [ "vboxsf" ]; | 
					
						
							| 
									
										
										
										
											2014-02-05 18:38:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-30 01:58:35 +02:00
										 |  |  |     users.groups.vboxsf.gid = config.ids.gids.vboxsf; | 
					
						
							| 
									
										
										
										
											2012-12-31 11:00:02 -10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-09 13:30:57 +02:00
										 |  |  |     systemd.services.virtualbox = | 
					
						
							| 
									
										
										
										
											2012-08-23 10:25:27 -04:00
										 |  |  |       { description = "VirtualBox Guest Services"; | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-06 14:59:58 -04:00
										 |  |  |         wantedBy = [ "multi-user.target" ]; | 
					
						
							|  |  |  |         requires = [ "dev-vboxguest.device" ]; | 
					
						
							|  |  |  |         after = [ "dev-vboxguest.device" ]; | 
					
						
							| 
									
										
										
										
											2010-09-07 13:28:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-09 13:30:57 +02:00
										 |  |  |         unitConfig.ConditionVirtualization = "oracle"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-04 03:03:24 +02:00
										 |  |  |         serviceConfig.ExecStart = "@${kernel.virtualboxGuestAdditions}/bin/VBoxService VBoxService --foreground"; | 
					
						
							| 
									
										
										
										
											2010-09-07 13:28:17 +00:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-04 22:06:14 +01:00
										 |  |  |     services.udev.extraRules = | 
					
						
							|  |  |  |       ''
 | 
					
						
							|  |  |  |         # /dev/vboxuser is necessary for VBoxClient to work.  Maybe we | 
					
						
							|  |  |  |         # should restrict this to logged-in users. | 
					
						
							|  |  |  |         KERNEL=="vboxuser",  OWNER="root", GROUP="root", MODE="0666" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Allow systemd dependencies on vboxguest. | 
					
						
							|  |  |  |         SUBSYSTEM=="misc", KERNEL=="vboxguest", TAG+="systemd" | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  |   } (mkIf cfg.x11 { | 
					
						
							| 
									
										
										
										
											2020-05-01 00:05:55 +02:00
										 |  |  |     services.xserver.videoDrivers = mkOverride 50 [ "vmware" "virtualbox" "modesetting" ]; | 
					
						
							| 
									
										
										
										
											2012-03-16 01:03:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     services.xserver.config = | 
					
						
							|  |  |  |       ''
 | 
					
						
							|  |  |  |         Section "InputDevice" | 
					
						
							|  |  |  |           Identifier "VBoxMouse" | 
					
						
							|  |  |  |           Driver "vboxmouse" | 
					
						
							|  |  |  |         EndSection | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     services.xserver.serverLayoutSection = | 
					
						
							|  |  |  |       ''
 | 
					
						
							|  |  |  |         InputDevice "VBoxMouse" | 
					
						
							|  |  |  |       '';
 | 
					
						
							| 
									
										
										
										
											2012-08-06 14:59:58 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-16 01:29:51 +00:00
										 |  |  |     services.xserver.displayManager.sessionCommands = | 
					
						
							|  |  |  |       ''
 | 
					
						
							| 
									
										
										
										
											2016-04-13 15:53:51 +03:00
										 |  |  |         PATH=${makeBinPath [ pkgs.gnugrep pkgs.which pkgs.xorg.xorgserver.out ]}:$PATH \ | 
					
						
							| 
									
										
										
										
											2012-03-16 01:29:51 +00:00
										 |  |  |           ${kernel.virtualboxGuestAdditions}/bin/VBoxClient-all | 
					
						
							|  |  |  |       '';
 | 
					
						
							| 
									
										
										
										
											2016-12-04 22:06:14 +01:00
										 |  |  |   })]); | 
					
						
							| 
									
										
										
										
											2010-09-07 13:28:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |