Skip to content

Docker build fails due to nix version mismatch #3

@shumbo

Description

@shumbo

Hi. Thanks for making this amazing repository available. This is pretty much what I've been looking for and really saved my day.

When I tried to build the Dockerfile, I found that it fails with the following error:

❯ docker build .
[+] Building 15.7s (11/31)                                                                                                                                                                                                                                    
 => [base  1/13] FROM docker.io/library/debian:stable-slim@sha256:4cdb3e09504f2ad8650da3aa8233d79227647b9943b6c31b5d383b2da9cc6670                                                                                                                       2.0s
 => => resolve docker.io/library/debian:stable-slim@sha256:4cdb3e09504f2ad8650da3aa8233d79227647b9943b6c31b5d383b2da9cc6670                                                                                                                              0.0s
 => => sha256:4cdb3e09504f2ad8650da3aa8233d79227647b9943b6c31b5d383b2da9cc6670 1.85kB / 1.85kB                                                                                                                                                           0.0s
 => => sha256:d8db286ed02d97988d1f2e0939e880c57962c83738a6d1ca5109bdbdb5664b04 529B / 529B                                                                                                                                                               0.0s
 => => sha256:60a8c9439847722f840286cae945f39ca72f8db453b36eba27eb7577ee81e17b 1.48kB / 1.48kB                                                                                                                                                           0.0s
 => => sha256:c762d58c28e4ca53ba8bac3b0134c76ccfdd867806db95aa0470ffbb0d68637b 30.05MB / 30.05MB                                                                                                                                                         0.9s
 => => extracting sha256:c762d58c28e4ca53ba8bac3b0134c76ccfdd867806db95aa0470ffbb0d68637b                                                                                                                                                                0.9s
 => [stage-1  2/14] RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends   ca-certificates   git   gnupg   locales   ssh   sudo &&   rm -rf /var/lib/apt/lists/*                        9.5s
 => [base  2/13] RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends   ca-certificates   curl   sudo   xz-utils                                                                                                       5.6s
[+] Building 96.8s (30/31)                                                                                                                                                                                                  => [internal] load build definition from Dockerfile                                                                                                                                                                  0.0s
 => => transferring dockerfile: 3.37kB                                                                                                                                                                                0.0s  => [internal] load .dockerignore                                                                                                                                                                                     0.0s
 => => transferring context: 2B                                                                                                                                                                                       0.0s  => [internal] load metadata for docker.io/library/debian:stable-slim                                                                                                                                                 2.9s
 => [auth] library/debian:pull token for registry-1.docker.io                                                                                                                                                         0.0s  => [internal] load build context                                                                                                                                                                                     0.0s
 => => transferring context: 4.20kB                                                                                                                                                                                   0.0s  => [base  1/13] FROM docker.io/library/debian:stable-slim@sha256:4cdb3e09504f2ad8650da3aa8233d79227647b9943b6c31b5d383b2da9cc6670                                                                                    2.0s
 => => resolve docker.io/library/debian:stable-slim@sha256:4cdb3e09504f2ad8650da3aa8233d79227647b9943b6c31b5d383b2da9cc6670                                                                                           0.0s  => => sha256:4cdb3e09504f2ad8650da3aa8233d79227647b9943b6c31b5d383b2da9cc6670 1.85kB / 1.85kB                                                                                                                        0.0s
 => => sha256:d8db286ed02d97988d1f2e0939e880c57962c83738a6d1ca5109bdbdb5664b04 529B / 529B                                                                                                                            0.0s  => => sha256:60a8c9439847722f840286cae945f39ca72f8db453b36eba27eb7577ee81e17b 1.48kB / 1.48kB                                                                                                                        0.0s
 => => sha256:c762d58c28e4ca53ba8bac3b0134c76ccfdd867806db95aa0470ffbb0d68637b 30.05MB / 30.05MB                                                                                                                      0.9s  => => extracting sha256:c762d58c28e4ca53ba8bac3b0134c76ccfdd867806db95aa0470ffbb0d68637b                                                                                                                             0.9s
 => [stage-1  2/14] RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends   ca-certificates   git   gnupg   locales   ssh   sudo &&   rm -rf /var/li  9.5s  => [base  2/13] RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends   ca-certificates   curl   sudo   xz-utils                                                                    5.6s
 => [base  3/13] RUN groupadd -g 1000 vscode &&   useradd -u 1000 -g 1000 -G sudo -m vscode -s /bin/bash                                                                                                              0.3s  => [base  4/13] RUN sed -i 's/%sudo.*ALL/%sudo   ALL=(ALL:ALL) NOPASSWD:ALL/' /etc/sudoers &&   echo "sandbox = false" > /etc/nix.conf &&   echo "experimental-features = nix-command flakes" >> /etc/nix.conf       0.3s
 => [base  5/13] RUN curl -L https://nixos.org/nix/install | NIX_INSTALLER_NO_MODIFY_PROFILE=1 sh                                                                                                                    11.8s
 => [stage-1  3/14] RUN groupadd -g 1000 vscode &&   useradd -u 1000 -g 1000 -G sudo -m vscode -s /bin/bash                                                                                                           0.3s
 => [base  6/13] RUN mkdir -p /home/vscode/.config/devcontainer/extra                                                                                                                                                 0.3s
 => [base  7/13] COPY --chown=vscode:vscode config/flake.nix /home/vscode/.config/devcontainer/flake.nix                                                                                                              0.0s
 => [base  8/13] COPY --chown=vscode:vscode config/flake.lock /home/vscode/.config/devcontainer/flake.lock                                                                                                            0.0s
 => [base  9/13] COPY --chown=vscode:vscode config/config.nix /home/vscode/.config/devcontainer/config.nix                                                                                                            0.0s
 => [base 10/13] RUN sed -i "s/ARCH/$(uname -m)-$(uname -s | tr '[:upper:]' '[:lower:]')/" /home/vscode/.config/devcontainer/flake.nix                                                                                0.1s
 => [base 11/13] RUN sed -i "s/USER/vscode/" /home/vscode/.config/devcontainer/flake.nix                                                                                                                              0.3s
 => [base 12/13] WORKDIR /home/vscode/.config/devcontainer                                                                                                                                                            0.0s
 => [base 13/13] RUN . /home/vscode/.nix-profile/etc/profile.d/nix.sh &&   nix build --no-link .#homeConfigurations.vscode.activationPackage                                                                         32.1s
 => [stage-1  4/14] COPY --from=base --chown=vscode:vscode /home/vscode /home/vscode                                                                                                                                  0.0s
 => [stage-1  5/14] RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen &&   locale-gen                                                                                                                                   1.2s
 => [stage-1  6/14] RUN sed -i 's/%sudo.*ALL/%sudo   ALL=(ALL:ALL) NOPASSWD:ALL/' /etc/sudoers                                                                                                                        0.3s
 => [stage-1  7/14] RUN echo "source /home/vscode/.nix-profile/etc/profile.d/nix.sh" >> /etc/bash.bashrc &&   echo "source /home/vscode/.nix-profile/etc/profile.d/nix.sh" >> /etc/zshrc                              0.3s
 => [stage-1  8/14] COPY --from=base /nix /nix                                                                                                                                                                       23.0s
 => [stage-1  9/14] COPY --from=base /etc/nix.conf /etc/nix.conf                                                                                                                                                      0.0s
 => [stage-1 10/14] COPY config/direnv.toml /etc                                                                                                                                                                      0.0s
 => [stage-1 11/14] RUN mkdir -p /home/vscode/.vscode-server/extensions &&   mkdir -p /home/vscode/.vscode-server-insiders/extensions                                                                                 0.3s
 => [stage-1 12/14] WORKDIR /home/vscode/.config/devcontainer                                                                                                                                                         0.0s
 => ERROR [stage-1 13/14] RUN . /home/vscode/.nix-profile/etc/profile.d/nix.sh &&   nix-env --set-flag priority 10 nix-2.8.1 &&   "$(nix path-info .#homeConfigurations.vscode.activationPackage)"/activate           0.3s
------
 > [stage-1 13/14] RUN . /home/vscode/.nix-profile/etc/profile.d/nix.sh &&   nix-env --set-flag priority 10 nix-2.8.1 &&   "$(nix path-info .#homeConfigurations.vscode.activationPackage)"/activate:
#30 0.280 error: selector 'nix-2.8.1' matches no derivations
------
executor failed running [/bin/sh -c . /home/${USER}/.nix-profile/etc/profile.d/nix.sh &&   nix-env --set-flag priority 10 nix-2.8.1 &&   "$(nix path-info .#homeConfigurations.${USER}.activationPackage)"/activate]: exit code: 1

I figured this is due to the version mismatch in Dockerfile and nix installed by the script.

nix-env --set-flag priority 10 nix-2.8.1 && \

This line assumes nix 2.8.1 is used during the build, but the installer script at https://nixos.org/nix/install always refers to the latest release of nix, which is currently 2.10.3.

ARG NIX_INSTALLER=https://nixos.org/nix/install

Changing line 103 to nix-env --set-flag priority 10 nix-2.10.3 solves the problem for now, but it will break again as soon as the next version of nix comes out.

I also realized that https://nixos.org/nix/install is redirected to https://releases.nixos.org/nix/nix-2.10.3/install. Although I couldn't find any reference, the website seems to maintain the older versions as well (https://releases.nixos.org/?prefix=nix/).

It might be a good idea to change the address of the installer to pin the version and upgrade both the installer and derivation to prioritize.

Since I'm new to nix, there may be other ways to fix it. Let me know what you think.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions