#!/bin/bash # GNU Guix --- Functional package management for GNU # Copyright © 2021 Oleg Pykhalov # # This file is part of GNU Guix. # # GNU Guix is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or (at # your option) any later version. # # GNU Guix is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GNU Guix. If not, see . # # Test the 'guix home' using the external store, if any. # guix home --version 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" export NIX_STORE_DIR GUIX_DAEMON_SOCKET # Run tests only when a "real" daemon is available. if ! guile -c '(use-modules (guix)) (exit (false-if-exception (open-connection)))' then exit 77 fi STORE_PARENT="$(dirname "$NIX_STORE_DIR")" export STORE_PARENT if test "$STORE_PARENT" = "/"; then exit 77; fi run_guix_home_without_home() { # Save current directory (Guix source directory) for later mount test_directory="$(mktemp -d)" trap 'umount $test_directory; rmdir $test_directory' EXIT mount --bind "$PWD" "$test_directory" # Make $HOME directory empty to preserve user's files mount --types tmpfs none "$HOME" # Mount Guix source directory in a clean environment mkdir -p "$PWD" mount --bind "$test_directory" "$PWD" cd "$PWD" || exit 77 cat > "dot-bashrc" <<'EOF' # dot-bashrc test file for guix home EOF cat > "home.scm" <<'EOF' (use-modules (gnu home) (gnu home-services) (gnu home services shells) (gnu services) (guix gexp)) (home-environment (services (list (service home-bash-service-type (home-bash-configuration (guix-defaults? #t) (bashrc (list (local-file (string-append (dirname (current-filename)) "/dot-bashrc"))))))))) EOF guix home reconfigure "${test_directory}/home.scm" } export -f run_guix_home_without_home unshare --mount --map-root-user --fork sh -c "run_guix_home_without_home"