I have been trying to implement nix local overlay store in a docker container, i have done nix single-user installation in dockerfile, it looks like this
FROM ubuntu:latest
RUN apt-get update &&
apt-get install -y sudo xz-utils curl vim &&
rm -rf /var/lib/apt/lists/*
RUN groupadd -g 1024 valnix &&
useradd -u 1024 -m -g valnix -s /bin/bash valnix &&
echo ‘valnix ALL=(ALL) NOPASSWD: ALL’ >> /etc/sudoers
RUN curl -L https://nixos.org/nix/install -o install_nix.sh
RUN chmod +x install_nix.sh
USER valnix
RUN sh install_nix.sh --no-daemon
ENV PATH=“{$PATH}:/home/valnix/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/bin”
when i run the container nix installation works,
docker run --privileged -v /nix/store:/nix/store-host -it image_name (/nix/store has several packages installed like python3)
For the local overlay store, i do the following steps inside the container
- mkdir -p /nix/store-host/upper /nix/store-host/workdir
- sudo mkdir -p /etc/nix && sudo vi /etc/nix/nix.conf
- In nix.conf
experimental-features = nix-command flakes local-overlay-store read-only-local-store
store = local-overlay?lower-store=/nix/store&upper-layer=/nix/store-host/upper&check-mount=false - sudo mount -t overlay overlay -o lowerdir=/nix/store,upperdir=/nix/store-host/upper,workdir=/nix/store-host/workdir “/nix/store”
When i do nix-shell or nix-env, for example (nix-shell -p python3) it will start installing from cache.nixos.org ( copying path ‘/nix/store/pgb120fb7srbh418v4i2a70aq1w9dawd-python3-3.12.5’ from ‘https://cache.nixos.org’ to ‘local-overlay://’… )
FYI, python3 was available in my host machine /nix/store
Expected is, when i do nix-shell -p python3 it shouldn’t be installed from “https://cache.nixos.org”
Please help me on this, let me know if i am doing something wrong