@@ -21,6 +21,7 @@ import (
2121 "go.jetpack.io/devbox/internal/devpkg/pkgtype"
2222 "go.jetpack.io/devbox/internal/lock"
2323 "go.jetpack.io/devbox/internal/nix"
24+ "go.jetpack.io/devbox/nix/flake"
2425 "go.jetpack.io/devbox/plugins"
2526)
2627
@@ -45,7 +46,7 @@ type Package struct {
4546 //
4647 // This is done for performance reasons. Some commands don't require the
4748 // fully-resolved package, so we don't want to waste time computing it.
48- installable FlakeInstallable
49+ installable flake. Installable
4950
5051 // resolve resolves a Devbox package string to a Nix installable.
5152 //
@@ -152,7 +153,7 @@ func newPackage(raw string, isInstallable bool, locker lock.Locker) *Package {
152153 // or it's a flake installable. In some cases they're ambiguous
153154 // ("nixpkgs" is a devbox package and a flake). When that happens, we
154155 // assume a Devbox package.
155- parsed , err := ParseFlakeInstallable (raw )
156+ parsed , err := flake . ParseInstallable (raw )
156157 if err != nil || isAmbiguous (raw , parsed ) {
157158 pkg .IsDevboxPackage = true
158159 pkg .resolve = sync .OnceValue (func () error { return resolve (pkg ) })
@@ -169,21 +170,21 @@ func newPackage(raw string, isInstallable bool, locker lock.Locker) *Package {
169170// isAmbiguous returns true if a package string could be a Devbox package or
170171// a flake installable. For example, "nixpkgs" is both a Devbox package and a
171172// flake.
172- func isAmbiguous (raw string , parsed FlakeInstallable ) bool {
173+ func isAmbiguous (raw string , parsed flake. Installable ) bool {
173174 // Devbox package strings never have a #attr_path in them.
174175 if parsed .AttrPath != "" {
175176 return false
176177 }
177178
178179 // Indirect installables must have a "flake:" scheme to disambiguate
179180 // them from legacy (unversioned) devbox package strings.
180- if parsed .Ref .Type == FlakeTypeIndirect {
181+ if parsed .Ref .Type == flake . TypeIndirect {
181182 return ! strings .HasPrefix (raw , "flake:" )
182183 }
183184
184185 // Path installables must have a "path:" scheme, start with "/" or start
185186 // with "./" to disambiguate them from devbox package strings.
186- if parsed .Ref .Type == FlakeTypePath {
187+ if parsed .Ref .Type == flake . TypePath {
187188 if raw [0 ] == '.' || raw [0 ] == '/' {
188189 return false
189190 }
@@ -208,16 +209,16 @@ func resolve(pkg *Package) error {
208209 if inCache , err := pkg .IsInBinaryCache (); err == nil && inCache {
209210 pkg .storePath = resolved .Systems [nix .System ()].StorePath
210211 }
211- parsed , err := ParseFlakeInstallable (resolved .Resolved )
212+ parsed , err := flake . ParseInstallable (resolved .Resolved )
212213 if err != nil {
213214 return err
214215 }
215216 pkg .setInstallable (parsed , pkg .lockfile .ProjectDir ())
216217 return nil
217218}
218219
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 ) {
221222 i .Ref .Path = filepath .Join (projectDir , i .Ref .Path )
222223 }
223224 p .installable = i
@@ -234,9 +235,9 @@ func (p *Package) FlakeInputName() string {
234235
235236 result := ""
236237 switch p .installable .Ref .Type {
237- case FlakeTypePath :
238+ case flake . TypePath :
238239 result = filepath .Base (p .installable .Ref .Path ) + "-" + p .Hash ()
239- case FlakeTypeGitHub :
240+ case flake . TypeGitHub :
240241 isNixOS := strings .ToLower (p .installable .Ref .Owner ) == "nixos"
241242 isNixpkgs := isNixOS && strings .ToLower (p .installable .Ref .Repo ) == "nixpkgs"
242243 if isNixpkgs && p .IsDevboxPackage {
@@ -300,8 +301,8 @@ func (p *Package) Installable() (string, error) {
300301// FlakeInstallable returns a flake installable. The raw string must contain
301302// a valid flake reference parsable by ParseFlakeRef, optionally followed by an
302303// #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 )
305306}
306307
307308// urlForInstall is used during `nix profile install`.
@@ -446,7 +447,7 @@ var ErrCannotBuildPackageOnSystem = errors.New("unable to build for system")
446447
447448func (p * Package ) Hash () string {
448449 sum := ""
449- if p .installable .Ref .Type == FlakeTypePath {
450+ if p .installable .Ref .Type == flake . TypePath {
450451 // For local flakes, use content hash of the flake.nix file to ensure
451452 // user always gets newest flake.
452453 sum , _ = cachehash .File (filepath .Join (p .installable .Ref .Path , "flake.nix" ))
0 commit comments