Skip to content

Instantly share code, notes, and snippets.

@LouisdeLooze
Last active January 13, 2026 17:47
Show Gist options
  • Select an option

  • Save LouisdeLooze/51c09ebcfa8403350677b8a82d256561 to your computer and use it in GitHub Desktop.

Select an option

Save LouisdeLooze/51c09ebcfa8403350677b8a82d256561 to your computer and use it in GitHub Desktop.
Magento2 devenv/NixOS development environment

Getting started

  1. Follow the installation guide for nix: https://devenv.sh/getting-started
  2. Add devenv.nix to your project root
  3. Add devenv.yaml to your project root. Note: I did this because I had issues with the 'unstable' dist and for ES you need to allow unfree packages

To start the processes:

devenv up

To go into the shell, but I would suggest using direnv: https://devenv.sh/automatic-shell-activation

devenv shell

Extra functions

Xdebug

Is enabled by default, and seems to be working out of the box in PhpStorm. I did set the PHP executable manually in Settings < PHP < CLI Interpreter < PHP Executable to:

/Users/louisdelooze/dev/<your_folder>/.devenv/profile/bin/php

And then I use the Xdebug browser extension, e.g.: Xdebug Helper for Firefox

Blackfire

If you want to add Blackfire:

{
...
    services.blackfire = {
        enable = true;
        client-id = "12xxx";
        client-token = "9be3xxx";
        server-id = "a513xxx";
        server-token = "9a2xxx";
    };
...
}    

and change:

...
    languages.php.package = pkgs.php82.buildEnv {
        extensions = { all, enabled }: with all; enabled ++ [ xdebug xsl redis imagick blackfire ];
...        
{ pkgs, config, ... }:
let
opensearch-with-plugins = pkgs.opensearch.overrideAttrs (old: {
# Workaround for packaging bug (deleting opensearch-cli breaks opensearch-plugin command)
installPhase = builtins.replaceStrings ["rm $out/bin/opensearch-cli\n"] [""] old.installPhase;
postInstall = ''
$out/bin/opensearch-plugin install analysis-icu analysis-phonetic
'';
});
in
{
packages = [ pkgs.git pkgs.gnupatch pkgs.n98-magerun2 opensearch-with-plugins pkgs.imagemagick pkgs.ghostscript];
languages.php.enable = true;
languages.php.package = pkgs.php82.buildEnv {
extensions = { all, enabled }: with all; enabled ++ [ xdebug xsl redis imagick ];
extraConfig = ''
memory_limit = 5G
opcache.memory_consumption = 256M
opcache.interned_strings_buffer = 20
xdebug.mode = debug
xdebug.discover_client_host = 1
xdebug.client_host = 127.0.0.1
'';
};
languages.php.fpm.pools.web = {
settings = {
"clear_env" = "no";
"pm" = "dynamic";
"pm.max_children" = 5;
"pm.start_servers" = 2;
"pm.min_spare_servers" = 1;
"pm.max_spare_servers" = 5;
};
};
services.mailhog.enable = true;
certificates = [
"magento.test"
];
hosts = {
"magento.test" = [ "127.0.0.1" "::1" ];
};
services.caddy.enable = true;
services.caddy.virtualHosts."magento.test" = {
extraConfig = ''
tls ${config.env.DEVENV_STATE}/mkcert/magento.test.pem ${config.env.DEVENV_STATE}/mkcert/magento.test-key.pem
root * pub
php_fastcgi unix/${config.languages.php.fpm.pools.web.socket}
file_server
@blocked {
path /media/customer/* /media/downloadable/* /media/import/* /media/custom_options/* /errors/*
}
respond @blocked 403
@notfound {
path_regexp reg_notfound \/\..*$|\/errors\/.*\.xml$|theme_customization\/.*\.xml
}
respond @notfound 404
@staticPath path_regexp reg_static ^/static/(version\d*/)?(.*)$
handle @staticPath {
@static file /static/{re.reg_static.2}
rewrite @static /static/{re.reg_static.2}
@dynamic not file /static/{re.reg_static.2}
rewrite @dynamic /static.php?resource={re.reg_static.2}
}
@mediaPath path_regexp reg_media ^/media/(.*)$
handle @mediaPath {
@static file /media/{re.reg_media.1}
rewrite @static /media/{re.reg_media.1}
@dynamic not file /media/{re.reg_media.1}
rewrite @dynamic /get.php?resource={re.reg_media.1}
}
'';
};
services.mysql = {
enable = true;
package = pkgs.percona-server_8_0; # Match with production, for Hypernode I use mariadb_106
initialDatabases = [{ name = "db"; }];
ensureUsers = [
{
name = "db";
password = "db";
ensurePermissions = { "*.*" = "ALL PRIVILEGES"; };
}
];
settings.mysqld.port = 3306;
};
services.opensearch = {
enable = true; # Must be set to false when using ES
package = opensearch-with-plugins;
};
services.elasticsearch = {
enable = false; # Can be set to true to use ES
};
scripts.magerun2.exec = ''
${pkgs.php82}/bin/php -dmemory_limit=5G ${pkgs.n98-magerun2}/bin/n98-magerun2 "$@"
'';
}
inputs:
nixpkgs:
url: github:NixOS/nixpkgs/nixos-25.05
nixpkgs:
allowUnfree: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment