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)
| 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 |
| 145 | func 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. |
| 199 | type keyedSlice struct { |
no test coverage detected