-
-
Notifications
You must be signed in to change notification settings - Fork 18k
Description
We've talked about this for years, usually in the context of people hating or wanting to replace systemd, but I think it's time to start talking about it in other less negative contexts as well.
Motivation
Nixpkgs now works pretty well on Darwin, and the nix-darwin effort by @LnL7 can manage services using launchd. Unfortunately, even though 99% of the logic could be shared with NixOS services, it can't currently be.
Furthermore, people are taking more and more infrastructure to distributed container scheduling systems like Kubernetes, ECS, or Nomad. Although in some cases people might run the host on NixOS, I think Nix can provide an equally compelling story for the container guests. @lethalman's dockerTools is a promising start to that, but just like nix-darwin, anyone using it has to reinvent the configuration for their services because NixOS service modules can't be reused.
Finally, assorted work like declarative user environments, replacing the init system (please don't turn this thread into another systemd flamewar; we have plenty of other venues for that), and service testing on virtualized platforms (I can't run any of the NixOS VM tests on EC2, Azure, Google Cloud, and so on) all could benefit heavily from such a layer.
Prior work
The major effort so far has been #5246 and it's an impressive feat but has long bitrotted, and @offlinehacker does not have the time to pick it up again.
Key goals
- Should be possible to evaluate/build on non-NixOS systems, and ideally non-Linux ones (with a suitable back-end)
- Shouldn't lose the nice functionality we enjoy from
systemd. More generally, it shouldn't prevent us from using system-specific idiosyncrasies that don't exist in other systems. If we see some of them being used repeatedly all over the place, we eventually factor them out into the SAL. - Shouldn't get overly complicated or generalized. Let's not try to plan for every eventuality and just tackle low-hanging fruit for now.
- Don't get mired in getting something perfect all at once. 1000-line+ PRs rarely get merged or even reviewed, and bitrot easily. I'm convinced we can do this incrementally and see if we like it on one or two simple services with small PRs, and then start working outwards from there.
Proposed approach
I'm not actually going to propose a technical approach here. Rather, I'd like to propose how we approach figuring out how to implement it.
- Go through all of our service modules and categorize how many of them use each
keyinsystemd.services.<name>.<key>and how. - Write the thinnest layer that covers the two or three most commonly used service keys and translates its config to the current
systemd.servicesmachinery - Write a simple "dump to text file" backend for the SAL that lists enabled services in an arbitrary piece of config, and builds on a non-Linux platform
- In separate PRs, start switching over small numbers of our simplest services to use the new SAL machinery, possibly leaving some
systemd.servicesconfig behind to merge with the config that SAL sets - Start work on more interesting backends like a launchd one and a docker one, etc.
I expect most services don't do much beyond setting ExecStart/script and some environment, possibly with a default wantedBy = [ "multi-user.target" ] which basically means "please run my unit" in most cases. Many services probably want a way to express that they need networking, and some might want to run as a separate user. Eventually we'll start running into services that depend on other services, and I propose not trying to tackle that at first.
cc @shlevy @offlinehacker @edolstra @globin @LnL7
P.S: this isn't an RFC because I'm not actually saying what to do, but just what I want and how I think we should go about making it happen