OS agnostic way of starting a new service

I’m currently working on creating development environments with nix for linux,macos and wsl. Up until now I’ve created new services trough docker images created using the docker tools. Is there a better way to do this?

Not really. There’s an RFC that might address this: https://github.com/NixOS/rfcs/pull/163

There might even be some other workarounds hinted at in there, but docker is a good start.

Generally, this isn’t trivial because NixOS modules are needed for a good, upstream-supported way of doing it, but that requires pretty invasive control of the host OS for the moment. It can’t be done in general, because some hardware-related services won’t be possible anyway. And generally, NixOS modules aren’t written to be used by users, so launching them in dev scripts is also not really intended.

You’d need a project separate from NixOS to do this; or NixOS would need to be rewritten to support an OS-agnostic service launching system, as the RFC suggests. Which, as it turns out, may be feasible.

Of course, in the meantime you can use scripts to run stuff, but now it’s your job to come up with an OS-agnostic service launcher - and docker is a pretty good one.

Devenv might also be useful, it seems to basically be writing NixOS-for-devshells, and targets your platforms: https://devenv.sh/