diff options
author | Samuel Dionne-Riel <samuel@dionne-riel.com> | 2018-10-08 16:55:38 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-08 16:55:38 -0400 |
commit | 7fb45271b27373d4016e51926d5b95e3354b065e (patch) | |
tree | d9c53d6ae0923d1bb8353b1db4d4911511989ec2 | |
parent | cbf93ba7e2f32087a0357b3b8ebf2666e2452847 (diff) | |
parent | 0668906e8470bb1bfa03a47cbedec5050a16a905 (diff) | |
download | nixpkgs-7fb45271b27373d4016e51926d5b95e3354b065e.tar nixpkgs-7fb45271b27373d4016e51926d5b95e3354b065e.tar.gz nixpkgs-7fb45271b27373d4016e51926d5b95e3354b065e.tar.bz2 nixpkgs-7fb45271b27373d4016e51926d5b95e3354b065e.tar.lz nixpkgs-7fb45271b27373d4016e51926d5b95e3354b065e.tar.xz nixpkgs-7fb45271b27373d4016e51926d5b95e3354b065e.tar.zst nixpkgs-7fb45271b27373d4016e51926d5b95e3354b065e.zip |
Merge pull request #47917 from arianvp/fix-imperative-containers
Fix imperative containers
-rw-r--r-- | nixos/doc/manual/administration/imperative-containers.xml | 18 | ||||
-rw-r--r-- | nixos/modules/virtualisation/container-config.nix | 7 | ||||
-rw-r--r-- | nixos/tests/containers-imperative.nix | 3 |
3 files changed, 19 insertions, 9 deletions
diff --git a/nixos/doc/manual/administration/imperative-containers.xml b/nixos/doc/manual/administration/imperative-containers.xml index fa380477f6c..9bb62bc2ece 100644 --- a/nixos/doc/manual/administration/imperative-containers.xml +++ b/nixos/doc/manual/administration/imperative-containers.xml @@ -73,7 +73,8 @@ Linux foo 3.4.82 #1-NixOS SMP Thu Mar 20 14:44:05 UTC 2014 x86_64 GNU/Linux </para> <para> - To change the configuration of the container, you can edit + There are several ways to change the configuration of the container. First, + on the host, you can edit <literal>/var/lib/container/<replaceable>name</replaceable>/etc/nixos/configuration.nix</literal>, and run <screen> @@ -86,7 +87,8 @@ Linux foo 3.4.82 #1-NixOS SMP Thu Mar 20 14:44:05 UTC 2014 x86_64 GNU/Linux <xref linkend="opt-services.httpd.enable"/> = true; <xref linkend="opt-services.httpd.adminAddr"/> = "foo@example.org"; <xref linkend="opt-networking.firewall.allowedTCPPorts"/> = [ 80 ]; - ' +' + # curl http://$(nixos-container show-ip foo)/ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">… </screen> @@ -95,13 +97,11 @@ Linux foo 3.4.82 #1-NixOS SMP Thu Mar 20 14:44:05 UTC 2014 x86_64 GNU/Linux </para> <para> - Note that in previous versions of NixOS (17.09 and earlier) one could also - use all nix-related commands (like <command>nixos-rebuild switch</command>) - from inside the container. However, since the release of Nix 2.0 this is not - supported anymore. Supporting Nix commands inside the container might be - possible again in future versions. See - <link xlink:href="https://github.com/NixOS/nixpkgs/issues/40355">the github - issue</link> for tracking progress on this issue. + Alternatively, you can change the configuration from within the container + itself by running <command>nixos-rebuild switch</command> inside the + container. Note that the container by default does not have a copy of the + NixOS channel, so you should run <command>nix-channel --update</command> + first. </para> <para> diff --git a/nixos/modules/virtualisation/container-config.nix b/nixos/modules/virtualisation/container-config.nix index 5e368acd6d8..561db7cabcf 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 + ''; + + + }; } diff --git a/nixos/tests/containers-imperative.nix b/nixos/tests/containers-imperative.nix index 6f86819f4e8..782095a09da 100644 --- a/nixos/tests/containers-imperative.nix +++ b/nixos/tests/containers-imperative.nix @@ -86,6 +86,9 @@ import ./make-test.nix ({ pkgs, ...} : { # Execute commands via the root shell. $machine->succeed("nixos-container run $id1 -- uname") =~ /Linux/ or die; + # Execute a nix command via the root shell. (regression test for #40355) + $machine->succeed("nixos-container run $id1 -- nix-instantiate -E 'derivation { name = \"empty\"; builder = \"false\"; system = \"false\"; }'"); + # Stop and start (regression test for #4989) $machine->succeed("nixos-container stop $id1"); $machine->succeed("nixos-container start $id1"); |