(commit string, commitToLocation map[string]string)
| 71 | } |
| 72 | |
| 73 | func saveToNixpkgsCommitFile(commit string, commitToLocation map[string]string) error { |
| 74 | // Make a query to get the /nix/store path for this commit hash. |
| 75 | cmd := Command("flake", "prefetch", "--json", |
| 76 | FlakeNixpkgs(commit), |
| 77 | ) |
| 78 | out, err := cmd.Output(context.TODO()) |
| 79 | if err != nil { |
| 80 | return errors.WithStack(err) |
| 81 | } |
| 82 | |
| 83 | // read the json response |
| 84 | var prefetchData struct { |
| 85 | StorePath string `json:"storePath"` |
| 86 | } |
| 87 | if err := json.Unmarshal(out, &prefetchData); err != nil { |
| 88 | return errors.WithStack(err) |
| 89 | } |
| 90 | |
| 91 | // Ensure the nixpkgs commit file path exists so we can write an update to it |
| 92 | path := nixpkgsCommitFilePath() |
| 93 | err = os.MkdirAll(filepath.Dir(path), 0o755) |
| 94 | if err != nil && !errors.Is(err, fs.ErrExist) { |
| 95 | return errors.WithStack(err) |
| 96 | } |
| 97 | |
| 98 | // write to the map, jsonify it, and write that json to the nixpkgsCommit file |
| 99 | commitToLocation[commit] = prefetchData.StorePath |
| 100 | serialized, err := json.Marshal(commitToLocation) |
| 101 | if err != nil { |
| 102 | return errors.WithStack(err) |
| 103 | } |
| 104 | |
| 105 | return errors.WithStack(os.WriteFile(path, serialized, 0o644)) |
| 106 | } |
| 107 | |
| 108 | func nixpkgsCommitFilePath() string { |
| 109 | cacheDir := xdg.CacheSubpath("devbox") |
no test coverage detected