environment: Provide /etc/hosts in containers without '--network'.

Fixes <https://bugs.gnu.org/43762>.

* guix/scripts/environment.scm (launch-environment/container): Create
/etc/hosts when NETWORK? is false.
* tests/guix-environment-container.sh: Add "localhost" resolution test.
This commit is contained in:
Ludovic Courtès 2020-10-02 23:17:40 +02:00
parent 8e1907a724
commit 0f53c801b9
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
2 changed files with 11 additions and 0 deletions

View File

@ -549,6 +549,13 @@ WHILE-LIST."
(write-passwd (list passwd))
(write-group groups)
(unless network?
;; When isolated from the network, provide a minimal /etc/hosts
;; to resolve "localhost".
(call-with-output-file "/etc/hosts"
(lambda (port)
(display "127.0.0.1 localhost\n" port))))
;; For convenience, start in the user's current working
;; directory or, if unmapped, the home directory.
(chdir (if map-cwd?

View File

@ -44,6 +44,10 @@ else
test $? = 42
fi
# Make sure "localhost" resolves.
guix environment --container --ad-hoc --bootstrap guile-bootstrap \
-- guile -c '(exit (pair? (getaddrinfo "localhost" "80")))'
# Make sure '--preserve' is honored.
result="`FOOBAR=42; export FOOBAR; guix environment -C --ad-hoc --bootstrap \
guile-bootstrap -E ^FOO -- guile -c '(display (getenv \"FOOBAR\"))'`"