-
-
Notifications
You must be signed in to change notification settings - Fork 220
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
make-disk-image: add binfmt emulation #943
base: master
Are you sure you want to change the base?
Conversation
Very cool! Could you try to add a test for this as well? No need to test all permutations, aarch64 on x86_64 would be sufficient. |
Very nice feature, thank you! Don't want to block, but I think copying the magic numbers and such from nixpkgs and duplicating them in diskos source might not be the best course of action long-term. Maybe nixpkgs could expose them via a non-visible readOnly option or so instead? |
I think copying might be fine. Having a new CPU architecture is a rare event. |
I didn't have time to work on this PR the last few weeks, but I'm working on adding tests and minor fixes soon. Regarding the duplicate code, I agree it's not the most ideal approach, but if that's ok we can do it this way for now and open a separate PR in nixpkgs to export the binfmt code to the lib. |
Thank you a lot for your work on this. |
Thank you for this PR! I tried it out but still had a few issues with it.
And in the formatting step it failed to create btrfs subvolumes.
|
You are right. I'm going to update the PR with the things you mentioned. I haven't run into the Btrfs issue, I also use Btrfs but only the root subvolume. You could open a separate issue and include your disko config. |
Shouldn't it be possible to run disko with the native system and only run the installer with the target arch? Filesystems will use a lot of uncommon ioctls so I don't think this will be the last one. |
The following diff works for me. Should I open a seperate PR or do we want to commit it directly to this one? diff --git a/lib/make-disk-image.nix b/lib/make-disk-image.nix
index 7281a16..b4a0b7d 100644
--- a/lib/make-disk-image.nix
+++ b/lib/make-disk-image.nix
@@ -51,6 +51,18 @@ let
}
];
};
+ systemToInstallNative = if binfmt.systemsAreDifferent then 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;
+ }
+ ];
+ }
+ else systemToInstall;
dependencies = with pkgs; [
bash
coreutils
@@ -88,7 +100,7 @@ let
ln -sfn /proc/self/fd/2 /dev/stderr
mkdir -p /etc/udev
mount -t efivarfs none /sys/firmware/efi/efivars
- ln -sfn ${systemToInstall.config.system.build.etc}/etc/udev/rules.d /etc/udev/rules.d
+ ln -sfn ${systemToInstallNative.config.system.build.etc}/etc/udev/rules.d /etc/udev/rules.d
mkdir -p /dev/.mdadm
${pkgs.systemdMinimal}/lib/systemd/systemd-udevd --daemon
partprobe
@@ -98,10 +110,11 @@ let
${lib.optionalString diskoCfg.testMode ''
export IN_DISKO_TEST=1
''}
- ${lib.getExe systemToInstall.config.system.build.destroyFormatMount} --yes-wipe-all-disks
+ ${lib.getExe systemToInstallNative.config.system.build.destroyFormatMount} --yes-wipe-all-disks
'';
installer = lib.optionalString cfg.copyNixStore ''
+ ${binfmtSetup}
# populate nix db, so nixos-install doesn't complain
export NIX_STATE_DIR=${systemToInstall.config.disko.rootMountPoint}/nix/var/nix
nix-store --load-db < "${closureInfo}/registration" |
Now it's possible to build images for other architectures with native speed using KVM.
Binfmt emulation is only needed for the bootloader installation step, other steps use native binaries.
To use it, set imageBuilder.enableBinfmt to true, and pass a new nixpkgs instance to the image builder, with the system set to the running machine.
Example, building an aarch64 image on an x86_64 host: