<p>I recently said that <a href="/daily/2024/11/30/using-nix-for-local-application-development">I've been using devenv to run Drupal applications locally</a>.</p>
<p>Here's the <code>devenv.nix</code> file I used for <a href="/presentations/tdd-test-driven-drupal">my recent talk for the Drupal London meetup</a>:</p>
<pre><code class="nix">{ 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
'';
}
</code></pre>
<p>It installs the required version of PHP for this project, creates a web server (Caddy) and configures MariaDB with a default database.</p>
<p>I've also added commands to run <code>composer install</code> to download dependencies when entering the shell and <code>phpunit</code> for tests.</p>
<p>With this approach, there's no need for containers as everything is run locally and I can view the site at <a href="http://localhost:8080">http://localhost:8080</a> (or whatever port is defined).</p>
<p>All of my current development projects are using this approach and I think it'll be my default method for future projects.</p>
<p>I recently said that <a href="/daily/2024/11/30/using-nix-for-local-application-development">I've been using devenv to run Drupal applications locally</a>.</p>
<p>Here's the <code>devenv.nix</code> file I used for <a href="/presentations/tdd-test-driven-drupal">my recent talk for the Drupal London meetup</a>:</p>
initialDatabases = [ { name = "drupal_london"; } ];
};
};
enterShell = ''
if [[ ! -d vendor ]]; then
composer install
fi
'';
enterTest = ''
phpunit --testdox
'';
}
</code></pre>
<p>It installs the required version of PHP for this project, creates a web server (Caddy) and configures MariaDB with a default database.</p>
<p>I've also added commands to run <code>composer install</code> to download dependencies when entering the shell and <code>phpunit</code> for tests.</p>
<p>With this approach, there's no need for containers as everything is run locally and I can view the site at <a href="http://localhost:8080">http://localhost:8080</a> (or whatever port is defined).</p>
<p>All of my current development projects are using this approach and I think it'll be my default method for future projects.</p>