Closed pieterlexis closed 4 years ago
I don't quite understand, the mkosi build already happens in two phases, quoting from the docs
mkosi.build may be an executable script. If it exists the image will be built twice: the first iteration will be the development image, the second iteration will be the final image. The development image is used to build the project in the current working directory (the source tree). For that the whole directory is copied into the image, along with the mkosi.build build script. The script is then invoked inside the image (via systemd-nspawn), with $SRCDIR pointing to the source tree. $DESTDIR points to a directory where the script should place any files generated it would like to end up in the final image. Note that make/automake/meson based build systems generally honor $DESTDIR, thus making it very natural to build source trees from the build script. After the development image was built and the build script ran inside of it, it is removed again. After that the final image is built, without any source tree or build script copied in. However, this time the contents of $DESTDIR are added into the image.
I guess we have no script hook right now that allows installing stuff with additional package managers before we take the copy in incremental mode. I mean, you could just install the additional stuff from the build script itself, but that means incremental mode doesn't work, and the build script needs to run with networking. We could add another hook that runs right after "dnf" and friends run, with full network, and only after that we take the snapshot for incremental mode. i.e. maybe call it "mkosi.prepare" or so. Would be delighted to take a patch for that.
I really like the idea of a prepare script. It can be a small step towards reproducible builds if you save the cached image (in incremental mode) to your VCS.
@poettering I have created a pull request which should do exactly what you described in your comment.
We have a prepare script option now.
Hi,
For a project I'm working on, I would like to have an image with systemd. So mkosi comes to mind. I need to build some dependencies that are not in any distro, but these don't change often. It would be neat if the build could be done in 2 stages, in the first one I'd build the dependencies and in the second (using the image produced in the first stage) the actual software I'm working on.
Let me know if this is a feature that would make sense for mkosi and I I'll see if I can find the time to implement it.