Skip to content

Commit

Permalink
interactive-vm: use host pkgs in the launcher script.
Browse files Browse the repository at this point in the history
  • Loading branch information
0x450x6c authored and mergify[bot] committed Sep 23, 2024
1 parent 430ba34 commit b1d6bed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/interactive-vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
```
Expand Down
8 changes: 5 additions & 3 deletions lib/interactive-vm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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}
Expand Down

0 comments on commit b1d6bed

Please sign in to comment.