Running nixos services during development

nix-shell is amazing for running a project in an environment with the same programs/binaries, but it is less useful for starting up and shutting down services. But often one is developing something that needs access to other services, such as a database.

Ideally, I’d like to be able to launch nixos services, configured using something like the nixos module system, whilst I’m developing a particular project. I’m wondering whether there are any conveniet approaches to running such services during development?

In practice, the most sensible seems to be to start up a nixos system in some sort of sandbox. Ideally, I’m aware of nix containers, and I know there are other options that do something similar, but it is a tad disconcerting to need to use sudo or privileged daemons when I’m trying to run something in a reduced scope.

I have had some experimental successes with starting a NixOS instance from within a user namespace, but it became a bit of a mess, and I was wondering what other approaches people used?

1 Like

For testing your NixOS services check out nixos-shell by @Mic92GitHub - Mic92/nixos-shell: Spawns lightweight nixos vms in a shell . It spawns lightweight VMs for development.

1 Like