Skip to content

Commit 4e672c5

Browse files
authored
call nix.System directly from lock.lockfile (#1245)
## Summary Removes the workaround hack I had made ## How was it tested? compiles
1 parent b6b196b commit 4e672c5

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

internal/impl/devbox.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919

2020
"github.com/pkg/errors"
2121
"github.com/samber/lo"
22-
"go.jetpack.io/devbox/internal/boxcli/featureflag"
2322
"go.jetpack.io/devbox/internal/devpkg"
2423
"go.jetpack.io/devbox/internal/impl/generate"
2524
"go.jetpack.io/devbox/internal/shellgen"
@@ -91,16 +90,7 @@ func Open(opts *devopt.Opts) (*Devbox, error) {
9190
pure: opts.Pure,
9291
}
9392

94-
// TODO savil: this is bad for perf, and so remove before enabling feature.
95-
// this hack is to workaround an import cycle: lock -> nix -> lock
96-
userSystem := ""
97-
if featureflag.RemoveNixpkgs.Enabled() {
98-
userSystem, err = nix.System()
99-
if err != nil {
100-
return nil, err
101-
}
102-
}
103-
lock, err := lock.GetFile(box, searcher.Client(), userSystem)
93+
lock, err := lock.GetFile(box, searcher.Client())
10494
if err != nil {
10595
return nil, err
10696
}

internal/lock/lockfile.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/samber/lo"
1414
"go.jetpack.io/devbox/internal/boxcli/featureflag"
1515
"go.jetpack.io/devbox/internal/devpkg/devpkgutil"
16+
"go.jetpack.io/devbox/internal/nix"
1617

1718
"go.jetpack.io/devbox/internal/cuecfg"
1819
)
@@ -28,8 +29,6 @@ type File struct {
2829

2930
// Packages is keyed by "canonicalName@version"
3031
Packages map[string]*Package `json:"packages"`
31-
32-
system string
3332
}
3433

3534
type Package struct {
@@ -50,15 +49,13 @@ type SystemInfo struct {
5049
ToHash string `json:"to_hash,omitempty"`
5150
}
5251

53-
func GetFile(project devboxProject, resolver resolver, system string) (*File, error) {
52+
func GetFile(project devboxProject, resolver resolver) (*File, error) {
5453
lockFile := &File{
5554
devboxProject: project,
5655
resolver: resolver,
5756

5857
LockFileVersion: lockFileVersion,
5958
Packages: map[string]*Package{},
60-
61-
system: system,
6259
}
6360
err := cuecfg.ParseFile(lockFilePath(project), lockFile)
6461
if errors.Is(err, fs.ErrNotExist) {
@@ -91,10 +88,15 @@ func (l *File) Remove(pkgs ...string) error {
9188
func (l *File) Resolve(pkg string) (*Package, error) {
9289
entry, hasEntry := l.Packages[pkg]
9390

91+
userSystem, err := nix.System()
92+
if err != nil {
93+
return nil, err
94+
}
95+
9496
// If the package's system info is missing, we need to resolve it again.
9597
needsSysInfo := false
9698
if hasEntry && featureflag.RemoveNixpkgs.Enabled() {
97-
needsSysInfo = entry.Systems[l.system] == nil
99+
needsSysInfo = entry.Systems[userSystem] == nil
98100
}
99101

100102
if !hasEntry || entry.Resolved == "" || needsSysInfo {

0 commit comments

Comments
 (0)