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 container_supported
()
31 if guile
-c '((@ (guix scripts environment) assert-container-features))'
39 NIX_STORE_DIR
="$(guile -c '(use-modules (guix config))(display %storedir)')"
40 localstatedir
="$(guile -c '(use-modules (guix config))(display %localstatedir)')"
41 GUIX_DAEMON_SOCKET
="$localstatedir/guix/daemon-socket/socket"
42 export NIX_STORE_DIR GUIX_DAEMON_SOCKET
44 # Run tests only when a "real" daemon is available.
45 if ! guile
-c '(use-modules (guix)) (exit (false-if-exception (open-connection)))'
50 STORE_PARENT
="$(dirname "$NIX_STORE_DIR")"
52 if test "$STORE_PARENT" = "/"; then exit 77; fi
54 test_directory
="$(mktemp -d)"
55 trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
58 cd "$test_directory" ||
exit 77
60 cat > "home.scm" <<'EOF'
61 (use-modules (guix gexp)
64 (gnu home services shells)
70 (simple-service 'test-config
71 home-files-service-type
72 (list `("config/test.conf"
75 "the content of ~/.config/test.conf"))))
77 (service home-bash-service-type
78 (home-bash-configuration
80 (bashrc (list (local-file "dot-bashrc")))))
82 (simple-service 'home-bash-service-extension-test
83 home-bash-service-type
88 "bashrc-test-config.sh"
89 "# the content of bashrc-test-config.sh"))))))))
92 echo -n "# dot-bashrc test file for guix home" > "dot-bashrc"
94 # Check whether the graph commands work as expected.
95 guix home extension-graph
"home.scm" |
grep 'label = "home-activation"'
96 guix home extension-graph
"home.scm" |
grep 'label = "home-symlink-manager"'
97 guix home extension-graph
"home.scm" |
grep 'label = "home"'
99 # There are no Shepherd services so the one below must fail.
100 ! guix home shepherd-graph
"home.scm"
102 if container_supported
104 # Run the home in a container.
105 guix home container home.scm
-- true
106 ! guix home container home.scm
-- false
107 test "$(guix home container home.scm -- echo '$HOME')" = "$HOME"
108 guix home container home.scm
-- cat '~/.config/test.conf' | \
109 grep "the content of"
110 guix home container home.scm
-- test -h '~/.bashrc'
111 test "$(guix home container home.scm -- id -u)" = 1000
112 ! guix home container home.scm
-- test -f '$HOME/sample/home.scm'
113 guix home container home.scm
--expose="$PWD=$HOME/sample" -- \
114 test -f '$HOME/sample/home.scm'
115 ! guix home container home.scm
--expose="$PWD=$HOME/sample" -- \
116 rm -v '$HOME/sample/home.scm'
118 echo "'guix home container' test SKIPPED" >&2
121 HOME
="$test_directory"
125 # Test 'guix home reconfigure'.
128 echo "# This file will be overridden and backed up." > "$HOME/.bashrc"
129 mkdir
"$HOME/.config"
130 echo "This file will be overridden too." > "$HOME/.config/test.conf"
131 echo "This file will stay around." > "$HOME/.config/random-file"
133 guix home reconfigure
"${test_directory}/home.scm"
134 test -d "${HOME}/.guix-home"
135 test -h "${HOME}/.bash_profile"
136 test -h "${HOME}/.bashrc"
137 test "$(tail -n 2 "${HOME}/.bashrc
")" == "\
138 # dot-bashrc test file for guix home
139 # the content of bashrc-test-config.sh"
140 grep -q "the content of ~/.config/test.conf" "${HOME}/.config/test.conf"
142 # This one should still be here.
143 grep "stay around" "$HOME/.config/random-file"
145 # Make sure preexisting files were backed up.
146 grep "overridden" "$HOME"/*guix-home
*backup
/.bashrc
147 grep "overridden" "$HOME"/*guix-home
*backup
/.config
/test.conf
148 rm -r "$HOME"/*guix-home
*backup
151 # Test 'guix home describe'.
157 |
grep 'configuration file:' \
161 test "$(cat "$
(configuration_file
)")" == "$(cat home.scm)"
163 canonical_file_name
()
166 |
grep 'canonical file name:' \
170 test "$(canonical_file_name)" == "$(readlink "${HOME}/.guix-home
")"
173 # Configure a new generation.
176 # Change the bashrc snippet content and comment out one service.
177 sed -i "home.scm" -e's/the content of/the NEW content of/g'
178 sed -i "home.scm" -e"s/(simple-service 'test-config/#;(simple-service 'test-config/g"
180 guix home reconfigure
"${test_directory}/home.scm"
181 test "$(tail -n 2 "${HOME}/.bashrc
")" == "\
182 # dot-bashrc test file for guix home
183 # the NEW content of bashrc-test-config.sh"
185 # This file must have been removed and not backed up.
186 ! test -e "$HOME/.config/test.conf"
187 ! test -e "$HOME"/*guix-home
*backup
/.config
/test.conf
189 test "$(cat "$
(configuration_file
)")" == "$(cat home.scm)"
190 test "$(canonical_file_name)" == "$(readlink "${HOME}/.guix-home
")"
192 test $
(guix home list-generations |
grep "^Generation" |
wc -l) -eq 2
195 # Test 'guix home search'.
198 guix home search mcron |
grep "^name: home-mcron"
199 guix home search job manager |
grep "^name: home-mcron"