MCPcopy Index your code
hub / github.com/jetify-com/devbox / saveToNixpkgsCommitFile

Function saveToNixpkgsCommitFile

internal/nix/nixpkgs.go:73–106  ·  view source on GitHub ↗
(commit string, commitToLocation map[string]string)

Source from the content-addressed store, hash-verified

71}
72
73func 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
108func nixpkgsCommitFilePath() string {
109 cacheDir := xdg.CacheSubpath("devbox")

Callers 1

EnsureNixpkgsPrefetchedFunction · 0.85

Calls 5

FlakeNixpkgsFunction · 0.85
nixpkgsCommitFilePathFunction · 0.85
IsMethod · 0.80
CommandFunction · 0.70
OutputMethod · 0.45

Tested by

no test coverage detected