nix-docker
nix-docker copied to clipboard
Sharing /nix with docker
Using the delegate
flag, file sharing with Docker is quite fast.
It would be great to have a minimal image that just needs nix to be installed on macos, and then it pulls it the linux dependencies, runs the image with -v /nix:/nix:delegate
and then everything is cached.
This would require overlayfs otherwise this is possible with any image if nix installed on the docker host. I use the following alias with DOCKER_HOST
pointing to my desktop.
nix-docker() {
docker run --rm -it -v /nix:/nix:ro \
-e PATH=/nix/var/nix/profiles/system/sw/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
-e NIX_PATH=nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs \
-e NIX_SSL_CERT_FILE=/nix/var/nix/profiles/system/etc/ssl/certs/ca-bundle.crt \
"$@"
}
$ nix-docker alpine
/ # nix run nixpkgs.hello -c hello
[1 copied (0.2 MiB), 0.0 MiB DL]
Hello, world!
If you want to do the same thing without nix on the docker host (eg. Docker.app) it needs a writable store since builds can't go through the nix-daemon and you'd need to configure a profile with a linux binaries on your mac because everything in the image is shadowed by the mount.
right - so basically I need to know what I need to pull in to have the nix-base linux image in my /nix.
🤔could I maybe just run the Nix installer inside an image that only has bash?