FROM ubuntu:24.04 AS bootstrap
RUN apt-get update \
    && apt-get install -y --no-install-recommends ca-certificates curl git nano xz-utils \
    && rm -rf /var/lib/apt/lists/* \
    && groupadd --gid 10001 nixlab \
    && useradd --uid 10001 --gid 10001 --create-home --shell /bin/bash nixlab \
    && install -d -o 10001 -g 10001 /nix /work
FROM bootstrap
COPY --chown=10001:10001 nix.tar.xz /tmp/nix.tar.xz
USER 10001:10001
ENV USER=nixlab HOME=/home/nixlab
ENV NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
RUN echo '0c3960a9792331a22081c3c7a5d8465db9b17c50b3acdf18587fa4c6f2cb1158  /tmp/nix.tar.xz' | sha256sum -c - \
    && tar -xJf /tmp/nix.tar.xz -C /tmp \
    && /tmp/nix-2.35.2-x86_64-linux/install --no-daemon --no-channel-add --no-modify-profile \
    && rm /tmp/nix.tar.xz
ENV PATH=/home/nixlab/.nix-profile/bin:$PATH
RUN mkdir -p /home/nixlab/.config/nix \
    && printf '%s\n' 'experimental-features = nix-command flakes' 'sandbox = false' 'build-users-group =' > /home/nixlab/.config/nix/nix.conf
WORKDIR /work
CMD ["bash"]
