mobile-nixos / mobile-nixos

📱 (rebooting... please wait...)
MIT License
907 stars 186 forks source link

nixos: prevent system closure from containing initrd whenever its packed into a boot img #639

Open colemickens opened 1 year ago

colemickens commented 1 year ago

Just glancing over as my openstick updates. I noticed it's pulling down a rather large initrd, even though that's presumably packed in the separate boot.img already.

Is it possible for mobile-nixos to prevent the initrd image from slipping into the system closure in cases of Android-ish systems that use aboot/boot.img?

samueldr commented 1 year ago

Probably here:

This is to follow NixOS semantics. As you can see, it may be using a "null ramdisk" when building a device-agnostic image... so if it was even possible to override system.build.initialRamdisk, you would do just that. Turns out it is now possible since https://github.com/NixOS/nixpkgs/commit/4014fb6a64bc5f68326fc08cbaa83475db1fae8e !!

So you can mkForce a null image now.

colemickens commented 1 year ago

Nice!

{
  config = {
    # ...
    system.build.initialRamdisk = lib.mkForce (pkgs.writeText "test" "null").outPath;
    # ...
  };
}

seems to have worked, and after deploying/rebooting/GCing, I seem to have regained a fair little chunk of space, quite nice.

Thanks! Feel free to close if you want, but I'll leave it open in the thought of maybe coming back one day and plumbing this in, it seems like a fairly safe optimization for such devices, with proper asserts or binding to something that indicates its an android-ish device.

samueldr commented 1 year ago

So, do I understand right that you are shoving the whole stage-2 build directly into the boot.img's initramfs?

I wonder how practical that is, really...

... though even then, having a less global (internal) option to turn off adding the initrd to the system closure might be a good idea, and if it was done, we'd move the behaviour of config.mobile.rootfs.shared.enabled into modules/shared-rootfs.nix; that is, make it use that new internal option.

colemickens commented 1 year ago

To be honest, I'm not sure. I'm a bit bogged down.

Basically, I know this thing has a boot.img on it, I assumed it had to have the kernel and initrd, and thus I didn't need the initrd to ever actually be in the stage-2/root.

I was thinking while doing this, and maybe it's what you're asking... but I assume if I needed to update the boot.img, I might need to undo this change. I'm not totally sure.

samueldr commented 1 year ago

Ah, I understand, then ignore what I said about practicality. You're right that it doesn't have to be there...

(Unless you wanted to use stage-0 booting, e.g. kexec)