From 90331e7174ac20a5475f431363edf58bb145a5f4 Mon Sep 17 00:00:00 2001 From: Hugo Alliaume Date: Fri, 3 Jul 2026 10:20:57 +0200 Subject: [PATCH] Add support for Nix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this change, the Symfony CLI was not able to find all PHP versions I installed on my machine through Nix. With this PR, all my PHP versions are now correctly discovered: ``` symfony-cli on  main via 🐳 orbstack via 🐹 v1.26.4 took 2s ➜ go build symfony-cli on  main via 🐳 orbstack via 🐹 v1.26.4 ➜ ./symfony-cli local:php:list +---------+------------------------------------------------------------------------+---------+-------------+-------------+---------+---------+ | Version | Directory | PHP | PHP | PHP | Server | System? | | | | CLI | FPM | CGI | | | +---------+------------------------------------------------------------------------+---------+-------------+-------------+---------+---------+ | 8.1.34 | /nix/store/0b124alj3m71nj2kz4mvh3yph729g45f-php-with-extensions-8.1.34 | bin/php | bin/php-fpm | bin/php-cgi | PHP FPM | | | 8.2.31 | /nix/store/h4q20jqavc40gcy8nlxn7r826b15cmy6-php-with-extensions-8.2.31 | bin/php | bin/php-fpm | bin/php-cgi | PHP FPM | | | 8.3.31 | /nix/store/xxzf9zv1rv95bjjmbrdkc2hyb3h4lb31-php-with-extensions-8.3.31 | bin/php | bin/php-fpm | bin/php-cgi | PHP FPM | | | 8.4.22 | /nix/store/d8wzkxvwhp0vd8aizgrk8aq0cykcsgik-php-with-extensions-8.4.22 | bin/php | bin/php-fpm | bin/php-cgi | PHP FPM | * | | 8.5.7 | /nix/store/7grs0mlr1nxjxjmw5iyk3mqpfsr7lwi6-php-with-extensions-8.5.7 | bin/php | bin/php-fpm | bin/php-cgi | PHP FPM | | +---------+------------------------------------------------------------------------+---------+-------------+-------------+---------+---------+ ``` --- discovery_others.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/discovery_others.go b/discovery_others.go index b0051e5..e947d83 100644 --- a/discovery_others.go +++ b/discovery_others.go @@ -24,6 +24,7 @@ package phpstore import ( "bytes" + "os" "os/exec" "path/filepath" "regexp" @@ -66,6 +67,20 @@ func (s *PHPStore) doDiscover() { s.discoverFromDir(prefix, nil, regexp.MustCompile(`^php/(?:[\d\._]+)$`), "homebrew") } + // Nix (https://nixos.org/): PHP built with its extensions is stored as + // /nix/store/-php-with-extensions-. Because /nix/store can + // hold thousands of unrelated packages, glob the matching entries directly + // instead of walking the whole tree. + if dirs, err := filepath.Glob("/nix/store/*-php-with-extensions-*"); err == nil { + for _, dir := range dirs { + // skip .drv files and any other non-directory matches + if fi, err := os.Stat(dir); err != nil || !fi.IsDir() { + continue + } + s.addFromDir(dir, nil, "Nix") + } + } + if runtime.GOOS == "darwin" { // Liip PHP https://php-osx.liip.ch/ (pattern example: php5-7.2.0RC1-20170907-205032/bin/php) s.discoverFromDir("/usr/local", nil, regexp.MustCompile(`^php5\-[\d\.]+(?:RC|BETA)?\d*\-\d+\-\d+$`), "Liip PHP")