Skip to content

Commit d78aedf

Browse files
authored
nixcache: fix setup error on multi-user systemd Nix installs (#2053)
1 parent 35b9265 commit d78aedf

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

internal/devbox/packages.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,11 @@ func (d *Devbox) installNixPackagesToStore(ctx context.Context, mode installMode
444444
Flags: flags,
445445
Writer: d.stderr,
446446
}
447-
args.ExtraSubstituter, _ = d.providers.NixCache.URI(ctx)
447+
args.ExtraSubstituter, err = d.providers.NixCache.URI(ctx)
448+
if err != nil {
449+
debug.Log("error getting nix cache URI, assuming user doesn't have access: %v", err)
450+
}
451+
448452
// TODO (Landau): handle errors that are not auth.ErrNotLoggedIn
449453
// Only lookup credentials if we have a cache to use
450454
if args.ExtraSubstituter != "" {

internal/devbox/providers/nixcache/setup.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"go.jetpack.io/devbox/internal/nix"
1919
"go.jetpack.io/devbox/internal/redact"
2020
"go.jetpack.io/devbox/internal/setup"
21+
"go.jetpack.io/devbox/internal/ux"
2122
)
2223

2324
func (p *Provider) Configure(ctx context.Context, username string) error {
@@ -87,10 +88,20 @@ func (s *setupTask) Run(ctx context.Context) error {
8788
return err
8889
}
8990

90-
err = nix.IncludeDevboxConfig(ctx, s.username)
91-
if err != nil {
92-
return redact.Errorf("update nix config: %v", err)
91+
trusted := false
92+
cfg, err := nix.CurrentConfig(ctx)
93+
if err == nil {
94+
trusted, _ = cfg.IsUserTrusted(ctx, s.username)
95+
}
96+
if !trusted {
97+
err = nix.IncludeDevboxConfig(ctx, s.username)
98+
if errors.Is(err, nix.ErrUnknownServiceManager) {
99+
ux.Fwarning(os.Stderr, "Devbox configured Nix to use a new cache. Please restart the Nix daemon and re-run Devbox.\n")
100+
} else if err != nil {
101+
return redact.Errorf("update nix config: %v", err)
102+
}
93103
}
104+
94105
err = s.updateAWSConfig()
95106
if err != nil {
96107
return redact.Errorf("update root aws config: %v", err)

0 commit comments

Comments
 (0)