diff --git a/internal/devpkg/package.go b/internal/devpkg/package.go index 99dd9bb6a54..6b80bc041c3 100644 --- a/internal/devpkg/package.go +++ b/internal/devpkg/package.go @@ -403,7 +403,7 @@ func (p *Package) Versioned() string { } func (p *Package) IsLegacy() bool { - return p.isDevboxPackage() && !p.isVersioned() && p.lockfile.Source(p.Raw) == "" + return p.isDevboxPackage() && !p.isVersioned() && p.lockfile.Get(p.Raw).GetSource() == "" } func (p *Package) LegacyToVersioned() string { diff --git a/internal/devpkg/package_test.go b/internal/devpkg/package_test.go index e0b3692fe25..7eba160cd3d 100644 --- a/internal/devpkg/package_test.go +++ b/internal/devpkg/package_test.go @@ -119,8 +119,8 @@ func (l *lockfile) LegacyNixpkgsPath(pkg string) string { ) } -func (l *lockfile) Source(pkg string) string { - return "" +func (l *lockfile) Get(pkg string) *lock.Package { + return nil } func (l *lockfile) Resolve(pkg string) (*lock.Package, error) { diff --git a/internal/lock/interfaces.go b/internal/lock/interfaces.go index e9f11ab9f44..98de11ac7db 100644 --- a/internal/lock/interfaces.go +++ b/internal/lock/interfaces.go @@ -11,8 +11,8 @@ type devboxProject interface { } type Locker interface { + Get(string) *Package LegacyNixpkgsPath(string) string ProjectDir() string Resolve(string) (*Package, error) - Source(string) string } diff --git a/internal/lock/lockfile.go b/internal/lock/lockfile.go index d1a254381e4..885d3b121fb 100644 --- a/internal/lock/lockfile.go +++ b/internal/lock/lockfile.go @@ -17,10 +17,6 @@ import ( ) const lockFileVersion = "1" -const ( - nixpkgSource string = "nixpkg" - devboxSearchSource string = "devbox-search" -) // Lightly inspired by package-lock.json type File struct { @@ -32,27 +28,6 @@ type File struct { Packages map[string]*Package `json:"packages"` } -type Package struct { - LastModified string `json:"last_modified,omitempty"` - PluginVersion string `json:"plugin_version,omitempty"` - Resolved string `json:"resolved,omitempty"` - Source string `json:"source,omitempty"` - Version string `json:"version,omitempty"` - // Systems is keyed by the system name - Systems map[string]*SystemInfo `json:"systems,omitempty"` -} - -type SystemInfo struct { - // StorePath is the input-addressed path for the nix package in /nix/store - // It is the cache key in the Binary Cache Store (cache.nixos.org) - // It is of the form -- - // may be different from the canonicalName so we store the full store path. - StorePath string `json:"store_path,omitempty"` - // CAStorePath is the content-addressed path for the nix package in /nix/store - // It is of the form -- - CAStorePath string `json:"ca_store_path,omitempty"` -} - func GetFile(project devboxProject) (*File, error) { lockFile := &File{ devboxProject: project, @@ -130,12 +105,12 @@ func (l *File) LegacyNixpkgsPath(pkg string) string { ) } -func (l *File) Source(pkg string) string { +func (l *File) Get(pkg string) *Package { entry, hasEntry := l.Packages[pkg] if !hasEntry || entry.Resolved == "" { - return "" + return nil } - return entry.Source + return entry } // This probably belongs in input.go but can't add it there because it will diff --git a/internal/lock/package.go b/internal/lock/package.go new file mode 100644 index 00000000000..cc61f275d8b --- /dev/null +++ b/internal/lock/package.go @@ -0,0 +1,37 @@ +// Copyright 2023 Jetpack Technologies Inc and contributors. All rights reserved. +// Use of this source code is governed by the license in the LICENSE file. + +package lock + +const ( + nixpkgSource string = "nixpkg" + devboxSearchSource string = "devbox-search" +) + +type Package struct { + LastModified string `json:"last_modified,omitempty"` + PluginVersion string `json:"plugin_version,omitempty"` + Resolved string `json:"resolved,omitempty"` + Source string `json:"source,omitempty"` + Version string `json:"version,omitempty"` + // Systems is keyed by the system name + Systems map[string]*SystemInfo `json:"systems,omitempty"` +} + +type SystemInfo struct { + // StorePath is the input-addressed path for the nix package in /nix/store + // It is the cache key in the Binary Cache Store (cache.nixos.org) + // It is of the form -- + // may be different from the canonicalName so we store the full store path. + StorePath string `json:"store_path,omitempty"` + // CAStorePath is the content-addressed path for the nix package in /nix/store + // It is of the form -- + CAStorePath string `json:"ca_store_path,omitempty"` +} + +func (p *Package) GetSource() string { + if p == nil { + return "" + } + return p.Source +}