summary refs log tree commit diff
path: root/nixos/modules/virtualisation/container-config.nix
diff options
context:
space:
mode:
authorArian van Putten <aeroboy94@gmail.com>2018-10-05 15:42:15 +0200
committerArian van Putten <aeroboy94@gmail.com>2018-10-05 18:36:47 +0200
commit3624bb536244ea99f9f9a6d18ff00bbe4a5204af (patch)
tree644c6f04af5cad846ef1fe5e36b2322e8e051bad /nixos/modules/virtualisation/container-config.nix
parent4b613137e4ca733360501108b3a97ac74567cdd7 (diff)
downloadnixlib-3624bb536244ea99f9f9a6d18ff00bbe4a5204af.tar
nixlib-3624bb536244ea99f9f9a6d18ff00bbe4a5204af.tar.gz
nixlib-3624bb536244ea99f9f9a6d18ff00bbe4a5204af.tar.bz2
nixlib-3624bb536244ea99f9f9a6d18ff00bbe4a5204af.tar.lz
nixlib-3624bb536244ea99f9f9a6d18ff00bbe4a5204af.tar.xz
nixlib-3624bb536244ea99f9f9a6d18ff00bbe4a5204af.tar.zst
nixlib-3624bb536244ea99f9f9a6d18ff00bbe4a5204af.zip
nixos-container: Force container to talk to host nix-daemon
When logging into a container by using
  nixos-container root-login
all nix-related commands in the container would fail, as they
tried to modify the nix db and nix store, which are mounted
read-only in the container.  We want nixos-container to not
try to modify the nix store at all, but instead delegate
any build commands to the nix daemon of the host operating system.

This already works for non-root users inside a nixos-container,
as it doesn't 'own' the nix-store, and thus defaults
to talking to the daemon socket at /nix/var/nix/daemon-socket/,
which is bind-mounted to the host daemon-socket, causing all nix
commands to be delegated to the host.

However, when we are the root user inside the container, we have the
same uid as the nix store owner, eventhough it's not actually
the same root user (due to user namespaces). Nix gets confused,
and is convinced it's running in single-user mode, and tries
to modify the nix store directly instead.

By setting `NIX_REMOTE=daemon` in `/etc/profile`, we force nix
to operate in multi-user mode, so that it will talk to the host
daemon instead, which will modify the nix store for the container.

This fixes #40355
Diffstat (limited to 'nixos/modules/virtualisation/container-config.nix')
-rw-r--r--nixos/modules/virtualisation/container-config.nix7
1 files changed, 7 insertions, 0 deletions
diff --git a/nixos/modules/virtualisation/container-config.nix b/nixos/modules/virtualisation/container-config.nix
index 5e368acd6d8b..561db7cabcfb 100644
--- a/nixos/modules/virtualisation/container-config.nix
+++ b/nixos/modules/virtualisation/container-config.nix
@@ -22,6 +22,13 @@ with lib;
     # Not supported in systemd-nspawn containers.
     security.audit.enable = false;
 
+    # Make sure that root user in container will talk to host nix-daemon
+    environment.etc."profile".text = ''
+    export NIX_REMOTE=daemon
+    '';
+
+
+
   };
 
 }