guix-system.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
  3. # Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
  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 'guix system', mostly error reporting.
  21. #
  22. set -e
  23. guix system --version
  24. tmpfile="t-guix-system-$$"
  25. errorfile="t-guix-system-error-$$"
  26. # Note: This directory is chosen outside $builddir so that relative file name
  27. # canonicalization doesn't mess up with 'current-source-directory', used by
  28. # 'local-file' ('load' forces 'relative' for
  29. # %FILE-PORT-NAME-CANONICALIZATION.)
  30. tmpdir="${TMPDIR:-/tmp}/t-guix-system-$$"
  31. mkdir "$tmpdir"
  32. trap 'rm -f "$tmpfile" "$errorfile" "$tmpdir"/*; rmdir "$tmpdir"' EXIT
  33. # Reporting of syntax errors.
  34. cat > "$tmpfile"<<EOF
  35. ;; This is line 1, and the next one is line 2.
  36. (operating-system)
  37. ;; The 'T' is at column 3.
  38. EOF
  39. if guix system vm "$tmpfile" 2> "$errorfile"
  40. then
  41. # This must not succeed.
  42. exit 1
  43. else
  44. grep "$tmpfile:2:3:.*missing.* initializers" "$errorfile"
  45. fi
  46. cat > "$tmpfile"<<EOF
  47. ;; This is line 1, and the next one is line 2.
  48. (operating-system
  49. ;; This is line 3, and there is no closing paren!
  50. EOF
  51. if guix system vm "$tmpfile" 2> "$errorfile"
  52. then
  53. # This must not succeed.
  54. exit 1
  55. else
  56. grep "$tmpfile:4:1: missing closing paren" "$errorfile"
  57. fi
  58. # Reporting of module not found errors.
  59. cat > "$tmpfile" <<EOF
  60. ;; Line 1.
  61. (use-modules (gnu))
  62. (use-service-modules openssh)
  63. EOF
  64. if guix system build "$tmpfile" -n 2> "$errorfile"
  65. then false
  66. else
  67. grep "$tmpfile:3:2: .*module .*openssh.*not found" "$errorfile"
  68. grep "Try.*use-service-modules ssh" "$errorfile"
  69. fi
  70. cat > "$tmpfile" <<EOF
  71. ;; Line 1.
  72. (use-modules (gnu))
  73. (use-package-modules qemu)
  74. EOF
  75. if guix system build "$tmpfile" -n 2> "$errorfile"
  76. then false
  77. else
  78. grep "$tmpfile:3:2: .*module .*qemu.*not found" "$errorfile"
  79. grep "Try.*use-package-modules virtualization" "$errorfile"
  80. fi
  81. # Reporting of unbound variables.
  82. cat > "$tmpfile" <<EOF
  83. (use-modules (gnu)) ; 1
  84. (use-service-modules networking) ; 2
  85. (operating-system ; 4
  86. (host-name "antelope") ; 5
  87. (timezone "Europe/Paris") ; 6
  88. (locale "en_US.UTF-8") ; 7
  89. (bootloader (GRUB-config (device "/dev/sdX"))) ; 9
  90. (file-systems (cons (file-system
  91. (device "root")
  92. (title 'label)
  93. (mount-point "/")
  94. (type "ext4"))
  95. %base-file-systems)))
  96. EOF
  97. if guix system build "$tmpfile" -n 2> "$errorfile"
  98. then false
  99. else
  100. if test "`guile -c '(display (effective-version))'`" = 2.2
  101. then
  102. # FIXME: With Guile 2.2.0 the error is reported on line 4.
  103. # See <http://bugs.gnu.org/26107>.
  104. grep "$tmpfile:[49]:[0-9]\+: GRUB-config.*[Uu]nbound variable" "$errorfile"
  105. else
  106. grep "$tmpfile:9:[0-9]\+: GRUB-config.*[Uu]nbound variable" "$errorfile"
  107. fi
  108. fi
  109. OS_BASE='
  110. (host-name "antelope")
  111. (timezone "Europe/Paris")
  112. (locale "en_US.UTF-8")
  113. (bootloader (bootloader-configuration
  114. (bootloader grub-bootloader)
  115. (device "/dev/sdX")))
  116. (file-systems (cons (file-system
  117. (device "root")
  118. (title (string->symbol "label"))
  119. (mount-point "/")
  120. (type "ext4"))
  121. %base-file-systems))
  122. '
  123. # Reporting of duplicate service identifiers.
  124. cat > "$tmpfile" <<EOF
  125. (use-modules (gnu))
  126. (use-service-modules networking)
  127. (operating-system
  128. $OS_BASE
  129. (services (cons* (dhcp-client-service)
  130. (dhcp-client-service) ;twice!
  131. %base-services)))
  132. EOF
  133. if guix system vm "$tmpfile" 2> "$errorfile"
  134. then
  135. # This must not succeed.
  136. exit 1
  137. else
  138. grep "service 'networking'.*more than once" "$errorfile"
  139. fi
  140. # Reporting unmet shepherd requirements.
  141. cat > "$tmpfile" <<EOF
  142. (use-modules (gnu) (gnu services shepherd))
  143. (use-service-modules networking)
  144. (define buggy-service-type
  145. (shepherd-service-type
  146. 'buggy
  147. (lambda _
  148. (shepherd-service
  149. (provision '(buggy!))
  150. (requirement '(does-not-exist))
  151. (start #t)))))
  152. (operating-system
  153. $OS_BASE
  154. (services (cons (service buggy-service-type #t)
  155. %base-services)))
  156. EOF
  157. if guix system build "$tmpfile" 2> "$errorfile"
  158. then
  159. exit 1
  160. else
  161. grep "service 'buggy!'.*'does-not-exist'.*not provided" "$errorfile"
  162. fi
  163. # Reporting inconsistent user accounts.
  164. make_user_config ()
  165. {
  166. cat > "$tmpfile" <<EOF
  167. (use-modules (gnu))
  168. (use-service-modules networking)
  169. (operating-system
  170. (host-name "antelope")
  171. (timezone "Europe/Paris")
  172. (locale "en_US.UTF-8")
  173. (bootloader (bootloader-configuration
  174. (bootloader grub-bootloader)
  175. (device "/dev/sdX")))
  176. (file-systems (cons (file-system
  177. (device "root")
  178. (title 'label)
  179. (mount-point "/")
  180. (type "ext4"))
  181. %base-file-systems))
  182. (users (list (user-account
  183. (name "dave")
  184. (home-directory "/home/dave")
  185. (group "$1")
  186. (supplementary-groups '("$2"))))))
  187. EOF
  188. }
  189. make_user_config "users" "wheel"
  190. guix system build "$tmpfile" -n # succeeds
  191. guix system build "$tmpfile" -d # succeeds
  192. guix system build "$tmpfile" -d | grep '\.drv$'
  193. guix system vm "$tmpfile" -d # succeeds
  194. guix system vm "$tmpfile" -d | grep '\.drv$'
  195. make_user_config "group-that-does-not-exist" "users"
  196. if guix system build "$tmpfile" -n 2> "$errorfile"
  197. then false
  198. else grep "primary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
  199. make_user_config "users" "group-that-does-not-exist"
  200. if guix system build "$tmpfile" -n 2> "$errorfile"
  201. then false
  202. else grep "supplementary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
  203. # Try 'local-file' and relative file name resolution.
  204. cat > "$tmpdir/config.scm"<<EOF
  205. (use-modules (gnu))
  206. (use-service-modules networking)
  207. (operating-system
  208. $OS_BASE
  209. (services (cons (tor-service (local-file "my-torrc"))
  210. %base-services)))
  211. EOF
  212. cat > "$tmpdir/my-torrc"<<EOF
  213. # This is an example file.
  214. EOF
  215. # In both cases 'my-torrc' should be properly resolved.
  216. guix system build "$tmpdir/config.scm" -n
  217. (cd "$tmpdir"; guix system build "config.scm" -n)
  218. # Searching.
  219. guix system search tor | grep "^name: tor"
  220. guix system search anonym network | grep "^name: tor"