@@ -38,22 +38,28 @@ func Configure(ctx context.Context) error {
3838 if err != nil {
3939 return redact .Errorf ("nixcache: lookup current user: %v" , err )
4040 }
41- return configure (ctx , u .Username , false )
42- }
4341
44- func ConfigureReprompt (ctx context.Context , username string ) error {
45- return configure (ctx , username , true )
46- }
42+ task := & setupTask {u .Username }
4743
48- func configure (ctx context.Context , username string , reprompt bool ) error {
49- if reprompt {
50- setup .Reset (setupKey )
44+ // This function might be called from other Devbox commands
45+ // (such as devbox add), so we need to provide some context in the sudo
46+ // prompt.
47+ const sudoPrompt = "You're logged into a Devbox account, but Nix isn't setup to use your account's caches. " +
48+ "Allow sudo to configure Nix?"
49+ err = setup .ConfirmRun (ctx , setupKey , task , sudoPrompt )
50+ if err != nil {
51+ return redact .Errorf ("nixcache: run setup: %w" , err )
5152 }
53+ return nil
54+ }
5255
56+ func ConfigureReprompt (ctx context.Context , username string ) error {
57+ setup .Reset (setupKey )
5358 task := & setupTask {username }
54- const sudoPrompt = "You're logged into a Devbox account that now has access to a Nix cache. " +
55- "Allow Devbox to configure Nix to use the new cache (requires sudo)?"
56- err := setup .ConfirmRun (ctx , setupKey , task , sudoPrompt )
59+
60+ // We're reprompting, so the user explicitly asked to configure the
61+ // cache. We can keep the sudo prompt short.
62+ err := setup .ConfirmRun (ctx , setupKey , task , "Allow sudo to configure Nix?" )
5763 if err != nil {
5864 return redact .Errorf ("nixcache: run setup: %w" , err )
5965 }
0 commit comments