Skip to content

Commit 9f140bb

Browse files
committed
Fix for nvim container build
1 parent 3854b51 commit 9f140bb

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

dot_files/nvim/Containerfile

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,22 @@ ENV LANG=en_US.UTF-8
5858
ENV LC_ALL=en_US.UTF-8
5959

6060
# =============================================================================
61-
# LAYER 2: Homebrew installation (as root, will work for any user via distrobox)
61+
# LAYER 2: Homebrew installation with non-root user
6262
# =============================================================================
63-
RUN git clone https://github.com/Homebrew/brew /home/linuxbrew/.linuxbrew/Homebrew \
63+
RUN useradd -m -s /bin/bash linuxbrew \
64+
&& git clone https://github.com/Homebrew/brew /home/linuxbrew/.linuxbrew/Homebrew \
6465
&& mkdir -p /home/linuxbrew/.linuxbrew/bin \
6566
&& ln -s ../Homebrew/bin/brew /home/linuxbrew/.linuxbrew/bin/ \
66-
&& chmod -R 777 /home/linuxbrew
67+
&& chown -R linuxbrew:linuxbrew /home/linuxbrew
6768

6869
ENV PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:${PATH}"
6970
ENV HOMEBREW_NO_AUTO_UPDATE=1
7071
ENV HOMEBREW_NO_ANALYTICS=1
7172

73+
# Switch to linuxbrew user for all brew operations
74+
USER linuxbrew
75+
WORKDIR /home/linuxbrew
76+
7277
# Update Homebrew
7378
RUN brew update
7479

@@ -122,31 +127,31 @@ RUN brew install \
122127
fish
123128

124129
# =============================================================================
125-
# LAYER 7: Rust toolchain
130+
# LAYER 7: Rust toolchain (as linuxbrew user)
126131
# =============================================================================
132+
ENV CARGO_HOME="/home/linuxbrew/.cargo"
133+
ENV RUSTUP_HOME="/home/linuxbrew/.rustup"
134+
ENV PATH="${CARGO_HOME}/bin:${PATH}"
135+
127136
RUN brew install rustup-init \
128137
&& rustup-init -y --default-toolchain stable \
129-
&& . /root/.cargo/env \
130-
&& rustup component add rustfmt clippy rust-analyzer \
131-
&& chmod -R 777 /root/.cargo /root/.rustup
132-
133-
ENV PATH="/root/.cargo/bin:${PATH}"
138+
&& . ${CARGO_HOME}/env \
139+
&& rustup component add rustfmt clippy rust-analyzer
134140

135141
# =============================================================================
136-
# LAYER 8: Go tools
142+
# LAYER 8: Go tools (as linuxbrew user)
137143
# =============================================================================
138-
ENV GOPATH="/root/go"
144+
ENV GOPATH="/home/linuxbrew/go"
139145
ENV PATH="${GOPATH}/bin:${PATH}"
140146

141147
RUN go install golang.org/x/tools/gopls@latest \
142148
&& go install github.com/go-delve/delve/cmd/dlv@latest \
143149
&& go install mvdan.cc/gofumpt@latest \
144150
&& go install golang.org/x/tools/cmd/goimports@latest \
145-
&& go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest \
146-
&& chmod -R 777 /root/go
151+
&& go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
147152

148153
# =============================================================================
149-
# LAYER 9: Python tools
154+
# LAYER 9: Python tools (as linuxbrew user, using brew's python)
150155
# =============================================================================
151156
RUN pip3 install --break-system-packages \
152157
pynvim \
@@ -156,9 +161,13 @@ RUN pip3 install --break-system-packages \
156161
debugpy
157162

158163
# =============================================================================
159-
# LAYER 10: Node.js/npm tools
164+
# LAYER 10: Node.js/npm tools (as linuxbrew user)
160165
# =============================================================================
161-
RUN npm install -g \
166+
ENV NPM_CONFIG_PREFIX="/home/linuxbrew/.npm-global"
167+
ENV PATH="${NPM_CONFIG_PREFIX}/bin:${PATH}"
168+
169+
RUN mkdir -p ${NPM_CONFIG_PREFIX} \
170+
&& npm install -g \
162171
neovim \
163172
typescript \
164173
typescript-language-server \
@@ -176,6 +185,10 @@ RUN npm install -g \
176185
tree-sitter-cli \
177186
@mermaid-js/mermaid-cli
178187

188+
# Switch back to root for system-level operations
189+
USER root
190+
WORKDIR /
191+
179192
# =============================================================================
180193
# LAYER 11: Terminal compatibility
181194
# =============================================================================
@@ -186,11 +199,8 @@ RUN curl -fsSL https://raw.githubusercontent.com/ghostty-org/ghostty/main/src/te
186199
# LAYER 12: Fix permissions for distrobox user mapping
187200
# =============================================================================
188201
# Distrobox maps the host user into the container, so we need to ensure
189-
# these directories are accessible
190-
RUN chmod -R 777 /home/linuxbrew \
191-
&& chmod -R 777 /root/.cargo || true \
192-
&& chmod -R 777 /root/.rustup || true \
193-
&& chmod -R 777 /root/go || true
202+
# all tool directories are accessible
203+
RUN chmod -R 777 /home/linuxbrew
194204

195205
# Labels for GitHub Container Registry
196206
LABEL org.opencontainers.image.source="https://github.com/binarypie/hypercube"

0 commit comments

Comments
 (0)