guix-home.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #
  5. # This file is part of GNU Guix.
  6. #
  7. # GNU Guix is free software; you can redistribute it and/or modify it
  8. # under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 3 of the License, or (at
  10. # your option) any later version.
  11. #
  12. # GNU Guix is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. # Test the 'guix home' using the external store, if any.
  21. #
  22. set -e
  23. guix home --version
  24. NIX_STORE_DIR="$(guile -c '(use-modules (guix config))(display %storedir)')"
  25. localstatedir="$(guile -c '(use-modules (guix config))(display %localstatedir)')"
  26. GUIX_DAEMON_SOCKET="$localstatedir/guix/daemon-socket/socket"
  27. export NIX_STORE_DIR GUIX_DAEMON_SOCKET
  28. # Run tests only when a "real" daemon is available.
  29. if ! guile -c '(use-modules (guix)) (exit (false-if-exception (open-connection)))'
  30. then
  31. exit 77
  32. fi
  33. STORE_PARENT="$(dirname "$NIX_STORE_DIR")"
  34. export STORE_PARENT
  35. if test "$STORE_PARENT" = "/"; then exit 77; fi
  36. test_directory="$(mktemp -d)"
  37. trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
  38. (
  39. cd "$test_directory" || exit 77
  40. HOME="$test_directory"
  41. export HOME
  42. #
  43. # Test 'guix home reconfigure'.
  44. #
  45. printf "# dot-bashrc test file for guix home" > "dot-bashrc"
  46. cat > "home.scm" <<'EOF'
  47. (use-modules (guix gexp)
  48. (gnu home)
  49. (gnu home services)
  50. (gnu home services shells)
  51. (gnu services))
  52. (home-environment
  53. (services
  54. (list
  55. (simple-service 'test-config
  56. home-files-service-type
  57. (list `("config/test.conf"
  58. ,(plain-file
  59. "tmp-file.txt"
  60. "the content of ~/.config/test.conf"))))
  61. (service home-bash-service-type
  62. (home-bash-configuration
  63. (guix-defaults? #t)
  64. (bashrc
  65. (list
  66. (local-file (string-append (dirname (current-filename))
  67. "/dot-bashrc"))))))
  68. (simple-service 'home-bash-service-extension-test
  69. home-bash-service-type
  70. (home-bash-extension
  71. (bashrc
  72. (list
  73. (plain-file
  74. "bashrc-test-config.sh"
  75. "# the content of bashrc-test-config.sh"))))))))
  76. EOF
  77. guix home reconfigure "${test_directory}/home.scm"
  78. test -d "${HOME}/.guix-home"
  79. test -h "${HOME}/.bash_profile"
  80. test -h "${HOME}/.bashrc"
  81. test "$(tail -n 2 "${HOME}/.bashrc")" == "\
  82. # dot-bashrc test file for guix home
  83. # the content of bashrc-test-config.sh"
  84. grep -q "the content of ~/.config/test.conf" "${HOME}/.config/test.conf"
  85. #
  86. # Test 'guix home describe'.
  87. #
  88. configuration_file()
  89. {
  90. guix home describe \
  91. | grep 'configuration file:' \
  92. | cut -d : -f 2 \
  93. | xargs echo
  94. }
  95. test "$(cat "$(configuration_file)")" == "$(cat home.scm)"
  96. canonical_file_name()
  97. {
  98. guix home describe \
  99. | grep 'canonical file name:' \
  100. | cut -d : -f 2 \
  101. | xargs echo
  102. }
  103. test "$(canonical_file_name)" == "$(readlink "${HOME}/.guix-home")"
  104. #
  105. # Test 'guix home search'.
  106. #
  107. guix home search mcron | grep "^name: home-mcron"
  108. guix home search job manager | grep "^name: home-mcron"
  109. )