From 2b337d6e451c842b40db1ccafab20baf644c6e59 Mon Sep 17 00:00:00 2001 From: Greg Curtis Date: Tue, 14 May 2024 11:56:55 -0400 Subject: [PATCH] nixcache: fix setup error on multi-user systemd Nix installs --- internal/devbox/packages.go | 6 +++++- internal/devbox/providers/nixcache/setup.go | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/internal/devbox/packages.go b/internal/devbox/packages.go index 4fa4c54dea0..02d632c2b32 100644 --- a/internal/devbox/packages.go +++ b/internal/devbox/packages.go @@ -444,7 +444,11 @@ func (d *Devbox) installNixPackagesToStore(ctx context.Context, mode installMode Flags: flags, Writer: d.stderr, } - args.ExtraSubstituter, _ = d.providers.NixCache.URI(ctx) + args.ExtraSubstituter, err = d.providers.NixCache.URI(ctx) + if err != nil { + debug.Log("error getting nix cache URI, assuming user doesn't have access: %v", err) + } + // TODO (Landau): handle errors that are not auth.ErrNotLoggedIn // Only lookup credentials if we have a cache to use if args.ExtraSubstituter != "" { diff --git a/internal/devbox/providers/nixcache/setup.go b/internal/devbox/providers/nixcache/setup.go index 021c55360b4..a15d11e02c6 100644 --- a/internal/devbox/providers/nixcache/setup.go +++ b/internal/devbox/providers/nixcache/setup.go @@ -18,6 +18,7 @@ import ( "go.jetpack.io/devbox/internal/nix" "go.jetpack.io/devbox/internal/redact" "go.jetpack.io/devbox/internal/setup" + "go.jetpack.io/devbox/internal/ux" ) func (p *Provider) Configure(ctx context.Context, username string) error { @@ -87,10 +88,20 @@ func (s *setupTask) Run(ctx context.Context) error { return err } - err = nix.IncludeDevboxConfig(ctx, s.username) - if err != nil { - return redact.Errorf("update nix config: %v", err) + trusted := false + cfg, err := nix.CurrentConfig(ctx) + if err == nil { + trusted, _ = cfg.IsUserTrusted(ctx, s.username) + } + if !trusted { + err = nix.IncludeDevboxConfig(ctx, s.username) + if errors.Is(err, nix.ErrUnknownServiceManager) { + ux.Fwarning(os.Stderr, "Devbox configured Nix to use a new cache. Please restart the Nix daemon and re-run Devbox.\n") + } else if err != nil { + return redact.Errorf("update nix config: %v", err) + } } + err = s.updateAWSConfig() if err != nil { return redact.Errorf("update root aws config: %v", err)