tvix/glue/derivation: implement exportReferencesGraph

#396
Opened by flokli at 2024-04-08T21·51+00

From https://nixos.org/manual/nix/stable/language/advanced-attributes#adv-attr-exportReferencesGraph:

This attribute allows builders access to the references graph of their inputs. The attribute is a list of inputs in the Nix store whose references graph the builder needs to know. The value of this attribute should be a list of pairs [ name1 path1 name2 path2 ... ]. The references graph of each pathN will be stored in a text file nameN in the temporary build directory. The text files have the format used by nix-store --register-validity (with the deriver fields left empty). For example, when the following derivation is built:

derivation {
  ...
  exportReferencesGraph = [ "libfoo-graph" libfoo ];
};

the references graph of libfoo is placed in the file libfoo-graph in the temporary build directory.

exportReferencesGraph is useful for builders that want to do something with the closure of a store path. Examples include the builders in NixOS that generate the initial ramdisk for booting Linux (a cpio archive containing the closure of the boot script) and the ISO-9660 image for the installation CD (which is populated with a Nix store containing the closure of a bootable NixOS configuration).


We need to first figure out how this changes the ATerm:

https://github.com/NixOS/nix/blob/c313394ae905db4c0df0bfeab9c79a2f1c085828/src/libstore/parsed-derivations.cc#L183-L193

… and later on make sure to synthesize a JSON in the resulting BuildRequest (which contains more data, like runtime references, so needs to happen quite late).