I’m trying to create a Linux Container (LXC) that starts up, performs a task, and then immediately shuts itself down.
This is already working fairly nicely with nixos-generators and the configuration at:
However, systemd seems rather overkill here. It seems neater if I could overwrite system.build.bootStage2 myself, do just the minimal initialization needed for the script (enabling networking), performing the task and shutting down again.
Naively setting system.build.bootStage2 in configuration.nix doesn’t seem to work, though. Is this possible? How would I do it?
This sounds like a case for not using NixOS: NixOS is quite tightly coupled with systemd, but you can make your container’s store contain just your init script and replace nixos with it, something like
Yes, exactly — Nix without NixOS systemd will probably be pulled in as a dependency because the dhcp client will (maybe transitively) depend on udev or whatever, but you can avoid running it as PID1 in this way.