Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use local substituter when mounted read-only #6835

Open
thomasjm opened this issue Jul 24, 2022 · 2 comments
Open

Can't use local substituter when mounted read-only #6835

thomasjm opened this issue Jul 24, 2022 · 2 comments
Labels

Comments

@thomasjm
Copy link
Contributor

I'm trying to bind-mount my /nix dir into a Docker container and use it as a local substituter. This works fine when I mount read/write:

docker run -it -v /nix:/host_nix/nix nixos/nix

> nix-build -E 'with import <nixpkgs> {}; pkgs.hello' --extra-substituters /host_nix/
...works fine, uses the local substituter to avoid hitting cache.nixos.org

But, I don't want the container to be able to modify my /nix dir if it happens to be run as root. So I tried to do the same thing with a read-only mount (note the :ro).

docker run -it -v /nix:/host_nix/nix:ro nixos/nix

> nix-build -E 'with import <nixpkgs> {}; pkgs.hello' --extra-substituters /host_nix/
warning: remounting /host_nix/nix/store writable: Operation not permitted
...proceeds to hit cache.nixos.org

As you can see, just because we're running as root, nix seems under the mistaken impression that it can remount this directory. When that fails, it fails to use the substituter.

It looks like maybe this is due to the "substituter" code path reusing the code for dealing with a normal local store?

Expected behavior

Read-only bind mounts should work as local substituters.

nix-env --version output

nix-env (Nix) 2.8.0
@thomasjm thomasjm added the bug label Jul 24, 2022
@thomasjm
Copy link
Contributor Author

Note: the code path in question seems to get triggered here.

I tried to dodge it by running the container as non-root, but then I promptly ran into another error a few lines lower.

@arianvp
Copy link
Member

arianvp commented Nov 16, 2024

Another workaround is to use the new overlay store functionality. You would use /host_nix as the lowerdir and then things should just work TM . Except for that the lower store should really be "immutable" which is not the case in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants