Skip to content

make-disk-image: add useVirtualDevices option #1008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
36 changes: 21 additions & 15 deletions lib/make-disk-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
[
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ in
description = "QEMU image format to use for the disk images";
default = "raw";
};

useVirtualDevices = lib.mkOption {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still quite don't understand why this is needed after partitioning. Are we not using partition labels in any case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also boot.loader.grub.devices.

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