From b1d6bed240abef5f5373e88fc7909f493013e557 Mon Sep 17 00:00:00 2001 From: zerox Date: Sun, 22 Sep 2024 01:03:56 +0500 Subject: [PATCH] interactive-vm: use host pkgs in the launcher script. --- docs/interactive-vm.md | 2 ++ lib/interactive-vm.nix | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/interactive-vm.md b/docs/interactive-vm.md index 17df62ef..c6119e51 100644 --- a/docs/interactive-vm.md +++ b/docs/interactive-vm.md @@ -18,6 +18,8 @@ You can configure the VM using the `virtualisation.vmVariantWithDisko` NixOS opt { virtualisation.vmVariantWithDisko = { virtualisation.fileSystems."/persist".neededForBoot = true; + # For running VM on macos: https://www.tweag.io/blog/2023-02-09-nixos-vm-on-macos/ + # virtualisation.host.pkgs = inputs.nixpkgs.legacyPackages.aarch64-darwin; }; } ``` diff --git a/lib/interactive-vm.nix b/lib/interactive-vm.nix index 1c9d28c3..87513579 100644 --- a/lib/interactive-vm.nix +++ b/lib/interactive-vm.nix @@ -40,6 +40,8 @@ let boot = cfg_.disko.devices._config.boot or { }; swapDevices = cfg_.disko.devices._config.swapDevices or [ ]; }; + + hostPkgs = config.virtualisation.host.pkgs; in { imports = [ @@ -63,12 +65,12 @@ in boot.zfs.devNodes = "/dev/disk/by-uuid"; # needed because /dev/disk/by-id is empty in qemu-vms boot.zfs.forceImportAll = true; - system.build.vmWithDisko = pkgs.writers.writeDashBin "disko-vm" '' + system.build.vmWithDisko = hostPkgs.writers.writeDashBin "disko-vm" '' set -efux - export tmp=$(mktemp -d) + export tmp=$(${hostPkgs.coreutils}/bin/mktemp -d) trap 'rm -rf "$tmp"' EXIT ${lib.concatMapStringsSep "\n" (disk: '' - ${pkgs.qemu}/bin/qemu-img create -f qcow2 \ + ${hostPkgs.qemu}/bin/qemu-img create -f qcow2 \ -b ${config.system.build.diskoImages}/${disk.name}.qcow2 \ -F qcow2 "$tmp"/${disk.name}.qcow2 '') disks}