guix-system.sh 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. # GNU Guix --- Functional package management for GNU
  2. # Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 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))'`" = 3.0
  101. then
  102. # FIXME: With Guile 3.3.0 the error is reported on line 11.
  103. # See <https://bugs.gnu.org/38388>.
  104. grep "$tmpfile:[0-9]\+:[0-9]\+:.*GRUB-config.*[Uu]nbound variable" "$errorfile"
  105. elif test "`guile -c '(display (effective-version))'`" = 2.2
  106. then
  107. # FIXME: With Guile 2.2.0 the error is reported on line 4.
  108. # See <http://bugs.gnu.org/26107>.
  109. grep "$tmpfile:[49]:[0-9]\+:.*GRUB-config.*[Uu]nbound variable" "$errorfile"
  110. else
  111. grep "$tmpfile:9:[0-9]\+:.*GRUB-config.*[Uu]nbound variable" "$errorfile"
  112. fi
  113. fi
  114. cat > "$tmpfile" <<EOF
  115. (use-modules (gnu)) ; 1
  116. (operating-system ; 3
  117. (file-systems (cons (file-system ; 4
  118. (device (file-system-label "root"))
  119. (mount-point "/") ; 6
  120. (type "ext4")))) ; 7 (!!)
  121. %base-file-systems)
  122. EOF
  123. if guix system build "$tmpfile" -n 2> "$errorfile"
  124. then false
  125. else
  126. # Here '%base-file-systems' appears as if it were a field specified of the
  127. # enclosing 'operating-system' form due to parenthesis mismatch.
  128. grep "$tmpfile:3:[0-9]\+:.*%base-file-system.*invalid field specifier" \
  129. "$errorfile"
  130. fi
  131. OS_BASE='
  132. (host-name "antelope")
  133. (timezone "Europe/Paris")
  134. (locale "en_US.UTF-8")
  135. (bootloader (bootloader-configuration
  136. (bootloader grub-bootloader)
  137. (target "/dev/sdX")))
  138. (file-systems (cons (file-system
  139. (device (file-system-label "root"))
  140. (mount-point "/")
  141. (type "ext4"))
  142. %base-file-systems))
  143. '
  144. # Reporting of duplicate service identifiers.
  145. cat > "$tmpfile" <<EOF
  146. (use-modules (gnu))
  147. (use-service-modules networking)
  148. (operating-system
  149. $OS_BASE
  150. (services (cons* (service dhcp-client-service-type)
  151. (service dhcp-client-service-type) ;twice!
  152. %base-services)))
  153. EOF
  154. if guix system vm "$tmpfile" 2> "$errorfile"
  155. then
  156. # This must not succeed.
  157. exit 1
  158. else
  159. grep "service 'networking'.*more than once" "$errorfile"
  160. fi
  161. # Reporting unmet shepherd requirements.
  162. cat > "$tmpfile" <<EOF
  163. (use-modules (gnu) (gnu services shepherd))
  164. (use-service-modules networking)
  165. (define buggy-service-type
  166. (shepherd-service-type
  167. 'buggy
  168. (lambda _
  169. (shepherd-service
  170. (provision '(buggy!))
  171. (requirement '(does-not-exist))
  172. (start #t)))))
  173. (operating-system
  174. $OS_BASE
  175. (services (cons (service buggy-service-type #t)
  176. %base-services)))
  177. EOF
  178. if guix system build "$tmpfile" 2> "$errorfile"
  179. then
  180. exit 1
  181. else
  182. grep "service 'buggy!'.*'does-not-exist'.*not provided" "$errorfile"
  183. fi
  184. # Reporting inconsistent user accounts.
  185. make_user_config ()
  186. {
  187. cat > "$tmpfile" <<EOF
  188. (use-modules (gnu))
  189. (use-service-modules networking)
  190. (operating-system
  191. (host-name "antelope")
  192. (timezone "Europe/Paris")
  193. (locale "en_US.UTF-8")
  194. (bootloader (bootloader-configuration
  195. (bootloader grub-bootloader)
  196. (target "/dev/sdX")))
  197. (file-systems (cons (file-system
  198. (device (file-system-label "root"))
  199. (mount-point "/")
  200. (type "ext4"))
  201. %base-file-systems))
  202. (users (list (user-account
  203. (name "dave")
  204. (home-directory "/home/dave")
  205. (group "$1")
  206. (supplementary-groups '("$2"))))))
  207. EOF
  208. }
  209. make_user_config "users" "wheel"
  210. guix system build "$tmpfile" -n # succeeds
  211. guix system build "$tmpfile" -d # succeeds
  212. guix system build "$tmpfile" -d | grep '\.drv$'
  213. guix system vm "$tmpfile" -d # succeeds
  214. guix system vm "$tmpfile" -d | grep '\.drv$'
  215. # Make sure the behavior is deterministic (<https://bugs.gnu.org/32652>).
  216. drv1="`guix system vm "$tmpfile" -d`"
  217. drv2="`guix system vm "$tmpfile" -d`"
  218. test "$drv1" = "$drv2"
  219. drv1="`guix system disk-image -t iso9660 "$tmpfile" -d`"
  220. drv2="`guix system disk-image -t iso9660 "$tmpfile" -d`"
  221. test "$drv1" = "$drv2"
  222. make_user_config "group-that-does-not-exist" "users"
  223. if guix system build "$tmpfile" -n 2> "$errorfile"
  224. then false
  225. else grep "primary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
  226. make_user_config "users" "group-that-does-not-exist"
  227. if guix system build "$tmpfile" -n 2> "$errorfile"
  228. then false
  229. else grep "supplementary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
  230. # Try 'local-file' and relative file name resolution.
  231. cat > "$tmpdir/config.scm"<<EOF
  232. (use-modules (gnu))
  233. (use-service-modules networking)
  234. (operating-system
  235. $OS_BASE
  236. (services (cons (service tor-service-type
  237. (tor-configuration
  238. (config-file (local-file "my-torrc"))))
  239. %base-services)))
  240. EOF
  241. cat > "$tmpdir/my-torrc"<<EOF
  242. # This is an example file.
  243. EOF
  244. # In both cases 'my-torrc' should be properly resolved.
  245. guix system build "$tmpdir/config.scm" -n
  246. (cd "$tmpdir"; guix system build "config.scm" -n)
  247. # Check that we get a warning when passing 'local-file' a non-literal relative
  248. # file name.
  249. cat > "$tmpdir/config.scm" <<EOF
  250. (use-modules (guix))
  251. (define (bad-local-file file)
  252. (local-file file))
  253. (bad-local-file "whatever.scm")
  254. EOF
  255. ! guix system build "$tmpdir/config.scm" -n
  256. guix system build "$tmpdir/config.scm" -n 2>&1 | \
  257. grep "config\.scm:4:2: warning:.*whatever.*relative to current directory"
  258. # Searching.
  259. guix system search tor | grep "^name: tor"
  260. guix system search tor | grep "^shepherdnames: tor"
  261. guix system search anonym network | grep "^name: tor"
  262. # Below, use -n (--dry-run) for the tests because if we actually tried to
  263. # build these images, the commands would take hours to run in the worst case.
  264. # Verify that the examples can be built.
  265. for example in gnu/system/examples/*.tmpl; do
  266. if echo "$example" | grep hurd; then
  267. target="--target=i586-pc-gnu"
  268. else
  269. target=
  270. fi
  271. guix system -n disk-image $target "$example"
  272. done
  273. # Verify that the disk image types can be built.
  274. guix system -n vm gnu/system/examples/vm-image.tmpl
  275. guix system -n vm-image gnu/system/examples/vm-image.tmpl
  276. # This invocation was taken care of in the loop above:
  277. # guix system -n disk-image gnu/system/examples/bare-bones.tmpl
  278. guix system -n disk-image -t iso9660 gnu/system/examples/bare-bones.tmpl
  279. guix system -n docker-image gnu/system/examples/docker-image.tmpl
  280. # Verify that at least the raw image type is available.
  281. guix system --list-image-types | grep "raw"