Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions lib/make-disk-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,40 @@ 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;
boot.kernelPackages = lib.mkDefault cfg.kernelPackages;
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;
[
Expand Down Expand Up @@ -111,9 +117,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
Expand All @@ -124,7 +127,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.environment.etc."udev/rules.d".source} /etc/udev/rules.d
ln -sfn ${cleanedSystemNative.config.environment.etc."udev/rules.d".source} /etc/udev/rules.d
mkdir -p /dev/.mdadm
${pkgs.systemdMinimal}/lib/systemd/systemd-udevd --daemon
partprobe
Expand All @@ -134,9 +137,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}
unset NIX_REMOTE
Expand Down
9 changes: 9 additions & 0 deletions module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,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 {
Expand Down
Loading