I think there's a way that might be easy-ish. In short what the services
setting does is to get necessary packages, write configuration files, and install systemd unit files. You can build a NixOS configuration, and symlink or copy the necessary systemd units and configuration files. I think that would work, and would not interfere with other stuff on your system.
NixOS configurations must be built with nixos-rebuild
- you can't use nix-build
by itself. You can put your configuration wherever, and run:
$ nixos-rebuild build -I nixos-config=./configuration.nix
That will build everything in paths under /nix/store/
without touching anything else on your system. It will create a symlink in your working directory called result/
with a fully-built, bot not installed, NixOS. If you were running NixOS you would run nixos-rebuild switch
to update symlinks to point to all of this stuff. But you'd skip that step.
result/etc/systemd/system/
contains systemd units. There will be a lot of stuff there that you don't want. You'd need to selectively symlink or copy units from this directory to your /etc/systemd/
tree.
The units use full paths to binaries in /nix/store/
so you don't need to do anything extra to install software packages.
You might need to symlink or copy configuration files for your services. Those should also be somewhere in result/
.
If NixOS and Debian use the same systemd target names your services should run automatically on boot. If not you might have to do some fix-up, or run systemctl
commands manually. I think you'd need to run some systemctl
commands to start and stop services if you want to update without rebooting.
You can probably do all that symlinking just once if you symlink everything through that result
symlink.
Edit: Although, taking a closer look at what services.nextcloud
does I see that it does a lot, like initializing databases and creating user accounts if you choose to use a local database. It might be a lot of work to chase down all of the configuration that you would have to copy over. Running NixOS is definitely going to be easier.