1
0
mirror of https://git.savannah.gnu.org/git/guix.git synced 2026-04-06 13:10:33 +02:00

guix home: Add 'container' command.

* guix/scripts/home.scm (show-help, %options): Add '--network',
'--share', and '--expose'.
(not-config?, user-shell, spawn-home-container): New procedures.
(%default-system-profile): New variable.
(perform-action): Add #:file-system-mappings, #:container-command,
and #:network?; honor them.
(process-action): Adjust accordingly.
(guix-home)[parse-sub-command]: Add "container".
[parse-args]: New procedure.
Use it instead of 'parse-command-line'.
* tests/guix-home.sh: Add tests.
* doc/guix.texi (Declaring the Home Environment): Mention 'guix home
container' as a way to test configuration.
(Invoking guix home): Document it.
This commit is contained in:
Ludovic Courtès
2022-03-13 22:44:54 +01:00
parent cff9fee82a
commit 094a2cfbe4
3 changed files with 347 additions and 38 deletions

View File

@@ -26,6 +26,16 @@ set -e
guix home --version
container_supported ()
{
if guile -c '((@ (guix scripts environment) assert-container-features))'
then
return 0
else
return 1
fi
}
NIX_STORE_DIR="$(guile -c '(use-modules (guix config))(display %storedir)')"
localstatedir="$(guile -c '(use-modules (guix config))(display %localstatedir)')"
GUIX_DAEMON_SOCKET="$localstatedir/guix/daemon-socket/socket"
@@ -47,20 +57,6 @@ trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
(
cd "$test_directory" || exit 77
HOME="$test_directory"
export HOME
#
# Test 'guix home reconfigure'.
#
echo "# This file will be overridden and backed up." > "$HOME/.bashrc"
mkdir "$HOME/.config"
echo "This file will be overridden too." > "$HOME/.config/test.conf"
echo "This file will stay around." > "$HOME/.config/random-file"
echo -n "# dot-bashrc test file for guix home" > "dot-bashrc"
cat > "home.scm" <<'EOF'
(use-modules (guix gexp)
(gnu home)
@@ -93,6 +89,8 @@ trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
"# the content of bashrc-test-config.sh"))))))))
EOF
echo -n "# dot-bashrc test file for guix home" > "dot-bashrc"
# Check whether the graph commands work as expected.
guix home extension-graph "home.scm" | grep 'label = "home-activation"'
guix home extension-graph "home.scm" | grep 'label = "home-symlink-manager"'
@@ -101,6 +99,37 @@ EOF
# There are no Shepherd services so the one below must fail.
! guix home shepherd-graph "home.scm"
if container_supported
then
# Run the home in a container.
guix home container home.scm -- true
! guix home container home.scm -- false
test "$(guix home container home.scm -- echo '$HOME')" = "$HOME"
guix home container home.scm -- cat '~/.config/test.conf' | \
grep "the content of"
guix home container home.scm -- test -h '~/.bashrc'
test "$(guix home container home.scm -- id -u)" = 1000
! guix home container home.scm -- test -f '$HOME/sample/home.scm'
guix home container home.scm --expose="$PWD=$HOME/sample" -- \
test -f '$HOME/sample/home.scm'
! guix home container home.scm --expose="$PWD=$HOME/sample" -- \
rm -v '$HOME/sample/home.scm'
else
echo "'guix home container' test SKIPPED" >&2
fi
HOME="$test_directory"
export HOME
#
# Test 'guix home reconfigure'.
#
echo "# This file will be overridden and backed up." > "$HOME/.bashrc"
mkdir "$HOME/.config"
echo "This file will be overridden too." > "$HOME/.config/test.conf"
echo "This file will stay around." > "$HOME/.config/random-file"
guix home reconfigure "${test_directory}/home.scm"
test -d "${HOME}/.guix-home"
test -h "${HOME}/.bash_profile"