How PHP Developers can create robust and reproducible applications with Nix.

https://www.oliverdavies.uk

Download PDF

Download EPUB

Copyright © 2025 Oliver Davies (opdavies). All rights reserved.

The code portions of this book are dedicated to the public domain under the terms of the Creative Commons Zero (CC0 1.0 Universal) license (https://creativecommons.org/publicdomain/zero/1.0).

This means you are free to copy, modify, distribute the code portions only, even for commercial purposes, without asking permission, and without saying where you got them. This is so there is no fear your creations are your own after learning to code using them.

The non-code prose and images are licensed under the more restrictive Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License (CC BY-NC-ND 4.0) (https://creativecommons.org/licenses/by-nc-nd/4.0).

This means that no non-code prose or image from the book may be reproduced, distributed, or transmitted in any form or by any means, without the prior written permission of the copyright holder. This includes remaking the same content in different formats such as PDF or EPUB since these fall under the definition of derived works. This restriction is primarily in place to ensure outdated copies are not redistributed given the frequent updates expected.

"Nix for PHP Developers" is a legal trademark of Oliver Davies (opdavies) but can be used freely to refer to this book without limitation. To avoid potential confusion, intentionally using this trademark to refer to other projects - free or proprietary - is prohibited.

About the author

Oliver Davies is a self-taught Software Developer based in the UK.

He learned to code in 2007 by building a website for a local Tae Kwon-Do School.

After developing the initial version with HTML and CSS, he learned PHP and MySQL in 2008 before adopting Drupal as his content management system of choice.

Other ways to install PHP

Coming soon…​

Different versions of PHP for different projects

Coming soon…​

What is Nix?

The language

Coming soon…​

The package manager

Coming soon…​

The build tool

Coming soon…​

The operating system (NixOS)

Coming soon…​

What are the benefits of using Nix?

Coming soon…​

Imperative vs. declarative

Coming soon…​

What are dev shells?

# shell.nix

{
  pkgs ? import <nixpkgs> { },
}:

pkgs.mkShell {
  packages = with pkgs; [
    php
    phpPackages.composer
    phpactor
  ];
}

dev shells and direnv

Using a local flake:

use flake .

Remote dev shells

Using a remote flake:

You can use a flake.nix flake in any Git repository, not just the directory you’re in.

It can be in a different local directory or a remote Git repository.

For example, you can add this to use the php84 dev shell within my dev-shells repository:

use flake "git+https://code.oliverdavies.uk/opdavies/dev-shells#php84"

This will install PHP 8.4, Composer and Phpactor without needing to create a bespoke flake.nix.

If you’re referencing a GitHub repository, you can use the shorter github:username/repo format instead of the full repository URL.

What are Flakes?

Coming soon…​

Flake templates

Coming soon…​

Configuring PHP with Nix

Coming soon…​

Managing services without NixOS

Coming soon…​

Building derivations of PHP applications

Coming soon…​

Nix vs. Composer

Coming soon…​

Other usages for Nix

Coming soon…​

Organising Nix configurations

Coming soon…​