| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 |
|
| 21 | |
| 22 | |
| 23 | |
| 24 |
|
| 25 | set -e
|
| 26 |
|
| 27 | guix home --version
|
| 28 |
|
| 29 | container_supported ()
|
| 30 | {
|
| 31 | if guile -c '((@ (guix scripts environment) assert-container-features))'
|
| 32 | then
|
| 33 | return 0
|
| 34 | else
|
| 35 | return 1
|
| 36 | fi
|
| 37 | }
|
| 38 |
|
| 39 | localstatedir="$(guile -c '(use-modules (guix config))(display %localstatedir)')"
|
| 40 | NIX_STORE_DIR="$(guile -c '(use-modules (guix config))(display %storedir)')"
|
| 41 | GUIX_DAEMON_SOCKET="$localstatedir/guix/daemon-socket/socket"
|
| 42 | GUIX_BUILD_OPTIONS="--timeout=`guile -c '(use-modules (guix tests))(display %tests-build-timeout)'`"
|
| 43 | export NIX_STORE_DIR GUIX_DAEMON_SOCKET GUIX_BUILD_OPTIONS
|
| 44 |
|
| 45 | |
| 46 | if ! guile -c '(use-modules (guix)) (exit (false-if-exception (open-connection)))'
|
| 47 | then
|
| 48 | exit 77
|
| 49 | fi
|
| 50 |
|
| 51 | STORE_PARENT="$(dirname "$NIX_STORE_DIR")"
|
| 52 | export STORE_PARENT
|
| 53 | if test "$STORE_PARENT" = "/"; then exit 77; fi
|
| 54 |
|
| 55 | test_directory="$(mktemp -d)"
|
| 56 | trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
|
| 57 |
|
| 58 | (
|
| 59 | cd "$test_directory" || exit 77
|
| 60 |
|
| 61 | cat > "home.scm" <<'EOF'
|
| 62 | (use-modules (guix gexp)
|
| 63 | (gnu home)
|
| 64 | (gnu home services)
|
| 65 | (gnu home services shells)
|
| 66 | (gnu packages bash)
|
| 67 | (gnu services))
|
| 68 |
|
| 69 | (home-environment
|
| 70 | (services
|
| 71 | (list
|
| 72 | (simple-service 'test-config
|
| 73 | home-files-service-type
|
| 74 | (list `(".config/test.conf"
|
| 75 | ,(plain-file
|
| 76 | "tmp-file.txt"
|
| 77 | "the content of ~/.config/test.conf"))
|
| 78 |
|
| 79 | `("symlink" ,(symlink-to "<test_directory>"))))
|
| 80 |
|
| 81 | (service home-bash-service-type
|
| 82 | (home-bash-configuration
|
| 83 | (guix-defaults? #t)
|
| 84 | (bashrc (list (local-file "dot-bashrc")))))
|
| 85 |
|
| 86 | (simple-service 'add-environment-variable
|
| 87 | home-environment-variables-service-type
|
| 88 | `(("TODAY" . "26 messidor")
|
| 89 | ("SHELL" . ,(file-append bash "/bin/bash"))
|
| 90 | ("BUILDHOST_TIME" . ,#~(strftime "%c"
|
| 91 | (localtime (current-time))))
|
| 92 | ("STRING_WITH_ESCAPES" . "chars: \" /\\")
|
| 93 | ("LITERAL" . ,(literal-string "${abc}"))))
|
| 94 |
|
| 95 | (simple-service 'home-bash-service-extension-test
|
| 96 | home-bash-service-type
|
| 97 | (home-bash-extension
|
| 98 | (environment-variables
|
| 99 | '(("PS1" . "$GUIX_ENVIRONMENT λ ")))
|
| 100 | (aliases
|
| 101 | `(("run" . "guix shell")
|
| 102 | ("path" . ,(literal-string "echo $PATH"))))
|
| 103 | (bashrc
|
| 104 | (list
|
| 105 | (plain-file
|
| 106 | "bashrc-test-config.sh"
|
| 107 | "# the content of bashrc-test-config.sh"))))))))
|
| 108 | EOF
|
| 109 |
|
| 110 | sed -i "s,<test_directory>,$test_directory," home.scm
|
| 111 | echo -n "# dot-bashrc test file for guix home" > "dot-bashrc"
|
| 112 |
|
| 113 | |
| 114 | guix home extension-graph "home.scm" | grep 'label = "home-activation"'
|
| 115 | guix home extension-graph "home.scm" | grep 'label = "home-symlink-manager"'
|
| 116 | guix home extension-graph "home.scm" | grep 'label = "home"'
|
| 117 |
|
| 118 | |
| 119 | guix home shepherd-graph "home.scm" && false
|
| 120 |
|
| 121 | if container_supported
|
| 122 | then
|
| 123 | |
| 124 | |
| 125 | |
| 126 | SHELL=bash
|
| 127 | guix home container home.scm -- true
|
| 128 | guix home container home.scm -- false && false
|
| 129 | test "$(guix home container home.scm -- echo '$HOME')" = "$HOME"
|
| 130 | guix home container home.scm -- cat '~/.config/test.conf' | \
|
| 131 | grep "the content of"
|
| 132 | guix home container home.scm -- test -h '~/.bashrc'
|
| 133 | guix home container home.scm -- test -h '~/symlink'
|
| 134 | test "$(guix home container home.scm -- id -u)" = 1000
|
| 135 | guix home container home.scm -- test -f '$HOME/sample/home.scm' && false
|
| 136 | guix home container home.scm --expose="$PWD=$HOME/sample" -- \
|
| 137 | test -f '$HOME/sample/home.scm'
|
| 138 | guix home container home.scm --expose="$PWD=$HOME/sample" -- \
|
| 139 | rm -v '$HOME/sample/home.scm' && false
|
| 140 | guix home container home.scm -- touch /whatever && false
|
| 141 | else
|
| 142 | echo "'guix home container' test SKIPPED" >&2
|
| 143 | fi
|
| 144 |
|
| 145 | HOME="$test_directory"
|
| 146 | export HOME
|
| 147 |
|
| 148 | |
| 149 | |
| 150 | |
| 151 |
|
| 152 | echo "# This file will be overridden and backed up." > "$HOME/.bashrc"
|
| 153 | mkdir "$HOME/.config"
|
| 154 | echo "This file will be overridden too." > "$HOME/.config/test.conf"
|
| 155 | echo "This file will stay around." > "$HOME/.config/random-file"
|
| 156 |
|
| 157 | guix home reconfigure "${test_directory}/home.scm"
|
| 158 | test -d "${HOME}/.guix-home"
|
| 159 | test -h "${HOME}/.bash_profile"
|
| 160 | test -h "${HOME}/.bashrc"
|
| 161 | test -h "${HOME}/symlink"
|
| 162 | test "$(readlink -f $HOME/symlink)" == "$test_directory"
|
| 163 | grep 'alias run="guix shell"' "$HOME/.bashrc"
|
| 164 | grep "alias path='echo \$PATH'" "$HOME/.bashrc"
|
| 165 | test "$(tail -n 2 "${HOME}/.bashrc")" == "\
|
| 166 | # dot-bashrc test file for guix home
|
| 167 | # the content of bashrc-test-config.sh"
|
| 168 | grep -q "the content of ~/.config/test.conf" "${HOME}/.config/test.conf"
|
| 169 | grep '^export PS1="\$GUIX_ENVIRONMENT λ "$' "${HOME}/.bash_profile"
|
| 170 |
|
| 171 | ( . "${HOME}/.guix-home/setup-environment"; test "$TODAY" = "26 messidor" )
|
| 172 | ( . "${HOME}/.guix-home/setup-environment"; test "$LITERAL" = '${abc}' )
|
| 173 | ( . "${HOME}/.guix-home/setup-environment";
|
| 174 | test "$STRING_WITH_ESCAPES" = "chars: \" /\\")
|
| 175 | ( . "${HOME}/.guix-home/setup-environment";
|
| 176 | echo "$SHELL" | grep "/gnu/store/.*/bin/bash" )
|
| 177 |
|
| 178 | |
| 179 | grep "stay around" "$HOME/.config/random-file"
|
| 180 |
|
| 181 | |
| 182 | grep "overridden" "$HOME"/*guix-home*backup/.bashrc
|
| 183 | grep "overridden" "$HOME"/*guix-home*backup/.config/test.conf
|
| 184 | rm -r "$HOME"/*guix-home*backup
|
| 185 |
|
| 186 | |
| 187 | |
| 188 | |
| 189 |
|
| 190 | configuration_file()
|
| 191 | {
|
| 192 | guix home describe \
|
| 193 | | grep 'configuration file:' \
|
| 194 | | cut -d : -f 2 \
|
| 195 | | xargs echo
|
| 196 | }
|
| 197 | test "$(cat "$(configuration_file)")" == "$(cat home.scm)"
|
| 198 |
|
| 199 | canonical_file_name()
|
| 200 | {
|
| 201 | guix home describe \
|
| 202 | | grep 'canonical file name:' \
|
| 203 | | cut -d : -f 2 \
|
| 204 | | xargs echo
|
| 205 | }
|
| 206 | test "$(canonical_file_name)" == "$(readlink "${HOME}/.guix-home")"
|
| 207 |
|
| 208 | |
| 209 | |
| 210 | |
| 211 |
|
| 212 | |
| 213 | sed -i "home.scm" -e's/the content of/the NEW content of/g'
|
| 214 | sed -i "home.scm" -e"s/(simple-service 'test-config/#;(simple-service 'test-config/g"
|
| 215 |
|
| 216 | guix home reconfigure "${test_directory}/home.scm"
|
| 217 | test "$(tail -n 2 "${HOME}/.bashrc")" == "\
|
| 218 | # dot-bashrc test file for guix home
|
| 219 | # the NEW content of bashrc-test-config.sh"
|
| 220 |
|
| 221 | |
| 222 | test ! -e "$HOME/.config/test.conf"
|
| 223 | test ! -e "$HOME"/*guix-home*backup/.config/test.conf
|
| 224 |
|
| 225 | test "$(cat "$(configuration_file)")" == "$(cat home.scm)"
|
| 226 | test "$(canonical_file_name)" == "$(readlink "${HOME}/.guix-home")"
|
| 227 |
|
| 228 | test $(guix home list-generations | grep "^Generation" | wc -l) -eq 2
|
| 229 |
|
| 230 | |
| 231 | |
| 232 | |
| 233 |
|
| 234 | guix home search mcron | grep "^name: home-mcron"
|
| 235 | guix home search scheduling daemon | grep "^name: home-mcron"
|
| 236 | )
|