Skip to content

Commit d01209d

Browse files
authored
[nix] Always do multi-user install if root (#703)
## Summary Instead of showing a nix error, switch to multi-user install when user tries to install as root (this is common in docker and CICD) ## How was it tested? fresh docker ubuntu
1 parent 94b34ef commit d01209d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

internal/boxcli/setup.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ package boxcli
66
import (
77
"fmt"
88
"os"
9+
"os/user"
910

1011
"github.com/fatih/color"
1112
"github.com/mattn/go-isatty"
13+
"github.com/samber/lo"
1214
"github.com/spf13/cobra"
1315
"go.jetpack.io/devbox/internal/boxcli/usererr"
1416
"go.jetpack.io/devbox/internal/nix"
17+
"go.jetpack.io/devbox/internal/ux"
1518
)
1619

1720
const nixDaemonFlag = "daemon"
@@ -75,7 +78,7 @@ func ensureNixInstalled(cmd *cobra.Command, args []string) error {
7578
fmt.Scanln()
7679
}
7780

78-
if err := nix.Install(cmd.ErrOrStderr(), nil); err != nil {
81+
if err := nix.Install(cmd.ErrOrStderr(), nixDaemonFlagVal(cmd)); err != nil {
7982
return err
8083
}
8184

@@ -90,6 +93,13 @@ func ensureNixInstalled(cmd *cobra.Command, args []string) error {
9093

9194
func nixDaemonFlagVal(cmd *cobra.Command) *bool {
9295
if !cmd.Flags().Changed(nixDaemonFlag) {
96+
if u, err := user.Current(); err == nil && u.Uid == "0" {
97+
ux.Fwarning(
98+
cmd.ErrOrStderr(),
99+
"Running as root. Installing Nix in multi-user mode.\n",
100+
)
101+
return lo.ToPtr(true)
102+
}
93103
return nil
94104
}
95105

0 commit comments

Comments
 (0)