Running Drupal on devenv

I recently said that I've been using devenv to run Drupal applications locally.

Here's the devenv.nix file I used for my recent talk for the Drupal London meetup:

{ pkgs, ... }:

let
drupal.root = "web";
in
{
packages = [ pkgs.git ];

dotenv.disableHint = true;

languages = {
php = {
enable = true;
version = "8.2";

ini = ''
memory_limit = 256M
'';

fpm.pools.web = {
listen = "127.0.0.1:9000";

settings = {
"pm" = "dynamic";
"pm.max_children" = 75;
"pm.max_requests" = 500;
"pm.max_spare_servers" = 20;
"pm.min_spare_servers" = 5;
"pm.start_servers" = 10;
};
};
};
};

processes = { };

services = {
caddy = {
enable = true;

config = ''
{
http_port 8080
}

localhost:8080 {
root * ${drupal.root}
encode gzip
php_fastcgi localhost:9000
file_server
}
'';
};

mysql = {
enable = true;
initialDatabases = [ { name = "drupal_london"; } ];
};
};

enterShell = ''
if [[ ! -d vendor ]]; then
composer install
fi
'';

enterTest = ''
phpunit --testdox
'';
}

It installs the required version of PHP for this project, creates a web server (Caddy) and configures MariaDB with a default database.

I've also added commands to run composer install to download dependencies when entering the shell and phpunit for tests.

With this approach, there's no need for containers as everything is run locally and I can view the site at http://localhost:8080 (or whatever port is defined).

All of my current development projects are using this approach and I think it'll be my default method for future projects.