@@ -2,6 +2,7 @@ package nixpkgs
22
33import (
44 "os"
5+ "os/exec"
56 "strings"
67
78 "github.com/bitrise-io/bitrise/v2/log"
@@ -13,19 +14,39 @@ const (
1314 PluginName = "nixpkgs"
1415)
1516
16- // TODO: check if Nix works at all
17-
1817func ShouldUseBackend (request provider.ToolRequest ) bool {
1918 if request .ToolName != "ruby" {
2019 log .Debugf ("[TOOLPROVIDER] The mise-nixpkgs backend is only enabled for Ruby for now. Using core plugin to install %s" , request .ToolName )
2120 return false
2221 }
2322
2423 value , ok := os .LookupEnv ("BITRISE_TOOLSETUP_FAST_INSTALL" )
25- if ok && strings .TrimSpace (value ) == "1" {
26- log .Debugf ("[TOOLPROVIDER] Using nixpkgs backend for %s as BITRISE_TOOLSETUP_FAST_INSTALL is set" , request .ToolName )
27- return true
24+ if ! ok || strings .TrimSpace (value ) != "1" {
25+ log .Debugf ("[TOOLPROVIDER] Using core mise plugin for %s" , request .ToolName )
26+ return false
27+ }
28+
29+ if ! isNixAvailable () {
30+ log .Debugf ("[TOOLPROVIDER] Nix is not available on the system, cannot use nixpkgs backend for %s" , request .ToolName )
31+ return false
32+ }
33+
34+ log .Debugf ("[TOOLPROVIDER] Using nixpkgs backend for %s as BITRISE_TOOLSETUP_FAST_INSTALL is set" , request .ToolName )
35+ return true
36+ }
37+
38+ func isNixAvailable () bool {
39+ _ , err := exec .LookPath ("nix" )
40+ if err != nil {
41+ return false
2842 }
29- log .Debugf ("[TOOLPROVIDER] Using core plugin for %s" , request .ToolName )
30- return false
43+
44+ cmd := exec .Command ("nix" , "--version" )
45+ out , err := cmd .CombinedOutput ()
46+ if err != nil {
47+ log .Debugf ("[TOOLPROVIDER] Exec nix --version: %s, output:\n %s" , err , out )
48+ return false
49+ }
50+
51+ return true
3152}
0 commit comments