I maintain a project that still uses PHP 7.4 (long story) so I need to build out my local environment with that version. Sourcing a Nix package for PHP 7.4 isn’t an issue; the nix-phps repository maintains PHP 5.6-PHP 8.4. The tricky part was adding that package to my local devenv.sh environment. Devenv supports PHP, but by default the PHP versions are limited to what’s in the devenv-nixpkgs repository, which starts at PHP 8.0.
I went down a few blind alleys, followed some outdated documentation, and generally overthought this. Devenv has awareness of older PHP versions; they’re simply not enabled by default. The first thing you need to do is enable the nix-phps repository. You can do that with this command:
1 | devenv inputs add phps github:fossar/nix-phps --follows nixpkgs |
That adds the following block to your devenv.yaml
file:
1 | phps: |
I thought that I need to muck around with inputs and imports, but I didn’t, because the devenv PHP support can interpret a request for an older version and will look for the nix-phps repository if you’ve enabled it. This is what a working PHP language block looks like:
1 | languages.php = { |
Declaring the version is enough; I don’t need to specify the package itself. I also don’t need to declare the extension within the buildEnv
argument because I did it in languages.php.extensions
.
And that’s it:
1 | (nix:devenv-shell-env) (devenv) $ php -v |