Skip to content

Commit

Permalink
Update lockfile api for package source (#1266)
Browse files Browse the repository at this point in the history
## Summary
Update lockfile api for package source as suggested in
#1264 (comment)

## How was it tested?
devbox run build
devbox update
  • Loading branch information
LucilleH authored Jul 11, 2023
1 parent f6f94fe commit 89b6055
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 32 deletions.
2 changes: 1 addition & 1 deletion internal/devpkg/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/devpkg/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion internal/lock/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
31 changes: 3 additions & 28 deletions internal/lock/lockfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 <hash>-<name>-<version>
// <name> 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 <hash>-<name>-<version>
CAStorePath string `json:"ca_store_path,omitempty"`
}

func GetFile(project devboxProject) (*File, error) {
lockFile := &File{
devboxProject: project,
Expand Down Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions internal/lock/package.go
Original file line number Diff line number Diff line change
@@ -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 <hash>-<name>-<version>
// <name> 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 <hash>-<name>-<version>
CAStorePath string `json:"ca_store_path,omitempty"`
}

func (p *Package) GetSource() string {
if p == nil {
return ""
}
return p.Source
}

0 comments on commit 89b6055

Please sign in to comment.