@@ -21,6 +21,7 @@ import (
21
21
"go.jetpack.io/devbox/internal/devpkg/pkgtype"
22
22
"go.jetpack.io/devbox/internal/lock"
23
23
"go.jetpack.io/devbox/internal/nix"
24
+ "go.jetpack.io/devbox/nix/flake"
24
25
"go.jetpack.io/devbox/plugins"
25
26
)
26
27
@@ -45,7 +46,7 @@ type Package struct {
45
46
//
46
47
// This is done for performance reasons. Some commands don't require the
47
48
// fully-resolved package, so we don't want to waste time computing it.
48
- installable FlakeInstallable
49
+ installable flake. Installable
49
50
50
51
// resolve resolves a Devbox package string to a Nix installable.
51
52
//
@@ -152,7 +153,7 @@ func newPackage(raw string, isInstallable bool, locker lock.Locker) *Package {
152
153
// or it's a flake installable. In some cases they're ambiguous
153
154
// ("nixpkgs" is a devbox package and a flake). When that happens, we
154
155
// assume a Devbox package.
155
- parsed , err := ParseFlakeInstallable (raw )
156
+ parsed , err := flake . ParseInstallable (raw )
156
157
if err != nil || isAmbiguous (raw , parsed ) {
157
158
pkg .IsDevboxPackage = true
158
159
pkg .resolve = sync .OnceValue (func () error { return resolve (pkg ) })
@@ -169,21 +170,21 @@ func newPackage(raw string, isInstallable bool, locker lock.Locker) *Package {
169
170
// isAmbiguous returns true if a package string could be a Devbox package or
170
171
// a flake installable. For example, "nixpkgs" is both a Devbox package and a
171
172
// flake.
172
- func isAmbiguous (raw string , parsed FlakeInstallable ) bool {
173
+ func isAmbiguous (raw string , parsed flake. Installable ) bool {
173
174
// Devbox package strings never have a #attr_path in them.
174
175
if parsed .AttrPath != "" {
175
176
return false
176
177
}
177
178
178
179
// Indirect installables must have a "flake:" scheme to disambiguate
179
180
// them from legacy (unversioned) devbox package strings.
180
- if parsed .Ref .Type == FlakeTypeIndirect {
181
+ if parsed .Ref .Type == flake . TypeIndirect {
181
182
return ! strings .HasPrefix (raw , "flake:" )
182
183
}
183
184
184
185
// Path installables must have a "path:" scheme, start with "/" or start
185
186
// with "./" to disambiguate them from devbox package strings.
186
- if parsed .Ref .Type == FlakeTypePath {
187
+ if parsed .Ref .Type == flake . TypePath {
187
188
if raw [0 ] == '.' || raw [0 ] == '/' {
188
189
return false
189
190
}
@@ -208,16 +209,16 @@ func resolve(pkg *Package) error {
208
209
if inCache , err := pkg .IsInBinaryCache (); err == nil && inCache {
209
210
pkg .storePath = resolved .Systems [nix .System ()].StorePath
210
211
}
211
- parsed , err := ParseFlakeInstallable (resolved .Resolved )
212
+ parsed , err := flake . ParseInstallable (resolved .Resolved )
212
213
if err != nil {
213
214
return err
214
215
}
215
216
pkg .setInstallable (parsed , pkg .lockfile .ProjectDir ())
216
217
return nil
217
218
}
218
219
219
- func (p * Package ) setInstallable (i FlakeInstallable , projectDir string ) {
220
- if i .Ref .Type == FlakeTypePath && ! filepath .IsAbs (i .Ref .Path ) {
220
+ func (p * Package ) setInstallable (i flake. Installable , projectDir string ) {
221
+ if i .Ref .Type == flake . TypePath && ! filepath .IsAbs (i .Ref .Path ) {
221
222
i .Ref .Path = filepath .Join (projectDir , i .Ref .Path )
222
223
}
223
224
p .installable = i
@@ -234,9 +235,9 @@ func (p *Package) FlakeInputName() string {
234
235
235
236
result := ""
236
237
switch p .installable .Ref .Type {
237
- case FlakeTypePath :
238
+ case flake . TypePath :
238
239
result = filepath .Base (p .installable .Ref .Path ) + "-" + p .Hash ()
239
- case FlakeTypeGitHub :
240
+ case flake . TypeGitHub :
240
241
isNixOS := strings .ToLower (p .installable .Ref .Owner ) == "nixos"
241
242
isNixpkgs := isNixOS && strings .ToLower (p .installable .Ref .Repo ) == "nixpkgs"
242
243
if isNixpkgs && p .IsDevboxPackage {
@@ -300,8 +301,8 @@ func (p *Package) Installable() (string, error) {
300
301
// FlakeInstallable returns a flake installable. The raw string must contain
301
302
// a valid flake reference parsable by ParseFlakeRef, optionally followed by an
302
303
// #attrpath and/or an ^output.
303
- func (p * Package ) FlakeInstallable () (FlakeInstallable , error ) {
304
- return ParseFlakeInstallable (p .Raw )
304
+ func (p * Package ) FlakeInstallable () (flake. Installable , error ) {
305
+ return flake . ParseInstallable (p .Raw )
305
306
}
306
307
307
308
// urlForInstall is used during `nix profile install`.
@@ -446,7 +447,7 @@ var ErrCannotBuildPackageOnSystem = errors.New("unable to build for system")
446
447
447
448
func (p * Package ) Hash () string {
448
449
sum := ""
449
- if p .installable .Ref .Type == FlakeTypePath {
450
+ if p .installable .Ref .Type == flake . TypePath {
450
451
// For local flakes, use content hash of the flake.nix file to ensure
451
452
// user always gets newest flake.
452
453
sum , _ = cachehash .File (filepath .Join (p .installable .Ref .Path , "flake.nix" ))
0 commit comments