MCPcopy
hub / github.com/jetify-com/devbox / flakeInputs

Function flakeInputs

internal/shellgen/flake_input.go:145–196  ·  view source on GitHub ↗

flakeInputs returns a list of flake inputs for the top level flake.nix created by devbox. We map packages to the correct flake and attribute path and group flakes by URL to avoid duplication. All inputs should be locked i.e. have a commit hash and always resolve to the same package/version. Note: in

(ctx context.Context, packages []*devpkg.Package)

Source from the content-addressed store, hash-verified

143// Note: inputs returned by this function include plugin packages. (php only for now)
144// It's not entirely clear we always want to add plugin packages to the top level
145func flakeInputs(ctx context.Context, packages []*devpkg.Package) []flakeInput {
146 defer trace.StartRegion(ctx, "flakeInputs").End()
147
148 var flakeInputs keyedSlice
149 for _, pkg := range packages {
150 // Non-nix packages (e.g. runx) don't belong in the flake
151 if !pkg.IsNix() {
152 continue
153 }
154
155 // Don't include cached packages (like local or remote flakes)
156 // that can be fetched from a Binary Cache Store.
157 // TODO(savil): return error?
158 cached, err := pkg.IsInBinaryCache()
159 if err != nil {
160 slog.Error("error checking if package is in binary cache", "err", err)
161 }
162 if err == nil && cached {
163 continue
164 }
165
166 // Packages that need a glibc patch are assigned to the special
167 // glibc-patched flake input. This input refers to the
168 // glibc-patch.nix flake.
169 if pkg.Patch {
170 nixpkgsGlibc := flakeInputs.getOrAppend(glibcPatchFlakeRef.String())
171 nixpkgsGlibc.Name = "glibc-patch"
172 nixpkgsGlibc.Ref = glibcPatchFlakeRef
173 nixpkgsGlibc.Packages = append(nixpkgsGlibc.Packages, pkg)
174 continue
175 }
176
177 installable, err := pkg.FlakeInstallable()
178 if err != nil {
179 // I don't think this should happen at this point. The
180 // packages should already be resolved to valid nixpkgs
181 // packages.
182 slog.Debug("error resolving package to flake installable", "err", err)
183 continue
184 }
185 flake := flakeInputs.getOrAppend(installable.Ref.String())
186 flake.Name = pkg.FlakeInputName()
187 flake.Ref = installable.Ref
188
189 // TODO(gcurtis): is the uniqueness check necessary? We're
190 // comparing pointers.
191 if !slices.Contains(flake.Packages, pkg) {
192 flake.Packages = append(flake.Packages, pkg)
193 }
194 }
195 return flakeInputs.slice
196}
197
198// keyedSlice keys the elements of an append-only slice for fast lookups.
199type keyedSlice struct {

Callers 1

newFlakePlanFunction · 0.85

Calls 8

getOrAppendMethod · 0.95
EndMethod · 0.80
IsNixMethod · 0.80
IsInBinaryCacheMethod · 0.80
FlakeInstallableMethod · 0.80
FlakeInputNameMethod · 0.80
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected