2025-08-13 10:20:37 +01:00
|
|
|
[separator=::]
|
|
|
|
= Nix for PHP Developers
|
|
|
|
:author: Oliver Davies (opdavies)
|
|
|
|
:copyright: 2025 {author}
|
|
|
|
:creator: {author}
|
|
|
|
:description: How to use Nix as a PHP Developer.
|
|
|
|
:doctype: book
|
|
|
|
:email: oliver@oliverdavies.uk
|
2025-08-15 00:53:15 +01:00
|
|
|
:front-cover-image: image:cover.png[fit=fill]
|
2025-08-13 10:20:37 +01:00
|
|
|
:icons: font
|
|
|
|
:keywords: php software-development nix linux
|
|
|
|
:leveloffset: +1
|
|
|
|
:pygments-linenums-mode: table
|
|
|
|
:pygments-style: vs
|
|
|
|
:revdate: {date}
|
|
|
|
:revnumber: v0.0.1
|
|
|
|
:revremark: Under development
|
|
|
|
:sectlinks:
|
|
|
|
:sectnums!:
|
|
|
|
:source-highlighter: pygments
|
|
|
|
:toc-title: Table of Contents
|
|
|
|
:toc: left
|
|
|
|
:toclevels: 2
|
|
|
|
:xrefstyle: short
|
|
|
|
|
|
|
|
include::introduction/index.adoc[]
|
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
[[installing_php]]
|
|
|
|
= Other ways to install PHP
|
2025-08-13 10:20:37 +01:00
|
|
|
|
|
|
|
////
|
|
|
|
apt, yum, pacman, etc. System package managers.
|
|
|
|
Homebrew on macOS and Linux.
|
|
|
|
Docker, podman, DDEV (containers).
|
|
|
|
Valet/Herd?
|
|
|
|
Symfony CLI.
|
2025-08-14 09:35:01 +01:00
|
|
|
Is there an "official" way on php.net? https://www.php.net/manual/en/install.php
|
2025-08-13 10:20:37 +01:00
|
|
|
////
|
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
[[different_versions]]
|
|
|
|
= Different versions of PHP for different projects
|
2025-08-13 10:20:37 +01:00
|
|
|
|
|
|
|
////
|
|
|
|
Virtual machines.
|
|
|
|
Vagrant.
|
|
|
|
Containers.
|
|
|
|
Valet/Herd. Symfony CLI.
|
|
|
|
IAC - Ansible, etc.
|
|
|
|
nvm for PHP?
|
|
|
|
"virtual" environments, aka. ruby, python.
|
|
|
|
|
|
|
|
Why do you need a full operating system?
|
|
|
|
Why use something specific to a particular framework?
|
|
|
|
////
|
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
[[what_nix]]
|
|
|
|
= What is Nix?
|
2025-08-13 10:20:37 +01:00
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
[[nix_language]]
|
|
|
|
== The language
|
2025-08-13 10:20:37 +01:00
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
[[nix_package_manager]]
|
|
|
|
== The package manager
|
2025-08-13 10:20:37 +01:00
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
[[nix_build_tool]]
|
|
|
|
== The build tool
|
2025-08-13 10:20:37 +01:00
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
[[nixos]]
|
|
|
|
== The operating system (NixOS)
|
2025-08-13 10:20:37 +01:00
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
[[nix_benefits]]
|
|
|
|
= What are the benefits of using Nix?
|
2025-08-13 10:20:37 +01:00
|
|
|
|
|
|
|
////
|
|
|
|
Lightweight.
|
|
|
|
Simpler - no need for Makefiles or helper scripts.
|
|
|
|
More native feel.
|
|
|
|
One tool to work with everything.
|
|
|
|
Different languages and frameworks.
|
|
|
|
Agnostic package manager, works on different Linux distros as well as macOS.
|
|
|
|
Lots of available packages and operating system options.
|
|
|
|
Ecosystem of tools - e.g. Home Manager.
|
|
|
|
////
|
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
== Reproducible software, not just repeatable
|
2025-08-13 10:20:37 +01:00
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
== Imperative vs. declarative
|
2025-08-13 10:20:37 +01:00
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
[[dev_shells]]
|
|
|
|
= What are dev shells?
|
2025-08-13 10:20:37 +01:00
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
[[direnv]]
|
|
|
|
= dev shells and direnv
|
2025-08-13 10:20:37 +01:00
|
|
|
|
|
|
|
Using a local flake:
|
|
|
|
|
|
|
|
[source,bash]
|
|
|
|
----
|
|
|
|
use flake .
|
|
|
|
----
|
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
== Remote dev shells
|
2025-08-13 10:20:37 +01:00
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
[source,bash]
|
|
|
|
----
|
|
|
|
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`.
|
|
|
|
|
|
|
|
[NOTE]
|
2025-08-14 09:35:01 +01:00
|
|
|
===
|
2025-08-13 10:20:37 +01:00
|
|
|
If you're referencing a GitHub repository, you can use the shorter `github:username/repo` format instead of the full repository URL.
|
2025-08-14 09:35:01 +01:00
|
|
|
===
|
2025-08-13 10:20:37 +01:00
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
[[what_flakes]]
|
|
|
|
= What are Flakes?
|
2025-08-13 10:20:37 +01:00
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
[[flake_templates]]
|
|
|
|
== Flake templates
|
2025-08-13 10:20:37 +01:00
|
|
|
|
|
|
|
////
|
|
|
|
flake-utils
|
|
|
|
flake-parts
|
|
|
|
////
|
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
[[configuring_php]]
|
|
|
|
= Configuring PHP with Nix
|
2025-08-13 10:20:37 +01:00
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
[[managing_services]]
|
|
|
|
= Managing services without NixOS
|
2025-08-13 10:20:37 +01:00
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
[[building_derivations]]
|
|
|
|
= Building derivations of PHP applications
|
2025-08-13 10:20:37 +01:00
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
[[nix_composer]]
|
|
|
|
= Nix vs. Composer
|
2025-08-13 10:20:37 +01:00
|
|
|
|
|
|
|
////
|
|
|
|
composer2nix
|
|
|
|
////
|
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
= Other usages for Nix
|
2025-08-13 10:20:37 +01:00
|
|
|
|
|
|
|
////
|
|
|
|
Homelab/Server
|
|
|
|
////
|
|
|
|
|
2025-08-14 09:35:01 +01:00
|
|
|
= Organising Nix configurations
|