Skip to content

Commit 3d1da79

Browse files
committed
feature #39 Add support for Nix (Kocal)
This PR was merged into the main branch. Discussion ---------- Add support for Nix 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 | | +---------+------------------------------------------------------------------------+---------+-------------+-------------+---------+---------+ ``` Commits ------- 90331e7 Add support for Nix
2 parents e123dee + 90331e7 commit 3d1da79

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

discovery_others.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package phpstore
2424

2525
import (
2626
"bytes"
27+
"os"
2728
"os/exec"
2829
"path/filepath"
2930
"regexp"
@@ -66,6 +67,20 @@ func (s *PHPStore) doDiscover() {
6667
s.discoverFromDir(prefix, nil, regexp.MustCompile(`^php/(?:[\d\._]+)$`), "homebrew")
6768
}
6869

70+
// Nix (https://nixos.org/): PHP built with its extensions is stored as
71+
// /nix/store/<hash>-php-with-extensions-<version>. Because /nix/store can
72+
// hold thousands of unrelated packages, glob the matching entries directly
73+
// instead of walking the whole tree.
74+
if dirs, err := filepath.Glob("/nix/store/*-php-with-extensions-*"); err == nil {
75+
for _, dir := range dirs {
76+
// skip .drv files and any other non-directory matches
77+
if fi, err := os.Stat(dir); err != nil || !fi.IsDir() {
78+
continue
79+
}
80+
s.addFromDir(dir, nil, "Nix")
81+
}
82+
}
83+
6984
if runtime.GOOS == "darwin" {
7085
// Liip PHP https://php-osx.liip.ch/ (pattern example: php5-7.2.0RC1-20170907-205032/bin/php)
7186
s.discoverFromDir("/usr/local", nil, regexp.MustCompile(`^php5\-[\d\.]+(?:RC|BETA)?\d*\-\d+\-\d+$`), "Liip PHP")

0 commit comments

Comments
 (0)