Devenv vs services-flake vs?

Hi, all,

I’m starting to use nix flakes for development of mostly Drupal sites, sometimes others, generally always with a need for a daemonized language runtime, a database, and a web server.

Most Drupal developers these days use a Docker-based solution – ddev is currently the leading one, but there are otthers. This is a pretty decent experience, but I’m wondering if I can get close with a Nix-based solution.

This is purely for development right now – I was trying to create a flake that would start all of these services and then drop into a devShell, but could only get the first running, was trying to fork and trap so I could have a command to start and stop the servers, and didn’t get there.

I’ve found that both Services-flake and Devenv are trying to solve this problem – would love to hear comparisons between them, or if there’s a simpler way to do this?

My goals are:

  • Have an easy one-command nix run to download a project, start all the servers, and kick off an install script
  • Be able to start a new project with nix flake init --template github://org/my-project
  • Be able to run different language versions in different projects by changing a single line in the project’s flake
  • Be able to run several projects simultaneously (on different ports)
  • make this portable to run on Darwin/Windows

Would love to hear anybody’s experiences working with these!

4 Likes

I use devenv.sh for PHP development:

  • Have an easy one-command nix run to download a project, start all the servers, and kick off an install script

Here is a sample nix config that I use on Mac.
To start working I do:

nix develop --impure path:./nix -c $SHELL
devenv-custom up path:nix
  • Be able to start a new project with nix flake init --template github://org/my-project

You can package your typical project templates and put on GitHub

  • Be able to run different language versions in different projects by changing a single line in the project’s flake
  • Be able to run several projects simultaneously (on different ports)

Devenv.sh allows it.

  • make this portable to run on Darwin/Windows

It should be portable as long as there are nixpkg for both systems.

In my case I use Mac’s built-in apache as a server which won’t work on Windows, but it’s possible to setup a server via devenv.sh as well.

I haven’t tried services-flake though so can’t compare.

1 Like

We’re a Drupal shop and I made drupal-devenv with pretty-much the same goals as you. I tried to get as close to ddev in terms of making something that Just Works™.

It’s probably easiest if I answer each goal individually:

Have an easy one-command nix run to download a project, start all the servers, and kick off an install script
Be able to start a new project with nix flake init --template github://org/my-project

Unfortunately, when setting up an environment you have to copy some stuff to devenv.yaml, after that it’s just devenv up.

IIRC, I looked into it and devenv doesn’t support arbitrary project templates. If it did, that would turn setup into a one-liner; I should file a feature request.

Be able to run different language versions in different projects by changing a single line in the project’s flake

Devenv supports this, and by extension drupal-devenv does too.

  1. Be able to run several projects simultaneously (on different ports)

Hopefully it won’t disappoint you to hear that drupal-devenv doesn’t need to use multiple ports to run multiple projects simultaneously. Caddy seems to handle this and SSL for localhost reasonably well.

  1. make this portable to run on Darwin/Windows

Unfortunately, we’re a small shop and we all run Linux. And I’m pretty sure the code that does privilege escalation, so Caddy can use ports 80 and 443, is Linux specific. I’d love a PR that makes it work on Mac and WSL!

I was trying to create a flake that would start all of these services and then drop into a devShell

In devenv, this would be devenv up -d and devenv processes down. I do find the latter to be slightly less reliable than Docker Compose, meaning sometimes I have to go pid-hunting, which is a bummer but not a show-stopper.

I haven’t tried Services-flake, so I’m sorry I can’t speak to the comparison part of your question. I started out trying to use Flakes with Devenv, but it’s not the easiest way to use Devenv so I gave up and used the Nix module approach the project recommends. That turned out great, as it eased me into Nix gently. Then once I understood flakes, I was able to read the one devenv creates in each of my projects and steal ideas from it.

I hope this helps! Have you made any progress since creating this thread?