summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/guix.texi13
-rw-r--r--guix/scripts/environment.scm8
-rw-r--r--tests/guix-environment-container.sh15
3 files changed, 28 insertions, 8 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index 616970b5052..616c2ef3053 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -4557,9 +4557,11 @@ Run @var{command} within an isolated container. The current working
4557directory outside the container is mapped inside the container. 4557directory outside the container is mapped inside the container.
4558Additionally, unless overridden with @code{--user}, a dummy home 4558Additionally, unless overridden with @code{--user}, a dummy home
4559directory is created that matches the current user's home directory, and 4559directory is created that matches the current user's home directory, and
4560@file{/etc/passwd} is configured accordingly. The spawned process runs 4560@file{/etc/passwd} is configured accordingly.
4561as the current user outside the container, but has root privileges in 4561
4562the context of the container. 4562The spawned process runs as the current user outside the container. Inside
4563the container, it has the same UID and GID as the current user, unless
4564@option{--user} is passed (see below.)
4563 4565
4564@item --network 4566@item --network
4565@itemx -N 4567@itemx -N
@@ -4587,8 +4589,9 @@ the environment.
4587@itemx -u @var{user} 4589@itemx -u @var{user}
4588For containers, use the username @var{user} in place of the current 4590For containers, use the username @var{user} in place of the current
4589user. The generated @file{/etc/passwd} entry within the container will 4591user. The generated @file{/etc/passwd} entry within the container will
4590contain the name @var{user}; the home directory will be 4592contain the name @var{user}, the home directory will be
4591@file{/home/USER}; and no user GECOS data will be copied. @var{user} 4593@file{/home/@var{user}}, and no user GECOS data will be copied. Furthermore,
4594the UID and GID inside the container are 1000. @var{user}
4592need not exist on the system. 4595need not exist on the system.
4593 4596
4594Additionally, any shared or exposed path (see @code{--share} and 4597Additionally, any shared or exposed path (see @code{--share} and
diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm
index c27edc7982d..2d1ba4c9386 100644
--- a/guix/scripts/environment.scm
+++ b/guix/scripts/environment.scm
@@ -459,17 +459,19 @@ will be used for the passwd entry. LINK-PROFILE? creates a symbolic link from
459 (return 459 (return
460 (let* ((cwd (getcwd)) 460 (let* ((cwd (getcwd))
461 (home (getenv "HOME")) 461 (home (getenv "HOME"))
462 (uid (if user 1000 (getuid)))
463 (gid (if user 1000 (getgid)))
462 (passwd (let ((pwd (getpwuid (getuid)))) 464 (passwd (let ((pwd (getpwuid (getuid))))
463 (password-entry 465 (password-entry
464 (name (or user (passwd:name pwd))) 466 (name (or user (passwd:name pwd)))
465 (real-name (if user 467 (real-name (if user
466 "" 468 ""
467 (passwd:gecos pwd))) 469 (passwd:gecos pwd)))
468 (uid 0) (gid 0) (shell bash) 470 (uid uid) (gid gid) (shell bash)
469 (directory (if user 471 (directory (if user
470 (string-append "/home/" user) 472 (string-append "/home/" user)
471 (passwd:dir pwd)))))) 473 (passwd:dir pwd))))))
472 (groups (list (group-entry (name "users") (gid 0)) 474 (groups (list (group-entry (name "users") (gid gid))
473 (group-entry (gid 65534) ;the overflow GID 475 (group-entry (gid 65534) ;the overflow GID
474 (name "overflow")))) 476 (name "overflow"))))
475 (home-dir (password-entry-directory passwd)) 477 (home-dir (password-entry-directory passwd))
@@ -541,6 +543,8 @@ will be used for the passwd entry. LINK-PROFILE? creates a symbolic link from
541 ;; A container's environment is already purified, so no need to 543 ;; A container's environment is already purified, so no need to
542 ;; request it be purified again. 544 ;; request it be purified again.
543 (launch-environment command profile manifest #:pure? #f))) 545 (launch-environment command profile manifest #:pure? #f)))
546 #:guest-uid uid
547 #:guest-gid gid
544 #:namespaces (if network? 548 #:namespaces (if network?
545 (delq 'net %namespaces) ; share host network 549 (delq 'net %namespaces) ; share host network
546 %namespaces))))))) 550 %namespaces)))))))
diff --git a/tests/guix-environment-container.sh b/tests/guix-environment-container.sh
index f2221af95bb..78507f76c04 100644
--- a/tests/guix-environment-container.sh
+++ b/tests/guix-environment-container.sh
@@ -44,6 +44,19 @@ else
44 test $? = 42 44 test $? = 42
45fi 45fi
46 46
47# By default, the UID inside the container should be the same as outside.
48uid="`id -u`"
49inner_uid="`guix environment -C --ad-hoc --bootstrap guile-bootstrap \
50 -- guile -c '(display (getuid))'`"
51test $inner_uid = $uid
52
53# When '--user' is passed, the UID should be 1000. (Note: Use a separate HOME
54# so that we don't run into problems when the test directory is under /home.)
55export tmpdir
56inner_uid="`HOME=$tmpdir guix environment -C --ad-hoc --bootstrap guile-bootstrap \
57 --user=gnu-guix -- guile -c '(display (getuid))'`"
58test $inner_uid = 1000
59
47if test "x$USER" = "x"; then USER="`id -un`"; fi 60if test "x$USER" = "x"; then USER="`id -un`"; fi
48 61
49# Check whether /etc/passwd and /etc/group are valid. 62# Check whether /etc/passwd and /etc/group are valid.
@@ -123,7 +136,7 @@ rm $tmpdir/mounts
123 136
124# Test that user can be mocked. 137# Test that user can be mocked.
125usertest='(exit (and (string=? (getenv "HOME") "/home/foognu") 138usertest='(exit (and (string=? (getenv "HOME") "/home/foognu")
126 (string=? (passwd:name (getpwuid 0)) "foognu") 139 (string=? (passwd:name (getpwuid 1000)) "foognu")
127 (file-exists? "/home/foognu/umock")))' 140 (file-exists? "/home/foognu/umock")))'
128touch "$tmpdir/umock" 141touch "$tmpdir/umock"
129HOME="$tmpdir" guix environment --bootstrap --container --user=foognu \ 142HOME="$tmpdir" guix environment --bootstrap --container --user=foognu \