I’m trying at add support to LXD’s distrobuilder. I’m hoping to provide a similar experience to other distributions which have images built automatically by the LXD team using their CI. Doing so should allow NixOS to be available through the Canonical image server and make it more approachable for new users.
At the same time I’m hoping to provide a more NixOS like experience using the existing LXD tooling. For example, allowing users who are building custom images to follow the LXD pattern but provide Nix code. I also eventually want to add support for a user to provide inputs (e.g. flake) to the metadata when an instance is created from the image.
Unfortunately I’m a bit stuck on how to proceed so I’m posting this to see if anybody has any good ideas, or has better insight. I’m still relatively new to using Nix and NixOS so I don’t have a lot of depth yet.
How distrobuilder seems to work is that it extracts a system tarball, “generates” some files into the structure, and chroots to run some commands. It’s specifically this last step that I am a bit hung up on, as I am unsure how to initiate a nixos-rebuild from within an un-activated system tarball. See this example of an image config.
I’m unsure how I could bootstrap this enough to allow an arbitrary shell script to run, since the un-activated tarball doesn’t seem to have a way to easily discover where bash, nixos-rebuild, etc are. So what would be the best way to allow for an arbitrary nixos-rebuild of a system tarball?
Other potentially relevant information:
- I’m using the existing lxdImage tarball in my working branch
- There’s an effort by @erictapen to refactor the lxc/lxd images here that I’m following and testing with as well
- And an open request to improve support for lxc/lxd images