1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2021 Andrew Tropin <andrew@trop.in>
3 # Copyright © 2021 Oleg Pykhalov <go.wigust@gmail.com>
4 # Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
6 # This file is part of GNU Guix.
8 # GNU Guix is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or (at
11 # your option) any later version.
13 # GNU Guix is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22 # Test the 'guix home' using the external store, if any.
29 NIX_STORE_DIR
="$(guile -c '(use-modules (guix config))(display %storedir)')"
30 localstatedir
="$(guile -c '(use-modules (guix config))(display %localstatedir)')"
31 GUIX_DAEMON_SOCKET
="$localstatedir/guix/daemon-socket/socket"
32 export NIX_STORE_DIR GUIX_DAEMON_SOCKET
34 # Run tests only when a "real" daemon is available.
35 if ! guile
-c '(use-modules (guix)) (exit (false-if-exception (open-connection)))'
40 STORE_PARENT
="$(dirname "$NIX_STORE_DIR")"
42 if test "$STORE_PARENT" = "/"; then exit 77; fi
44 test_directory
="$(mktemp -d)"
45 trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
48 cd "$test_directory" ||
exit 77
50 HOME
="$test_directory"
54 # Test 'guix home reconfigure'.
57 echo "# This file will be overridden and backed up." > "$HOME/.bashrc"
59 echo "This file will be overridden too." > "$HOME/.config/test.conf"
60 echo "This file will stay around." > "$HOME/.config/random-file"
62 echo -n "# dot-bashrc test file for guix home" > "dot-bashrc"
64 cat > "home.scm" <<'EOF'
65 (use-modules (guix gexp)
68 (gnu home services shells)
74 (simple-service 'test-config
75 home-files-service-type
76 (list `("config/test.conf"
79 "the content of ~/.config/test.conf"))))
81 (service home-bash-service-type
82 (home-bash-configuration
86 (local-file (string-append (dirname (current-filename))
89 (simple-service 'home-bash-service-extension-test
90 home-bash-service-type
95 "bashrc-test-config.sh"
96 "# the content of bashrc-test-config.sh"))))))))
99 guix home reconfigure
"${test_directory}/home.scm"
100 test -d "${HOME}/.guix-home"
101 test -h "${HOME}/.bash_profile"
102 test -h "${HOME}/.bashrc"
103 test "$(tail -n 2 "${HOME}/.bashrc
")" == "\
104 # dot-bashrc test file for guix home
105 # the content of bashrc-test-config.sh"
106 grep -q "the content of ~/.config/test.conf" "${HOME}/.config/test.conf"
108 # This one should still be here.
109 grep "stay around" "$HOME/.config/random-file"
111 # Make sure preexisting files were backed up.
112 grep "overridden" "$HOME"/*guix-home
*backup
/.bashrc
113 grep "overridden" "$HOME"/*guix-home
*backup
/.config
/test.conf
116 # Test 'guix home describe'.
122 |
grep 'configuration file:' \
126 test "$(cat "$
(configuration_file
)")" == "$(cat home.scm)"
128 canonical_file_name
()
131 |
grep 'canonical file name:' \
135 test "$(canonical_file_name)" == "$(readlink "${HOME}/.guix-home
")"
138 # Test 'guix home search'.
141 guix home search mcron |
grep "^name: home-mcron"
142 guix home search job manager |
grep "^name: home-mcron"