nixos/qemu: Add pkgs option for allowing other systems to run the VM

This commit is contained in:
Silvan Mosberger 2021-01-10 01:22:05 +01:00 committed by Yuriy Taraday
parent e2e40d7098
commit 04648b8dcf

View file

@ -102,7 +102,9 @@ let
# Shell script to start the VM.
startVM =
''
#! ${pkgs.runtimeShell}
#! ${cfg.host.pkgs.runtimeShell}
export PATH=${makeBinPath [ cfg.host.pkgs.coreutils ]}''${PATH:+:}$PATH
set -e
@ -574,11 +576,24 @@ in
description = "Primary IP address used in /etc/hosts.";
};
virtualisation.host.pkgs = mkOption {
type = options.nixpkgs.pkgs.type;
default = pkgs;
defaultText = "pkgs";
example = literalExpression ''
import pkgs.path { system = "x86_64-darwin"; }
'';
description = ''
pkgs set to use for the host-specific packages of the vm runner.
Changing this to e.g. a Darwin package set allows running NixOS VMs on Darwin.
'';
};
virtualisation.qemu = {
package =
mkOption {
type = types.package;
default = pkgs.qemu_kvm;
default = cfg.host.pkgs.qemu_kvm;
example = "pkgs.qemu_test";
description = lib.mdDoc "QEMU package to use.";
};
@ -1075,14 +1090,14 @@ in
services.qemuGuest.enable = cfg.qemu.guestAgent.enable;
system.build.vm = pkgs.runCommand "nixos-vm" {
system.build.vm = cfg.host.pkgs.runCommand "nixos-vm" {
preferLocalBuild = true;
meta.mainProgram = "run-${config.system.name}-vm";
}
''
mkdir -p $out/bin
ln -s ${config.system.build.toplevel} $out/system
ln -s ${pkgs.writeScript "run-nixos-vm" startVM} $out/bin/run-${config.system.name}-vm
ln -s ${cfg.host.pkgs.writeScript "run-nixos-vm" startVM} $out/bin/run-${config.system.name}-vm
'';
# When building a regular system configuration, override whatever