Since you cannot (or could not at that moment in time) overlay mount on top of the nix store, there’s quite a few limitations. You either need to rely on external caching like cachix, or have a simple enough build that outputs files only in result. Alternatively, it should be possible to do something with copy-closure, but I kinda lost interest since it wasn’t really meshing well with the other actions.
Just a (perhaps) related data point – this also happens on Travis-CI. I encounter this quite regularly. Sometimes this happens during installation, but also during e.g. channel updates:
There’s also this issue:
But the reporter does not seem to have filed an issue in the Nix repo.
I wasn’t able to reproduce the issue with docker. Any idea how it could be done in a more fully-fledged VM?
Dockerfile:
FROM debian:latest
RUN apt update -q
RUN apt install -qy bzip2 curl vim sudo
# create a default user
RUN yes | adduser -q zimbatm
RUN echo "zimbatm ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/zimbatm
# switch to user, set USER to make the nix install script happy
ENV USER=zimbatm
USER zimbatm
i=0; id=$(docker build .); while docker run -ti --rm --privileged 4a0f74255254 sh -c "curl https://nixos.org/nix/install | sh && . /home/zimbatm/.nix-profile/etc/profile.d/nix.sh && NIX_PATH=nixpkgs=channel:nixos-unstable nix-channel --update"; do ((i++)); echo "************** $i *****************"; done