summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-08-27 21:12:18 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-08-28 02:20:31 +0200
commit21ab4e054c1570dd5000a18cb114e665729b378a (patch)
tree404ed3fe12b5ed5c69d7e51f1606e84af7ffea32 /nixos
parent6773babd5b75d34afa850351fd292310e3dd3fc8 (diff)
downloadnixlib-21ab4e054c1570dd5000a18cb114e665729b378a.tar
nixlib-21ab4e054c1570dd5000a18cb114e665729b378a.tar.gz
nixlib-21ab4e054c1570dd5000a18cb114e665729b378a.tar.bz2
nixlib-21ab4e054c1570dd5000a18cb114e665729b378a.tar.lz
nixlib-21ab4e054c1570dd5000a18cb114e665729b378a.tar.xz
nixlib-21ab4e054c1570dd5000a18cb114e665729b378a.tar.zst
nixlib-21ab4e054c1570dd5000a18cb114e665729b378a.zip
nixos-container run: Execute command using ‘su’
This ensures that the environment is set up correctly.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/virtualisation/nixos-container.pl9
1 files changed, 5 insertions, 4 deletions
diff --git a/nixos/modules/virtualisation/nixos-container.pl b/nixos/modules/virtualisation/nixos-container.pl
index b829eeb05790..7403a42f0f14 100644
--- a/nixos/modules/virtualisation/nixos-container.pl
+++ b/nixos/modules/virtualisation/nixos-container.pl
@@ -197,8 +197,7 @@ sub getLeader {
 sub runInContainer {
     my @args = @_;
     my $leader = getLeader;
-    # FIXME: initialise the environment properly.
-    exec($nsenter, "-t", $leader, "-m", "-u", "-i", "-n", "-p", "--", "env", "-i", "--", @args);
+    exec($nsenter, "-t", $leader, "-m", "-u", "-i", "-n", "-p", "--", @args);
     die "cannot run ‘nsenter’: $!\n";
 }
 
@@ -251,12 +250,14 @@ elsif ($action eq "login") {
 }
 
 elsif ($action eq "root-login") {
-    runInContainer("bash", "--login");
+    runInContainer("su", "root", "-l");
 }
 
 elsif ($action eq "run") {
     shift @ARGV; shift @ARGV;
-    runInContainer(@ARGV);
+    # Escape command.
+    my $s = join(' ', map { s/'/'\\''/g; "'$_'" } @ARGV);
+    runInContainer("su", "root", "-l", "-c", "exec " . $s);
 }
 
 elsif ($action eq "show-ip") {