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")