Skip to content

Commit 654e973

Browse files
authored
[devcontainer] Changed to single user nix in devcontainer (#1325)
## Summary Multi user nix installation with creating a devbox user in dockerfile causes an issue in devcontainer with Nix due to permission issues with subdirectories nix creates in `/tmp/`. Changing to a single user installation and handling everything under root user in docker seems to fix the issue. ## How was it tested? - `devbox init && devbox add hello` - `devbox generate devcontainer` - open vscode: `code .` - in vscode command palette (cmd + shift + p) run `Dev Containers: Rebuild Without Cache and Reopen in Container` - confirm that devcontainer gets created successfully and vscode switches to remote devcontainer environment.
1 parent b24890b commit 654e973

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

internal/impl/generate/devcontainer_util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func getDevcontainerContent(pkgs []string) *devcontainerObject {
128128
},
129129
},
130130
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
131-
RemoteUser: "devbox",
131+
RemoteUser: "root",
132132
}
133133

134134
// match only python3 or python3xx as package names

internal/impl/generate/tmpl/devcontainerDockerfile.tmpl

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,26 @@ FROM debian:stable-slim
44
RUN apt-get update
55
RUN apt-get -y install bash binutils git{{if .IsDevcontainer}} gnupg2{{- end}} xz-utils wget sudo
66

7-
# Step 2: Setting up devbox user
8-
ENV DEVBOX_USER=devbox
9-
RUN adduser $DEVBOX_USER
10-
RUN usermod -aG sudo $DEVBOX_USER
11-
RUN echo "devbox ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/$DEVBOX_USER
12-
13-
USER $DEVBOX_USER
7+
# Step 2: Installing Nix
8+
RUN wget --output-document=/dev/stdout https://nixos.org/nix/install | sh -s -- --daemon
9+
RUN . ~/.nix-profile/etc/profile.d/nix.sh
10+
ENV PATH="/root/.nix-profile/bin:$PATH"
1411

1512
# Step 3: Installing devbox
1613
RUN wget --quiet --output-document=/dev/stdout https://get.jetpack.io/devbox | bash -s -- -f
17-
RUN chown -R "${DEVBOX_USER}:${DEVBOX_USER}" /usr/local/bin/devbox
1814

19-
# Step 4: Installing Nix
20-
RUN wget --output-document=/dev/stdout https://nixos.org/nix/install | sh -s -- --no-daemon
21-
RUN . ~/.nix-profile/etc/profile.d/nix.sh
22-
# updating PATH
23-
ENV PATH="/home/${DEVBOX_USER}/.nix-profile/bin:/home/${DEVBOX_USER}/.devbox/nix/profile/default/bin:${PATH}"
24-
25-
# Step 5: Installing your devbox project
15+
# Step 4: Installing your devbox project
2616
WORKDIR /code
27-
RUN sudo chown $DEVBOX_USER:root /code
2817
COPY devbox.json devbox.json
2918
{{if len .LocalFlakeDirs}}
3019
# Step 6: Copying local flakes directories
3120
{{- end}}
3221
{{range $i, $element := .LocalFlakeDirs -}}
3322
COPY {{$element}} {{$element}}
3423
{{end}}
35-
RUN devbox install
24+
RUN devbox run -- echo "Installed Packages."
3625
{{if .IsDevcontainer}}
3726
RUN devbox shellenv --init-hook >> ~/.profile
3827
{{- else}}
3928
CMD ["devbox", "shell"]
40-
{{- end}}
29+
{{- end}}

0 commit comments

Comments
 (0)