Skip to content

Commit db26125

Browse files
committed
Merge branch 'main' into landau/fix-release
2 parents 4b73a83 + 0515891 commit db26125

File tree

9 files changed

+552
-530
lines changed

9 files changed

+552
-530
lines changed

.github/workflows/cli-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ jobs:
147147
uses: easimon/maximize-build-space@v8
148148
if: matrix.os == 'ubuntu-latest'
149149
with:
150-
root-reserve-mb: 40000
150+
root-reserve-mb: 32768
151151
temp-reserve-mb: 10000
152152
remove-dotnet: true
153153
remove-android: true

internal/devbox/devbox.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ func (d *Devbox) RunScript(ctx context.Context, cmdName string, cmdArgs []string
233233
return err
234234
}
235235

236+
lock.SetIgnoreShellMismatch(true)
236237
env, err := d.ensureStateIsUpToDateAndComputeEnv(ctx)
237238
if err != nil {
238239
return err

internal/devbox/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (d *Devbox) attemptToUpgradeFlake(pkg *devpkg.Package) error {
183183

184184
err = nixprofile.ProfileUpgrade(profilePath, pkg, d.lockfile)
185185
if err != nil {
186-
ux.Ferror(
186+
ux.Fwarning(
187187
d.stderr,
188188
"Failed to upgrade %s using `nix profile upgrade`: %s\n",
189189
pkg.Raw,

internal/devpkg/flakeref_test.go

Lines changed: 0 additions & 394 deletions
This file was deleted.

internal/devpkg/package.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

447448
func (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"))

internal/lock/statehash.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"go.jetpack.io/devbox/internal/cuecfg"
1414
)
1515

16+
var ignoreShellMismatch = false
17+
1618
// stateHashFile is a non-shared lock file that helps track the state of the
1719
// local devbox environment. It contains hashes that may not be the same across
1820
// machines (e.g. manifest hash).
@@ -46,6 +48,12 @@ func UpdateAndSaveStateHashFile(args UpdateStateHashFileArgs) error {
4648
return cuecfg.WriteFile(stateHashFilePath(args.ProjectDir), newLock)
4749
}
4850

51+
// SetIgnoreShellMismatch is used to disable the shell comparison when checking
52+
// if the state is up to date. This is useful when we don't load shellrc (e.g. running)
53+
func SetIgnoreShellMismatch(ignore bool) {
54+
ignoreShellMismatch = ignore
55+
}
56+
4957
func isStateUpToDate(args UpdateStateHashFileArgs) (bool, error) {
5058
filesystemStateHash, err := readStateHashFile(args.ProjectDir)
5159
if err != nil {
@@ -56,6 +64,10 @@ func isStateUpToDate(args UpdateStateHashFileArgs) (bool, error) {
5664
return false, err
5765
}
5866

67+
if ignoreShellMismatch {
68+
filesystemStateHash.IsFish = newStateHash.IsFish
69+
}
70+
5971
return *filesystemStateHash == *newStateHash, nil
6072
}
6173

internal/nix/nix.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/pkg/errors"
1919
"go.jetpack.io/devbox/internal/boxcli/featureflag"
2020
"go.jetpack.io/devbox/internal/boxcli/usererr"
21+
"go.jetpack.io/devbox/internal/redact"
2122

2223
"go.jetpack.io/devbox/internal/debug"
2324
)
@@ -63,11 +64,16 @@ func (*Nix) PrintDevEnv(ctx context.Context, args *PrintDevEnvArgs) (*PrintDevEn
6364
}
6465
}
6566

67+
flakeDirResolved, err := filepath.EvalSymlinks(args.FlakeDir)
68+
if err != nil {
69+
return nil, errors.WithStack(err)
70+
}
71+
6672
if len(data) == 0 {
6773
cmd := exec.CommandContext(
6874
ctx,
6975
"nix", "print-dev-env",
70-
args.FlakeDir,
76+
"path:"+flakeDirResolved,
7177
)
7278
cmd.Args = append(cmd.Args, ExperimentalFlags()...)
7379
cmd.Args = append(cmd.Args, "--json")
@@ -76,15 +82,15 @@ func (*Nix) PrintDevEnv(ctx context.Context, args *PrintDevEnvArgs) (*PrintDevEn
7682
if insecure, insecureErr := IsExitErrorInsecurePackage(err, "" /*installable*/); insecure {
7783
return nil, insecureErr
7884
} else if err != nil {
79-
return nil, errors.Wrapf(err, "Command: %s", cmd)
85+
return nil, redact.Errorf("nix print-dev-env --json \"path:%s\": %w", flakeDirResolved, err)
8086
}
8187

8288
if err := json.Unmarshal(data, &out); err != nil {
83-
return nil, errors.WithStack(err)
89+
return nil, redact.Errorf("unmarshal nix print-dev-env output: %w", redact.Safe(err))
8490
}
8591

8692
if err = savePrintDevEnvCache(args.PrintDevEnvCachePath, out); err != nil {
87-
return nil, errors.WithStack(err)
93+
return nil, redact.Errorf("savePrintDevEnvCache: %w", redact.Safe(err))
8894
}
8995
}
9096

@@ -175,12 +181,13 @@ func Version() (string, error) {
175181
cmd := command("--version")
176182
outBytes, err := cmd.Output()
177183
if err != nil {
178-
return "", errors.WithStack(err)
184+
return "", redact.Errorf("nix command: %s", redact.Safe(cmd))
179185
}
180186
out := string(outBytes)
181187
const prefix = "nix (Nix) "
182188
if !strings.HasPrefix(out, prefix) {
183-
return "", errors.Errorf(`Expected "%s" prefix, but output from nix --version was: %s`, prefix, out)
189+
return "", redact.Errorf(`nix command %s: expected %q prefix, but output was: %s`,
190+
redact.Safe(cmd), redact.Safe(prefix), redact.Safe(out))
184191
}
185192
version = strings.TrimSpace(strings.TrimPrefix(out, prefix))
186193
return version, nil

0 commit comments

Comments
 (0)