diff --git a/lib/make-disk-image.nix b/lib/make-disk-image.nix index df3324f4..14222b12 100644 --- a/lib/make-disk-image.nix +++ b/lib/make-disk-image.nix @@ -53,33 +53,38 @@ let customQemu = cfg.qemu; } ); + cleanedConfig = diskoLib.testLib.prepareDiskoConfig config diskoLib.testLib.devices; - systemToInstall = extendModules { + virtualDevicesModule = { + disko.devices = lib.mkForce cleanedConfig.disko.devices; + boot.loader.grub.devices = lib.mkForce cleanedConfig.boot.loader.grub.devices; + }; + system = extendModules { modules = [ cfg.extraConfig { disko.testMode = true; - disko.devices = lib.mkForce cleanedConfig.disko.devices; - boot.loader.grub.devices = lib.mkForce cleanedConfig.boot.loader.grub.devices; } ]; }; - systemToInstallNative = + cleanedSystem = system.extendModules { + modules = [ virtualDevicesModule ]; + }; + systemNative = if binfmt.systemsAreDifferent then - extendModules { + system.extendModules { modules = [ - cfg.extraConfig { - disko.testMode = true; - disko.devices = lib.mkForce cleanedConfig.disko.devices; - boot.loader.grub.devices = lib.mkForce cleanedConfig.boot.loader.grub.devices; nixpkgs.hostPlatform = lib.mkForce pkgs.stdenv.hostPlatform; nixpkgs.buildPlatform = lib.mkForce pkgs.stdenv.hostPlatform; } ]; } else - systemToInstall; + system; + cleanedSystemNative = systemNative.extendModules { + modules = [ virtualDevicesModule ]; + }; dependencies = with pkgs; [ @@ -108,9 +113,6 @@ let install -m600 ${pkgs.OVMF.variables} efivars.fd ''; - closureInfo = pkgs.closureInfo { - rootPaths = [ systemToInstall.config.system.build.toplevel ]; - }; partitioner = '' set -efux # running udev, stolen from stage-1.sh @@ -121,7 +123,7 @@ let ln -sfn /proc/self/fd/2 /dev/stderr mkdir -p /etc/udev mount -t efivarfs none /sys/firmware/efi/efivars - ln -sfn ${systemToInstallNative.config.system.build.etc}/etc/udev/rules.d /etc/udev/rules.d + ln -sfn ${cleanedSystemNative.config.system.build.etc}/etc/udev/rules.d /etc/udev/rules.d mkdir -p /dev/.mdadm ${pkgs.systemdMinimal}/lib/systemd/systemd-udevd --daemon partprobe @@ -131,9 +133,13 @@ let ${lib.optionalString diskoCfg.testMode '' export IN_DISKO_TEST=1 ''} - ${lib.getExe systemToInstallNative.config.system.build.destroyFormatMount} --yes-wipe-all-disks + ${lib.getExe cleanedSystemNative.config.system.build.destroyFormatMount} --yes-wipe-all-disks ''; + systemToInstall = if cfg.useVirtualDevices then cleanedSystem else system; + closureInfo = pkgs.closureInfo { + rootPaths = [ systemToInstall.config.system.build.toplevel ]; + }; installer = lib.optionalString cfg.copyNixStore '' ${binfmtSetup} # populate nix db, so nixos-install doesn't complain diff --git a/module.nix b/module.nix index 24d2305a..aab64ff3 100644 --- a/module.nix +++ b/module.nix @@ -121,6 +121,15 @@ in description = "QEMU image format to use for the disk images"; default = "raw"; }; + + useVirtualDevices = lib.mkOption { + type = lib.types.bool; + description = '' + Replace device names with ones usable in VMs. Ex: `/dev/vda`. + Disable this if the disk image is for use on real hardware. + ''; + default = true; + }; }; memSize = lib.mkOption {