guix-system.sh 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
  3. # Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
  4. # Copyright © 2018 Chris Marusich <cmmarusich@gmail.com>
  5. #
  6. # This file is part of GNU Guix.
  7. #
  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.
  12. #
  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.
  17. #
  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/>.
  20. #
  21. # Test 'guix system', mostly error reporting.
  22. #
  23. set -e
  24. guix system --version
  25. tmpfile="t-guix-system-$$"
  26. errorfile="t-guix-system-error-$$"
  27. # Note: This directory is chosen outside $builddir so that relative file name
  28. # canonicalization doesn't mess up with 'current-source-directory', used by
  29. # 'local-file' ('load' forces 'relative' for
  30. # %FILE-PORT-NAME-CANONICALIZATION.)
  31. tmpdir="${TMPDIR:-/tmp}/t-guix-system-$$"
  32. mkdir "$tmpdir"
  33. trap 'rm -f "$tmpfile" "$errorfile" "$tmpdir"/*; rmdir "$tmpdir"' EXIT
  34. # Reporting of syntax errors.
  35. cat > "$tmpfile"<<EOF
  36. ;; This is line 1, and the next one is line 2.
  37. (operating-system)
  38. ;; The 'T' is at column 3.
  39. EOF
  40. if guix system vm "$tmpfile" 2> "$errorfile"
  41. then
  42. # This must not succeed.
  43. exit 1
  44. else
  45. grep "$tmpfile:2:3:.*missing.* initializers" "$errorfile"
  46. fi
  47. cat > "$tmpfile"<<EOF
  48. ;; This is line 1, and the next one is line 2.
  49. (operating-system
  50. ;; This is line 3, and there is no closing paren!
  51. EOF
  52. if guix system vm "$tmpfile" 2> "$errorfile"
  53. then
  54. # This must not succeed.
  55. exit 1
  56. else
  57. grep "$tmpfile:4:1: missing closing paren" "$errorfile"
  58. fi
  59. # Reporting of module not found errors.
  60. cat > "$tmpfile" <<EOF
  61. ;; Line 1.
  62. (use-modules (gnu))
  63. (use-service-modules openssh)
  64. EOF
  65. if guix system build "$tmpfile" -n 2> "$errorfile"
  66. then false
  67. else
  68. grep "$tmpfile:3:2: .*module .*openssh.*not found" "$errorfile"
  69. grep "Try.*use-service-modules ssh" "$errorfile"
  70. fi
  71. cat > "$tmpfile" <<EOF
  72. ;; Line 1.
  73. (use-modules (gnu))
  74. (use-package-modules qemu)
  75. EOF
  76. if guix system build "$tmpfile" -n 2> "$errorfile"
  77. then false
  78. else
  79. grep "$tmpfile:3:2: .*module .*qemu.*not found" "$errorfile"
  80. grep "Try.*use-package-modules virtualization" "$errorfile"
  81. fi
  82. # Reporting of unbound variables.
  83. cat > "$tmpfile" <<EOF
  84. (use-modules (gnu)) ; 1
  85. (use-service-modules networking) ; 2
  86. (operating-system ; 4
  87. (host-name "antelope") ; 5
  88. (timezone "Europe/Paris") ; 6
  89. (locale "en_US.UTF-8") ; 7
  90. (bootloader (GRUB-config (target "/dev/sdX"))) ; 9
  91. (file-systems (cons (file-system
  92. (device (file-system-label "root"))
  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. (target "/dev/sdX")))
  116. (file-systems (cons (file-system
  117. (device (file-system-label "root"))
  118. (mount-point "/")
  119. (type "ext4"))
  120. %base-file-systems))
  121. '
  122. # Reporting of duplicate service identifiers.
  123. cat > "$tmpfile" <<EOF
  124. (use-modules (gnu))
  125. (use-service-modules networking)
  126. (operating-system
  127. $OS_BASE
  128. (services (cons* (service dhcp-client-service-type)
  129. (service dhcp-client-service-type) ;twice!
  130. %base-services)))
  131. EOF
  132. if guix system vm "$tmpfile" 2> "$errorfile"
  133. then
  134. # This must not succeed.
  135. exit 1
  136. else
  137. grep "service 'networking'.*more than once" "$errorfile"
  138. fi
  139. # Reporting unmet shepherd requirements.
  140. cat > "$tmpfile" <<EOF
  141. (use-modules (gnu) (gnu services shepherd))
  142. (use-service-modules networking)
  143. (define buggy-service-type
  144. (shepherd-service-type
  145. 'buggy
  146. (lambda _
  147. (shepherd-service
  148. (provision '(buggy!))
  149. (requirement '(does-not-exist))
  150. (start #t)))))
  151. (operating-system
  152. $OS_BASE
  153. (services (cons (service buggy-service-type #t)
  154. %base-services)))
  155. EOF
  156. if guix system build "$tmpfile" 2> "$errorfile"
  157. then
  158. exit 1
  159. else
  160. grep "service 'buggy!'.*'does-not-exist'.*not provided" "$errorfile"
  161. fi
  162. # Reporting inconsistent user accounts.
  163. make_user_config ()
  164. {
  165. cat > "$tmpfile" <<EOF
  166. (use-modules (gnu))
  167. (use-service-modules networking)
  168. (operating-system
  169. (host-name "antelope")
  170. (timezone "Europe/Paris")
  171. (locale "en_US.UTF-8")
  172. (bootloader (bootloader-configuration
  173. (bootloader grub-bootloader)
  174. (target "/dev/sdX")))
  175. (file-systems (cons (file-system
  176. (device (file-system-label "root"))
  177. (mount-point "/")
  178. (type "ext4"))
  179. %base-file-systems))
  180. (users (list (user-account
  181. (name "dave")
  182. (home-directory "/home/dave")
  183. (group "$1")
  184. (supplementary-groups '("$2"))))))
  185. EOF
  186. }
  187. make_user_config "users" "wheel"
  188. guix system build "$tmpfile" -n # succeeds
  189. guix system build "$tmpfile" -d # succeeds
  190. guix system build "$tmpfile" -d | grep '\.drv$'
  191. guix system vm "$tmpfile" -d # succeeds
  192. guix system vm "$tmpfile" -d | grep '\.drv$'
  193. # Make sure the behavior is deterministic (<https://bugs.gnu.org/32652>).
  194. drv1="`guix system vm "$tmpfile" -d`"
  195. drv2="`guix system vm "$tmpfile" -d`"
  196. test "$drv1" = "$drv2"
  197. drv1="`guix system disk-image --file-system-type=iso9660 "$tmpfile" -d`"
  198. drv2="`guix system disk-image --file-system-type=iso9660 "$tmpfile" -d`"
  199. test "$drv1" = "$drv2"
  200. make_user_config "group-that-does-not-exist" "users"
  201. if guix system build "$tmpfile" -n 2> "$errorfile"
  202. then false
  203. else grep "primary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
  204. make_user_config "users" "group-that-does-not-exist"
  205. if guix system build "$tmpfile" -n 2> "$errorfile"
  206. then false
  207. else grep "supplementary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
  208. # Try 'local-file' and relative file name resolution.
  209. cat > "$tmpdir/config.scm"<<EOF
  210. (use-modules (gnu))
  211. (use-service-modules networking)
  212. (operating-system
  213. $OS_BASE
  214. (services (cons (service tor-service-type
  215. (tor-configuration
  216. (config-file (local-file "my-torrc"))))
  217. %base-services)))
  218. EOF
  219. cat > "$tmpdir/my-torrc"<<EOF
  220. # This is an example file.
  221. EOF
  222. # In both cases 'my-torrc' should be properly resolved.
  223. guix system build "$tmpdir/config.scm" -n
  224. (cd "$tmpdir"; guix system build "config.scm" -n)
  225. # Searching.
  226. guix system search tor | grep "^name: tor"
  227. guix system search tor | grep "^shepherdnames: tor"
  228. guix system search anonym network | grep "^name: tor"
  229. # Below, use -n (--dry-run) for the tests because if we actually tried to
  230. # build these images, the commands would take hours to run in the worst case.
  231. # Verify that the examples can be built.
  232. for example in gnu/system/examples/*.tmpl; do
  233. guix system -n disk-image "$example"
  234. done
  235. # Verify that the disk image types can be built.
  236. guix system -n vm gnu/system/examples/vm-image.tmpl
  237. guix system -n vm-image gnu/system/examples/vm-image.tmpl
  238. # This invocation was taken care of in the loop above:
  239. # guix system -n disk-image gnu/system/examples/bare-bones.tmpl
  240. guix system -n disk-image --file-system-type=iso9660 gnu/system/examples/bare-bones.tmpl
  241. guix system -n docker-image gnu/system/examples/docker-image.tmpl