|
1 | 1 | FROM ubuntu:24.10 AS builder
|
2 | 2 |
|
3 |
| -# Avoid interactive prompts |
4 |
| -ENV DEBIAN_FRONTEND=noninteractive |
| 3 | +# Create non-root user early |
| 4 | +RUN useradd -ms /bin/bash builder |
5 | 5 |
|
6 |
| -# Install dependencies as root |
7 |
| -RUN apt-get update && \ |
8 |
| - apt-get install -y curl sudo systemd ca-certificates && \ |
9 |
| - rm -rf /var/lib/apt/lists/* |
| 6 | +# Install curl and other deps as root BEFORE switching users |
| 7 | +RUN apt-get update && apt-get install -y curl systemd ca-certificates && rm -rf /var/lib/apt/lists/* |
10 | 8 |
|
11 |
| -# Create non-root user |
12 |
| -RUN useradd -ms /bin/bash builder && \ |
13 |
| - echo "builder ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers |
| 9 | +USER builder |
| 10 | +ENV USER=builder |
| 11 | +WORKDIR /home/builder |
14 | 12 |
|
15 |
| -# Install Nix (multi-user mode, non-daemon) |
| 13 | +# Install Determinate Nix as builder (non-root setup) |
16 | 14 | RUN curl --proto '=https' --tlsv1.2 -sSf https://install.determinate.systems/nix | \
|
17 | 15 | bash -s -- install linux \
|
18 | 16 | --extra-conf "sandbox = false" \
|
19 | 17 | --no-start-daemon \
|
20 | 18 | --no-confirm
|
21 | 19 |
|
22 |
| -# Export Nix to path |
23 |
| -ENV PATH="/nix/var/nix/profiles/default/bin:/root/.nix-profile/bin:$PATH" |
24 |
| - |
25 |
| -# Optionally set experimental features |
26 |
| -RUN mkdir -p /etc/nix && \ |
27 |
| - echo "experimental-features = nix-command flakes" > /etc/nix/nix.conf |
28 |
| - |
29 |
| -# Switch to builder |
30 |
| -USER builder |
31 |
| -ENV USER=builder |
| 20 | +# Set up proper Nix PATH for non-root user |
32 | 21 | ENV PATH="/home/builder/.nix-profile/bin:/nix/var/nix/profiles/default/bin:$PATH"
|
33 | 22 |
|
| 23 | +# Prove it works |
| 24 | +RUN nix run nixpkgs#hello |
| 25 | + |
34 | 26 | # Copy the source code into the container
|
35 | 27 | COPY . /tmp/build
|
36 | 28 | WORKDIR /tmp/build
|
|
0 commit comments