guix-shell.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2021-2022 Ludovic Courtès <ludo@gnu.org>
  3. #
  4. # This file is part of GNU Guix.
  5. #
  6. # GNU Guix is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or (at
  9. # your option) any later version.
  10. #
  11. # GNU Guix is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # Test the 'guix shell' alias.
  20. #
  21. guix shell --version
  22. configdir="t-guix-shell-config-$$"
  23. tmpdir="t-guix-shell-$$"
  24. trap 'rm -r "$tmpdir" "$configdir"' EXIT
  25. mkdir "$tmpdir" "$configdir" "$configdir/guix"
  26. XDG_CONFIG_HOME="$(realpath $configdir)"
  27. export XDG_CONFIG_HOME
  28. guix shell --bootstrap --pure guile-bootstrap -- guile --version
  29. # '--symlink' can only be used with --container.
  30. guix shell --bootstrap guile-bootstrap -S /dummy=bin/guile && false
  31. # '--ad-hoc' is a thing of the past.
  32. guix shell --ad-hoc guile-bootstrap && false
  33. # Rejecting unsupported packages.
  34. guix shell -s armhf-linux intelmetool -n && false
  35. # Test approximately that the child process does not inherit extra file
  36. # descriptors. Ideally we'd check there's nothing more than 0, 1, and 2, but
  37. # we cannot do that because (1) we might be inheriting additional FDs, for
  38. # example due to <https://issues.guix.gnu.org/57567>, and (2) Bash itself
  39. # opens a couple of extra FDs.
  40. initial_fd_list="$(echo /proc/$$/fd/*)"
  41. fd_list="$(guix shell --bootstrap guile-bootstrap -- \
  42. "$SHELL" -c 'echo /proc/$$/fd/*')"
  43. test "$(echo $fd_list | wc -w)" -le "$(echo $initial_fd_list | wc -w)"
  44. # Ignoring unauthorized files.
  45. cat > "$tmpdir/guix.scm" <<EOF
  46. This is a broken guix.scm file.
  47. EOF
  48. (cd "$tmpdir"; SHELL="$(type -P true)" guix shell --bootstrap 2> "stderr") && false
  49. grep "not authorized" "$tmpdir/stderr"
  50. rm "$tmpdir/stderr"
  51. # Authorize the directory.
  52. echo "$(realpath "$tmpdir")" > "$configdir/guix/shell-authorized-directories"
  53. # Ignoring 'manifest.scm' and 'guix.scm' in non-interactive use.
  54. (cd "$tmpdir"; guix shell --bootstrap -- true)
  55. mv "$tmpdir/guix.scm" "$tmpdir/manifest.scm"
  56. (cd "$tmpdir"; guix shell --bootstrap -- true)
  57. rm "$tmpdir/manifest.scm"
  58. # Honoring the local 'manifest.scm' file.
  59. cat > "$tmpdir/manifest.scm" <<EOF
  60. (specifications->manifest '("guile-bootstrap"))
  61. EOF
  62. cat > "$tmpdir/fake-shell.sh" <<EOF
  63. #!$SHELL
  64. # This fake shell allows us to test interactive use.
  65. exec echo "\$GUIX_ENVIRONMENT"
  66. EOF
  67. chmod +x "$tmpdir/fake-shell.sh"
  68. profile1="$(cd "$tmpdir"; SHELL="$(realpath fake-shell.sh)" guix shell --bootstrap)"
  69. profile2="$(guix shell --bootstrap guile-bootstrap -- "$SHELL" -c 'echo $GUIX_ENVIRONMENT')"
  70. test -n "$profile1"
  71. test "$profile1" = "$profile2"
  72. rm "$tmpdir/manifest.scm"
  73. # Do not read manifest when passed '-q'.
  74. echo "Broken manifest." > "$tmpdir/manifest.scm"
  75. (cd "$tmpdir"; SHELL="$(realpath fake-shell.sh)" guix shell --bootstrap -q)
  76. rm "$tmpdir/manifest.scm"
  77. # Make sure '-D' affects only the immediately following '-f', and not packages
  78. # that appear later: <https://issues.guix.gnu.org/52093>.
  79. cat > "$tmpdir/empty-package.scm" <<EOF
  80. (use-modules (guix) (guix tests)
  81. (guix build-system trivial))
  82. (dummy-package "empty-package"
  83. (build-system trivial-build-system)) ;zero inputs
  84. EOF
  85. guix shell --bootstrap --pure -D -f "$tmpdir/empty-package.scm" \
  86. guile-bootstrap -- guile --version
  87. rm "$tmpdir/empty-package.scm"
  88. if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
  89. then
  90. # Compute the build environment for the initial GNU Make.
  91. guix shell --bootstrap --no-substitutes --search-paths --pure \
  92. -D -e '(@ (guix tests) gnu-make-for-tests)' > "$tmpdir/a"
  93. # Make sure bootstrap binaries are in the profile.
  94. profile=`grep "^export PATH" "$tmpdir/a" | sed -r 's|^.*="(.*)/bin"|\1|'`
  95. # Make sure the bootstrap binaries are all listed where they belong.
  96. grep -E "^export PATH=\"$profile/bin\"" "$tmpdir/a"
  97. grep -E "^export C_INCLUDE_PATH=\"$profile/include\"" "$tmpdir/a"
  98. grep -E "^export LIBRARY_PATH=\"$profile/lib\"" "$tmpdir/a"
  99. for dep in bootstrap-binaries-0 gcc-bootstrap-0 glibc-bootstrap-0
  100. do
  101. guix gc --references "$profile" | grep "$dep"
  102. done
  103. # 'make-boot0' itself must not be listed.
  104. guix gc --references "$profile" | grep make-boot0 && false
  105. # Honoring the local 'guix.scm' file.
  106. echo '(@ (guix tests) gnu-make-for-tests)' > "$tmpdir/guix.scm"
  107. (cd "$tmpdir"; guix shell --bootstrap --search-paths --pure > "b")
  108. cmp "$tmpdir/a" "$tmpdir/b"
  109. rm "$tmpdir/guix.scm"
  110. fi