Commit Graph

31 Commits

Author SHA1 Message Date
Ludovic Courtès ff1146fb4f
tests: Adjust to cope with glibc graft.
This is a followup to 1328c4cca5, which
led to failures for tests that were not prepared to cope with that.

* tests/guix-environment-container.sh (hello_drv_nested): Pass “-E
GUIX_BUILD_OPTIONS” so ‘--no-grafts’ is passed.
* tests/guix-pack.sh (GUIX_BUILD_OPTIONS): Add ‘--no-grafts’.
* tests/transformations.scm ("options->transformation, with-graft"):
Skip when ‘glibc-final’ has a replacement.

Change-Id: Ia65c9aeb06f524252815b8290a5ca7bf97ee8136
2023-10-28 01:30:37 +02:00
Eric Bavier 37dd69b445
tests: Fix checks for expected failures.
Addresses <https://issues.guix.gnu.org/62406>.

With 'set -e', a return status inverted with '!' does not cause the shell to
exit immediately.  Instead use '&& false' to indicate an expected failure.

* tests/guix-archive.sh, tests/guix-build-branch.sh, tests/guix-build.sh,
tests/guix-daemon.sh, tests/guix-download.sh,
tests/guix-environment-container.sh, tests/guix-environment.sh,
tests/guix-gc.sh, tests/guix-git-authenticate.sh, tests/guix-graph.sh,
tests/guix-hash.sh, tests/guix-home.sh, tests/guix-pack-relocatable.sh,
tests/guix-pack.sh, tests/guix-package-aliases.sh, tests/guix-package-net.sh,
tests/guix-package.sh, tests/guix-refresh.sh, tests/guix-shell.sh,
tests/guix-style.sh, tests/guix-system.sh: Replace uses of '! ...' with
'... && false' or `test ! ...` as appropriate.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2023-04-21 16:16:38 +02:00
Ludovic Courtès 57db09aae7
environment: Add '--nesting'.
* guix/scripts/environment.scm (show-environment-options-help)
(%options): Add '--nesting'.
(options/resolve-packages): Handle it.
(launch-environment/container): Add #:nesting? and honor it.
[nesting-mappings]: New procedure.
(guix-environment*): Add support for '--nesting'.
* guix/scripts/shell.scm (profile-cached-gc-root): Special-case
'nesting?'.
* tests/guix-environment-container.sh: Test it.
* doc/guix.texi (Invoking guix shell): Document it.
2023-04-06 18:34:15 +02:00
John Kehayias 3bfbfa2946
environment: Fix '--emulate-fhs' option overriding $PATH.
Fixes <https://issues.guix.gnu.org/60566> where even if "--preserve='^PATH$'"
was passed to 'guix shell' it would be replaced by just the FHS directories
when '--emulate-fhs' was also set.

* gnu/scripts/environment.scm (launch-environment): Add the FHS directories to
$PATH rather than overriding $PATH completely.
* tests/guix-environment-container.sh: Test that FHS directories are in $PATH
in the container and that $PATH can be preserved.

Co-authored-by: Ludovic Courtès <ludo@gnu.org>
2023-01-15 17:54:14 -05:00
Maxim Cournoyer 788602b37f
shell: Detect --symlink spec problems early.
* guix/scripts/pack.scm (symlink-spec-option-parser): Remove extraneous
char-set.  Raise an exception when the target is an absolute file name.
(guix-pack): Move with-error-handler earlier.
* guix/scripts/shell.scm (guix-shell): Likewise.
* guix/scripts/environment.scm (guix-environment): Wrap the whole
guix-environment* call with the with-error-handling handler.
* tests/guix-environment-container.sh: Add tests.
* tests/guix-pack.sh: Adjust symlink spec.
2022-11-15 14:15:11 -05:00
Maxim Cournoyer b31ea797ed
guix: shell: Add '--symlink' option.
* guix/scripts/pack.scm (%options): Extract symlink parsing logic to...
(symlink-spec-option-parser): ... here.
(self-contained-tarball/builder): Add a comment mentioning why a relative file
name is used for the link target.
* guix/scripts/environment.scm (show-environment-options-help): Document new
--symlink option.
(%default-options): Add default value for symlinks.
(%options): Register new symlink option.
(launch-environment/container): Add #:symlinks argument and extend doc, and
create symlinks using evaluate-populate-directive.
(guix-environment*): Pass symlinks arguments to launch-environment/container.
* doc/guix.texi (Invoking guix shell): Document it.
* tests/guix-shell.sh: Add a --symlink (negative) test.
* tests/guix-environment-container.sh: Add tests.
2022-11-15 14:15:11 -05:00
John Kehayias 905443abb7
shell: Fix '--emulate-fhs' sometimes not including 'glibc-for-fhs'.
Fixes <https://issues.guix.gnu.org/58861>.

Previously the order of the options giving to 'guix shell' could mean that the
'glibc-for-fhs' package included with the '--emulate-fhs' option would not
appear in the container.  For example, using the development option with a
package using the 'gnu-build-system', e.g. 'guix shell -CFD hello', would
include the regular 'glibc' package.  The option ordered mattered: 'guix shell
-CD hello -F' would include the expected 'glibc-for-fhs'.  We fix this by
having 'glibc-for-fhs' added to the package list just before calling
'options-with-caching' so the option order given by the user does not matter.

* guix/scripts/shell.scm (%options): Move the '--emulate-fhs' (expression
. ...) component from here...
(parse-args): ... to here.
* tests/guix-environment-container.sh: Add a test to check that
'glibc-for-fhs' is in the container even when 'glibc' is included in the 'guix
shell' package list.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2022-11-06 12:38:02 +01:00
Ludovic Courtès 8b192c5550
shell: Handle '--emulate-fhs' in 'guix shell', not in 'guix environment'.
Previously, using 'guix shell -CF coreutils' twice (such that the
profile is cache) would result in:

  guix shell: error: '--profile' cannot be used with package options

This patch fixes it by moving argument handling to (guix scripts shell),
before 'options-with-caching' is called.

* guix/scripts/environment.scm (show-environment-options-help)
(%options): Remove '--emulate-fhs'.
(guix-environment*): Pass OPTS as-is to 'options/resolve-packages'.
* guix/scripts/shell.scm (show-help, %options): Add '--emulate-fhs'.
Add the (expression . ...) component to RESULT right from the argument
handler.
* tests/guix-environment-container.sh: Change '--emulate-fhs' tests to
use 'guix shell' instead of 'guix environment'.
2022-10-13 15:56:56 +02:00
John Kehayias c7ba5f38b8
environment: Add '--emulate-fhs'.
* guix/scripts/environment.scm (show-environment-options-help, %options): Add
'--emulate-fhs'.
(setup-fhs): New procedure.  Setup for the Filesystem Hierarchy Standard (FHS)
container.  Defines and uses FHS-SYMLINKS and LINK-CONTENTS to create FHS
expected directories and creates /etc/ld.so.conf.
(launch-environment): Add 'emulate-fhs?' key and implement it to set $PATH and
generate /etc/ld.so.cache before calling COMMAND.
(launch-environment/container): Add 'emulate-fhs?' and 'setup-hook' keys and
implement them.  Define and use FHS-MAPPINGS, to set up additional bind mounts
in the container to follow FHS expectations.
(guix-environment*): Add glibc-for-fhs to the container packages when
'emulate-fhs?' key is in OPTS.
* doc/guix.texi (Invoking guix shell): Document '--emulate-fhs'.
(Invoking guix environment): Document '--emulate-fhs'.
* tests/guix-environment-container.sh: Add tests for '--emulate-fhs'.

Co-authored-by: Ludovic Courtès <ludo@gnu.org>
2022-10-13 09:19:08 +02:00
Ludovic Courtès 10208952ea
environment: Add tests for '--profile'.
This is a followup to a643deac2d.

* tests/guix-environment-container.sh, tests/guix-environment.sh: Add
tests for '--profile'.
2021-10-25 19:02:32 +02:00
Ludovic Courtès b68d410651
environment: Turn "lo" up in network-less containers.
This is a followup to 0f53c801b9.

* guix/scripts/environment.scm (launch-environment/container): Add call
to 'set-network-interface-up'.
* tests/guix-environment-container.sh: Add test.
2020-10-05 10:41:59 +02:00
Ludovic Courtès 0f53c801b9
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.
2020-10-02 23:28:09 +02:00
Ludovic Courtès 9b65281de5
environment: '--link-profile' uses ~/.guix-profile for environment variables.
Before this patch, we had:

  $ guix environment -CP --ad-hoc coreutils
  [env]$ echo $PATH
  /gnu/store/…-profile/bin
  [env]$ echo $GUIX_ENVIRONMENT
  /gnu/store/…-profile

After this patch:

  $ guix environment -CP --ad-hoc coreutils
  [env]$ echo $PATH
  /home/ludo/.guix-profile/bin
  [env]$ echo $GUIX_ENVIRONMENT
  /home/ludo/.guix-profile

* guix/scripts/environment.scm (launch-environment/container): When
LINK-PROFILE? is true, pass ~/.guix-profile as the second argument to
'launch-environment'.
* tests/guix-environment-container.sh: Adjust test accordingly.
* doc/guix.texi (Invoking guix environment): Update accordingly.
2020-09-21 23:05:38 +02:00
Ludovic Courtès 90f496be9a
tests: Actually run 'tests/guix-environment-container.sh'.
This test was skipped since the switch to Guile 3 because
'assert-container-features' would be inlined and thus accessing it with
@@ would fail with an unbound-variable error.

* guix/scripts/environment.scm (assert-container-features): Export.
* tests/guix-environment-container.sh: Use single '@'.
2020-06-20 13:18:11 +02:00
Ludovic Courtès 5a02f8e384
environment: '--container' honors '--preserve'.
* guix/scripts/environment.scm (launch-environment/container): Add
 #:white-list parameter and  honor it.
(guix-environment): Pass #:white-list to 'launch-environment/container'.
* tests/guix-environment-container.sh: Add test.
2019-10-03 23:48:59 +02:00
Ludovic Courtès 75a6f66815
tests: Move 'guix environment -C --no-cwd' test where it belongs.
This ensures that this test is skipped in contexts where user namespaces
are not supported, instead of failing.

This is a followup to commit b6dc08393e.

* tests/guix-environment.sh: Move '--container --no-cwd' test to...
* tests/guix-environment-container.sh: ... here.
2019-08-17 16:23:05 +02:00
Ludovic Courtès 1ccc0f807d
environment: '-C' creates namespaces where the user is not root.
* guix/scripts/environment.scm (launch-environment/container): Add UID
and GID.  Use them in PASSWD and GROUPS.  Pass them as #:guest-uid and
 #:guest-gid to 'call-with-container'.
* tests/guix-environment-container.sh: Test the inner UID.
In '--user' test, replace hard-coded 0 with 1000.
* doc/guix.texi (Invoking guix environment): Adjust accordingly.
2019-04-02 18:15:37 +02:00
Ludovic Courtès 952afb6f8c
environment: Create /etc/group in containers.
Reported by Pierre Neidhardt <mail@ambrevar.xyz>.

* guix/scripts/environment.scm (launch-environment/container): Create
GROUPS and call 'write-group'.
* tests/guix-environment-container.sh: Test it.
2019-03-26 18:11:52 +01:00
Ludovic Courtès 8a9922bdee
environment: Use (gnu build accounts) for /etc/passwd handling.
* guix/scripts/environment.scm (launch-environment/container): Remove
call to 'mock-passwd'; instantiate a <password-entry> instead.  Call
'write-passwd' to write the pasword database instead of using custom
code.
(mock-passwd): Remove.
* tests/guix-environment-container.sh: Test 'getpwuid'.
2019-03-26 18:11:52 +01:00
Mike Gerwitz e37944d827
environment: Add --user.
This change allows overriding the home directory of all filesystem mappings to
help hide the identity of the calling user in a container.

* doc/guix.texi (Invoking guix environment)[--container]: Mention --user.
[--user]: Add item.
* guix/scripts/environment.scm (show-help): Add --user.
(%options): Add --user.
(launch-environment/container) Add 'user' parameter.  Update doc.  Override
'user-mappings' using 'override-user-mappings'.  Consider override for chdir.
(mock-passwd, user-override-home, overrid-euser-dir): New procedures.
(guix-environment): Disallow --user without --container.  Provide user to
'launch-environment/container'.
* tests/guix-environment.sh: Add user test.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2018-03-02 11:55:43 +01:00
Mike Gerwitz 07ec349229
environment: Add --link-profile.
This change is motivated by attempts to run programs (like GNU IceCat) within
containers.  The 'fontconfig' program, for example, is configured explicitly
to check ~/.guix-profile for additional fonts.

There were no existing container tests in 'tests/guix-environment.sh', but I
added one anyway for this change.

* doc/guix.texi (Invoking guix environment): Add '--link-profile'.
* guix/scripts/environment.scm (show-help): Add '--link-profile'.
(%options): Add 'link-profile' as '#\P', assigned to 'link-profile?'.
(link-environment): New procedure.
(launch-environment/container): Use it when 'link-profile?'.
[link-profile?]: New parameter.
(guix-environment): Leave when '--link-prof' but not '--container'.  Add
'#:link-profile?' argument to 'launch-environment/container' application.
* tests/guix-environment-container.sh: New '--link-profile' test.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2018-03-02 11:55:42 +01:00
Ludovic Courtès 7cdec6a90a
tests: Fix 'guix environment --container' test in the presence of tmpfs.
Reported by Ting-Wei Lan <lantw44@gmail.com>.
This is a followup to 1250034d5a.

* tests/guix-environment-container.sh (mount_test_code): Reverse order
of 'string-prefix?' arguments.
2016-08-29 00:09:44 +02:00
Ludovic Courtès 1250034d5a
tests: 'guix-environment-container.sh' works when run from a tmpfs.
Fixes <http://bugs.gnu.org/22004>.
Reported by Ting-Wei Lan <lantw44@gmail.com>.

* tests/guix-environment-container.sh (mount_test_code): Add 'match'
clause to ignore "/"; augment clause that ignores specific file system
types such that it does not ignore parent mount points.
2016-07-31 18:51:38 +02:00
Ludovic Courtès c06f6db7a4
container: Gracefully report mount errors in the child process.
Fixes <http://bugs.gnu.org/23306>.

* gnu/build/linux-container.scm (run-container): Use 'socketpair'
instead of 'pipe'.  Rename 'in' to 'child' and 'out' to 'parent'.  Send
a 'ready message or an exception argument list from the child to the
parent; adjust the parent accordingly.
* tests/containers.scm ("call-with-container, mnt namespace, wrong bind
mount"): New test.
* tests/guix-environment-container.sh: Add test with
--expose=/does-not-exist.
2016-05-31 00:11:04 +02:00
David Thompson 13bc8d5e4f environment: Properly handle SIGINT.
Switching to execlp means that the process spawned in a container is PID
1, which obsoleted one of the 'guix environment --container' tests
because the init process can't be killed in the usual manner.

* guix/scripts/environment.scm (launch-environment/fork): New procedure.
(launch-environment): Switch from system* to execlp.  Add handler for
SIGINT.
(guix-environment): Use launch-environment/fork.
* tests/guix-environment-container.sh: Replace abnormal exit test with
one that works now that the spawned process is PID 1.
2016-03-27 15:09:21 -04:00
David Thompson 779aa003fb scripts: environment: Build environments as profiles.
Fixes <http://bugs.gnu.org/19816>.

* guix/scripts/environment.scm (evaluate-input-search-paths)
(build-inputs): Delete.
(evaluate-profile-search-paths, strip-input-name)
(package-or-package+output?, package-environment-inputs)
(build-environment, inputs->profile-derivations): New procedures.
(create-environment, show-search-paths, launch-environment)
(launch-environment/container): Replace 'inputs' argument
with 'profile' argument.
(package+propagated-inputs): Strip off names off of input tuples.
(options/resolve-packages): Handle input tuples that specify an output
in expressions.
(guix-environment): Convert inputs into a profile to use in the
environment.  Remove non-package inputs such as origins from
environment inputs.
* doc/guix.texi ("invoking guix environment"): Document package+output
tuples for --expression option.
* tests/guix-environment.sh: Update tests.
* tests/guix-environment-container.sh: Likewise.

Co-authored-by: Ludovic Courtès <ludo@gnu.org>
2016-02-12 22:02:06 +01:00
Ludovic Courtès 82e64fc14e environment: Correctly handle abnormal exits.
Fixes <http://bugs.gnu.org/21958>.

* guix/scripts/environment.scm (status->exit-code): New procedure.
(exit/status, primitive-exit/status): Use it.
* tests/guix-environment-container.sh: Add test.
2015-11-21 22:26:13 +01:00
Ludovic Courtès 6493fd0458 tests: Skip 'guix-container-environment.sh' when support is missing.
Fixes <http://bugs.gnu.org/21410>.
Reported by Alex Vong <alexvong1995@gmail.com>.

* tests/guix-environment-container.sh: Exit with 77 when
'((@@ (guix scripts environment) assert-container-features))' fails.
2015-11-21 22:26:13 +01:00
Ludovic Courtès c8855b9918 tests: Use the canonical current directory name.
* tests/guix-environment-container.sh (current_dir): New variable.  Use
  it when grepping "mounts".
2015-11-04 12:10:11 +01:00
Ludovic Courtès 855038b294 tests: Print the mounts visible in the container.
* tests/guix-environment-container.sh: Print the content of
  $tmpdir/mounts.
2015-10-28 15:55:10 +01:00
David Thompson f535dcbe19 scripts: environment: Add --container option.
* guix/scripts/system.scm (specification->file-system-mapping): Move from
  here...
* guix/ui.scm (specification->file-system-mapping): ... to here.
* guix/scripts/enviroment.scm (show-help): Show help for new options.
  (%options): Add --container --network, --expose, and --share options.
  (%network-configuration-files): New variable.
  (launch-environment, launch-environment/container, requisites*,
  inputs->requisites): New procedures.
  (guix-environment): Spawn new process in a container when requested.
* doc/guix.texi (Invoking guix environment): Document it.
* tests/guix-environment-container.sh: New file.
* Makefile.am (SH_TESTS): Add it.
2015-10-25 20:27:19 -04:00