Dependency closure "erasure" over ISO file boundaries

Hi there,

i have a situation where i would like to boot an initial ramdisk, and the initial ramdisk basically just starts a VM.
The VM is basically just some hypervisor booting a bootable ISO.

I cannot post a minimal sample right now so i hope the following information is enough to give a complete problem statement:

On the nix expression level, the script is a writeScript derivation that references both the hypervisor binaries and the ISO from the nix store. The hypervisor might for example be qemu from nixpkgs.
The ISO is its own derivation which simply outputs a store path that is just /nix/store/213213213213-myiso.iso.

Now, in order to calculate the contents that should go into the initial ramdisk, one would simply calculate the closure of this script and get all those store paths into the initrd.

This does work. The initrd contains enough to run the whole scenario. Unfortunately, if you ask the nix store about the dependencies of the ISO, it lists all the things that the ISO contains already. That means that my initrd contains the ISO plus its contents in addition to that in the initrd nix store.

E.g. if you query the closure info of the installer iso of nixos, you get the whole list:

nixpkgs $ nix-store -qR $(nix-build nixos/release.nix -A iso_minimal)
/nix/store/01pymsf349brc1w2i06nqip0cn1a3xl1-coreutils-8.31-info
/nix/store/029wkc688a2qrrlpbasypqcp4xz5q86g-nghttp2-1.40.0
/nix/store/02y6dq8a12rqhh7yaww8g4gm6qs101yd-nixos-20.09pre130979.gfedcba
/nix/store/r2nywq3ziag55zi6dqcxkpb6yla044kq-libunistring-0.9.10
/nix/store/arb8311fjm1dsrbsy8j7pdanwnz1qwxv-libidn2-2.3.0
/nix/store/mh78fk3x12q2a77srgkzv16h0irl8r61-glibc-2.31
/nix/store/5nq3a165axi47y1w11c71ks4cndr9gkm-xz-5.2.5
/nix/store/9zv18gxlzj614hfb92m0jwilhiqa982b-lz4-1.9.2
/nix/store/m0glpxhldl4j7rfzzbmj8vngb7g7dg9l-libcap-2.27-lib
/nix/store/vjy3d4fxg3ka03p9swhm4v5caa37izf3-libgpg-error-1.38
/nix/store/qavjy93r2lfv3r5vn4fi6g2wdy8zlwjc-libgcrypt-1.8.6
...
/nix/store/jxg0pddcj0d3l07gh1yqaqkw0fmhcrls-nixos-minimal-20.09pre130979.gfedcba-aarch64-linux.iso

Is there some possibility to let nix “stop” calculating the dependencies at ISO boundaries, as the ISO is selfcontained and does not have any other deps in order to be booted in a VM?

In nixpkgs, references known to be unneeded are often removed using nuke-references or remove-references-to, which replace the hashes with invalid ones. This won’t work in your case though, since the paths are actually used in the initramfs.

A somewhat questionable “solution” to this is compressing the resulting image (then decompressing it for use), so the references are no longer detected.

I’m not aware of a way to tell nix “no really, this path doesn’t depend on that one, I promise o:)” while leaving the references unmodified.

2 Likes