Brief note on a nix flake that supports Node 20 and PHP 7.4. My use case is deploying an AWS CDK project that supports a Moodle 3.11 environment. I’m not version-limited on the Node version for CDK, but I need to start with PHP 7.4 to support the Moodle package code, though I’ll be moving to PHP 8.1 soon.
I also need to add it as an argument for the outputs:
1
outputs = { self, nixpkgs, phps }:
If I don’t, I’ll get an error:
1
error: function'outputs' called with unexpected argument 'phps'
Having done that, I can add the PHP packages to the package list. I didn’t find the nix-phps docs very helpful and it took some trial and error to get it right:
This installs PHP 7.4 with default extensions and also composer. The ${system} variable ensures that the correct architecture is used. I did install Cachix as part of this process; I think the extensions were still built locally. The end result works fine:
1 2 3 4 5 6
2.92.0 (build bf62e55) PHP 7.4.33 (cli) (built: Oct 24 2023 14:46:15) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies (nix:nix-shell-env)
After all the difficult experiences I’ve had with building PHP on a Mac via either phpbrew or phpenv, the relative ease of the build process (Nix learning curve aside) is welcome.