|
1 | 1 | package mise |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "encoding/json" |
5 | 4 | "errors" |
6 | 5 | "fmt" |
7 | 6 | "os" |
@@ -127,6 +126,7 @@ func (m *MiseToolProvider) InstallTool(tool provider.ToolRequest) (provider.Tool |
127 | 126 | } |
128 | 127 |
|
129 | 128 | if !useNix { |
| 129 | + // Nix already checks version existence previously |
130 | 130 | versionExists, err := m.versionExists(tool.ToolName, tool.UnparsedVersion) |
131 | 131 | if err != nil { |
132 | 132 | return provider.ToolInstallResult{}, fmt.Errorf("check if version exists: %w", err) |
@@ -224,7 +224,9 @@ func (m *MiseToolProvider) shouldUseNixPkgs(tool provider.ToolRequest) bool { |
224 | 224 | return false |
225 | 225 | } |
226 | 226 |
|
227 | | - available, err := availableInNixIndex(tool.ToolName, tool.UnparsedVersion) |
| 227 | + nameWithBackend := provider.ToolID(fmt.Sprintf("nixpkgs:%s", tool.ToolName)) |
| 228 | + |
| 229 | + available, err := m.versionExists(nameWithBackend, tool.UnparsedVersion) |
228 | 230 | if err != nil || !available { |
229 | 231 | log.Warnf("Failed to check nixpkgs index for %s@%s: %v. Falling back to legacy installation.", tool.ToolName, tool.UnparsedVersion, err) |
230 | 232 | return false |
@@ -306,47 +308,6 @@ func (m *MiseToolProvider) getNixpkgsPlugin() error { |
306 | 308 | return nil |
307 | 309 | } |
308 | 310 |
|
309 | | -type nixpkgsIndex struct { |
310 | | - Pkgs map[string]map[string]interface{} `json:"pkgs"` |
311 | | -} |
312 | | - |
313 | | -func availableInNixIndex(toolName provider.ToolID, version string) (bool, error) { |
314 | | - // Find the index file |
315 | | - indexPath, err := findIndexPath() |
316 | | - if err != nil { |
317 | | - return false, err |
318 | | - } |
319 | | - |
320 | | - // Read the index file |
321 | | - data, err := os.ReadFile(indexPath) |
322 | | - if err != nil { |
323 | | - return false, fmt.Errorf("read index file: %w", err) |
324 | | - } |
325 | | - |
326 | | - // Parse JSON |
327 | | - var index nixpkgsIndex |
328 | | - if err := json.Unmarshal(data, &index); err != nil { |
329 | | - return false, fmt.Errorf("parse index JSON: %w", err) |
330 | | - } |
331 | | - |
332 | | - // Check if tool exists |
333 | | - toolVersions, toolExists := index.Pkgs[string(toolName)] |
334 | | - if !toolExists { |
335 | | - log.Debugf("[TOOLPROVIDER] Tool %s not found in nixpkgs index", toolName) |
336 | | - return false, nil |
337 | | - } |
338 | | - |
339 | | - // Check if version exists |
340 | | - _, versionExists := toolVersions[version] |
341 | | - if !versionExists { |
342 | | - log.Debugf("[TOOLPROVIDER] Version %s not found for tool %s in nixpkgs index", version, toolName) |
343 | | - return false, nil |
344 | | - } |
345 | | - |
346 | | - log.Debugf("[TOOLPROVIDER] Tool %s version %s found in nixpkgs index", toolName, version) |
347 | | - return true, nil |
348 | | -} |
349 | | - |
350 | 311 | // cloneGitRepo clones a git repository to the specified path with minimal history. |
351 | 312 | func cloneGitRepo(repoURL, destPath string) error { |
352 | 313 | cmd := exec.Command("git", "clone", "--depth", "1", "--no-tags", repoURL, destPath) |
|
0 commit comments