diff options
| author | David Thompson <dthompson2@worcester.edu> | 2016-03-17 23:19:25 -0400 |
|---|---|---|
| committer | David Thompson <dthompson2@worcester.edu> | 2016-03-26 09:38:27 -0400 |
| commit | a01ad63893da1f1cf1b35482037382030724716c (patch) | |
| tree | f9197cf8b889c123d33fdc431f1c86e297a60467 | |
| parent | bf9eacd2af770c458dbd8c18d14e1885b6246313 (diff) | |
environment: container: Create dummy home directory and /etc/passwd.
* guix/scripts/environment.scm (launch-environment/container): Change
$HOME to the current user's home directory instead of
/homeless-shelter. Create a dummy /etc/passwd with a single entry for
the current user.
* doc/guix.texi ("invoking guix environment"): Add a note about the
dummy home directory and /etc/passwd.
| -rw-r--r-- | doc/guix.texi | 15 | ||||
| -rw-r--r-- | guix/scripts/environment.scm | 31 |
2 files changed, 29 insertions, 17 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index b618480353f..008a5cf7149 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -3292,7 +3292,7 @@ omitted since it will take place implicitly, as we will see later | |||
| 3292 | @end example | 3292 | @end example |
| 3293 | 3293 | ||
| 3294 | @c See | 3294 | @c See |
| 3295 | @c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/> | 3295 | @c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/> |
| 3296 | @c for the funny quote. | 3296 | @c for the funny quote. |
| 3297 | Calling the monadic @code{sh-symlink} has no effect. As someone once | 3297 | Calling the monadic @code{sh-symlink} has no effect. As someone once |
| 3298 | said, ``you exit a monad like you exit a building on fire: by running''. | 3298 | said, ``you exit a monad like you exit a building on fire: by running''. |
| @@ -4339,7 +4339,7 @@ So for instance, imagine you want to see the build log of GDB on MIPS, | |||
| 4339 | but you are actually on an @code{x86_64} machine: | 4339 | but you are actually on an @code{x86_64} machine: |
| 4340 | 4340 | ||
| 4341 | @example | 4341 | @example |
| 4342 | $ guix build --log-file gdb -s mips64el-linux | 4342 | $ guix build --log-file gdb -s mips64el-linux |
| 4343 | https://hydra.gnu.org/log/@dots{}-gdb-7.10 | 4343 | https://hydra.gnu.org/log/@dots{}-gdb-7.10 |
| 4344 | @end example | 4344 | @end example |
| 4345 | 4345 | ||
| @@ -5338,10 +5338,11 @@ Attempt to build for @var{system}---e.g., @code{i686-linux}. | |||
| 5338 | @itemx -C | 5338 | @itemx -C |
| 5339 | @cindex container | 5339 | @cindex container |
| 5340 | Run @var{command} within an isolated container. The current working | 5340 | Run @var{command} within an isolated container. The current working |
| 5341 | directory outside the container is mapped inside the | 5341 | directory outside the container is mapped inside the container. |
| 5342 | container. Additionally, the spawned process runs as the current user | 5342 | Additionally, a dummy home directory is created that matches the current |
| 5343 | outside the container, but has root privileges in the context of the | 5343 | user's home directory, and @file{/etc/passwd} is configured accordingly. |
| 5344 | container. | 5344 | The spawned process runs as the current user outside the container, but |
| 5345 | has root privileges in the context of the container. | ||
| 5345 | 5346 | ||
| 5346 | @item --network | 5347 | @item --network |
| 5347 | @itemx -N | 5348 | @itemx -N |
| @@ -8748,7 +8749,7 @@ isn't enough disk space, just skip it. | |||
| 8748 | @item fcntl | 8749 | @item fcntl |
| 8749 | Use this if possible. Works with NFS too if lockd is used. | 8750 | Use this if possible. Works with NFS too if lockd is used. |
| 8750 | @item flock | 8751 | @item flock |
| 8751 | May not exist in all systems. Doesn't work with NFS. | 8752 | May not exist in all systems. Doesn't work with NFS. |
| 8752 | @item lockf | 8753 | @item lockf |
| 8753 | May not exist in all systems. Doesn't work with NFS. | 8754 | May not exist in all systems. Doesn't work with NFS. |
| 8754 | @end table | 8755 | @end table |
diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index b122b4cd406..0d5cab432c9 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm | |||
| @@ -373,6 +373,7 @@ host file systems to mount inside the container." | |||
| 373 | (list (direct-store-path bash) profile)))) | 373 | (list (direct-store-path bash) profile)))) |
| 374 | (return | 374 | (return |
| 375 | (let* ((cwd (getcwd)) | 375 | (let* ((cwd (getcwd)) |
| 376 | (passwd (getpwuid (getuid))) | ||
| 376 | ;; Bind-mount all requisite store items, user-specified mappings, | 377 | ;; Bind-mount all requisite store items, user-specified mappings, |
| 377 | ;; /bin/sh, the current working directory, and possibly networking | 378 | ;; /bin/sh, the current working directory, and possibly networking |
| 378 | ;; configuration files within the container. | 379 | ;; configuration files within the container. |
| @@ -417,16 +418,26 @@ host file systems to mount inside the container." | |||
| 417 | ;; The same variables as in Nix's 'build.cc'. | 418 | ;; The same variables as in Nix's 'build.cc'. |
| 418 | '("TMPDIR" "TEMPDIR" "TMP" "TEMP")) | 419 | '("TMPDIR" "TEMPDIR" "TMP" "TEMP")) |
| 419 | 420 | ||
| 420 | ;; From Nix build.cc: | 421 | ;; Create a dummy home directory under the same name as on the |
| 421 | ;; | 422 | ;; host. |
| 422 | ;; Set HOME to a non-existing path to prevent certain | 423 | (mkdir-p (passwd:dir passwd)) |
| 423 | ;; programs from using /etc/passwd (or NIS, or whatever) | 424 | (setenv "HOME" (passwd:dir passwd)) |
| 424 | ;; to locate the home directory (for example, wget looks | 425 | |
| 425 | ;; for ~/.wgetrc). I.e., these tools use /etc/passwd if | 426 | ;; Create a dummy /etc/passwd to satisfy applications that demand |
| 426 | ;; HOME is not set, but they will just assume that the | 427 | ;; to read it, such as 'git clone' over SSH, a valid use-case when |
| 427 | ;; settings file they are looking for does not exist if | 428 | ;; sharing the host's network namespace. |
| 428 | ;; HOME is set but points to some non-existing path. | 429 | (mkdir-p "/etc") |
| 429 | (setenv "HOME" "/homeless-shelter") | 430 | (call-with-output-file "/etc/passwd" |
| 431 | (lambda (port) | ||
| 432 | (display (string-join (list (passwd:name passwd) | ||
| 433 | "x" ; but there is no shadow | ||
| 434 | "0" "0" ; user is now root | ||
| 435 | (passwd:gecos passwd) | ||
| 436 | (passwd:dir passwd) | ||
| 437 | bash) | ||
| 438 | ":") | ||
| 439 | port) | ||
| 440 | (newline port))) | ||
| 430 | 441 | ||
| 431 | ;; For convenience, start in the user's current working | 442 | ;; For convenience, start in the user's current working |
| 432 | ;; directory rather than the root directory. | 443 | ;; directory rather than the root directory. |
