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.
Here’s the flake.nix in its entirety:
1 | { |
This flake builds on the code I demonstrated in This blog post was written with Hexo and Nix. First, to get PHP 7.4 I need to bring in the nix-phps repository. First, I add it to the list of inputs:
1 | inputs = { |
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:
1 | phps.packages.${system}.php74 |
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.92.0 (build bf62e55) |
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.