system.scm 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016, 2018 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. (define-module (test-system)
  20. #:use-module (gnu)
  21. #:use-module ((gnu services) #:select (service-value))
  22. #:use-module (guix store)
  23. #:use-module (srfi srfi-1)
  24. #:use-module (srfi srfi-64))
  25. ;; Test the (gnu system) module.
  26. (define %root-fs
  27. (file-system
  28. (device (file-system-label "my-root"))
  29. (mount-point "/")
  30. (type "ext4")))
  31. (define %os
  32. (operating-system
  33. (host-name "komputilo")
  34. (timezone "Europe/Berlin")
  35. (locale "en_US.utf8")
  36. (bootloader (bootloader-configuration
  37. (bootloader grub-bootloader)
  38. (target "/dev/sdX")))
  39. (file-systems (cons %root-fs %base-file-systems))
  40. (users %base-user-accounts)))
  41. (define %luks-device
  42. (mapped-device
  43. (source "/dev/foo") (target "my-luks-device")
  44. (type luks-device-mapping)))
  45. (define %os-with-mapped-device
  46. (operating-system
  47. (host-name "komputilo")
  48. (timezone "Europe/Berlin")
  49. (locale "en_US.utf8")
  50. (bootloader (bootloader-configuration
  51. (bootloader grub-bootloader)
  52. (target "/dev/sdX")))
  53. (mapped-devices (list %luks-device))
  54. (file-systems (cons (file-system
  55. (inherit %root-fs)
  56. (dependencies (list %luks-device)))
  57. %base-file-systems))
  58. (users %base-user-accounts)))
  59. (test-begin "system")
  60. (test-assert "operating-system-store-file-system"
  61. ;; %BASE-FILE-SYSTEMS defines a bind-mount for /gnu/store, but this
  62. ;; shouldn't be a problem.
  63. (eq? %root-fs
  64. (operating-system-store-file-system %os)))
  65. (test-assert "operating-system-store-file-system, prefix"
  66. (let* ((gnu (file-system
  67. (device "foobar")
  68. (mount-point (dirname (%store-prefix)))
  69. (type "ext5")))
  70. (os (operating-system
  71. (inherit %os)
  72. (file-systems (cons* gnu %root-fs
  73. %base-file-systems)))))
  74. (eq? gnu (operating-system-store-file-system os))))
  75. (test-assert "operating-system-store-file-system, store"
  76. (let* ((gnu (file-system
  77. (device "foobar")
  78. (mount-point (%store-prefix))
  79. (type "ext5")))
  80. (os (operating-system
  81. (inherit %os)
  82. (file-systems (cons* gnu %root-fs
  83. %base-file-systems)))))
  84. (eq? gnu (operating-system-store-file-system os))))
  85. (test-equal "operating-system-user-mapped-devices"
  86. '()
  87. (operating-system-user-mapped-devices %os-with-mapped-device))
  88. (test-equal "operating-system-boot-mapped-devices"
  89. (list %luks-device)
  90. (operating-system-boot-mapped-devices %os-with-mapped-device))
  91. (test-equal "operating-system-boot-mapped-devices, implicit dependency"
  92. (list %luks-device)
  93. ;; Here we expect the implicit dependency between "/" and
  94. ;; "/dev/mapper/my-luks-device" to be found, in spite of the lack of a
  95. ;; 'dependencies' field in the root file system.
  96. (operating-system-boot-mapped-devices
  97. (operating-system
  98. (inherit %os-with-mapped-device)
  99. (file-systems (cons (file-system
  100. (device "/dev/mapper/my-luks-device")
  101. (mount-point "/")
  102. (type "ext4"))
  103. %base-file-systems)))))
  104. (test-equal "non-boot-file-system-service"
  105. '()
  106. ;; Make sure that mapped devices with at least one needed-for-boot user are
  107. ;; handled exclusively from the initrd. See <https://bugs.gnu.org/31889>.
  108. (append-map file-system-dependencies
  109. (service-value
  110. ((@@ (gnu system) non-boot-file-system-service)
  111. (operating-system
  112. (inherit %os-with-mapped-device)
  113. (file-systems
  114. (list (file-system
  115. (mount-point "/foo/bar")
  116. (device "qux:baz")
  117. (type "none")
  118. (dependencies (list %luks-device)))
  119. (file-system
  120. (device (file-system-label "my-root"))
  121. (mount-point "/")
  122. (type "ext4")
  123. (dependencies (list %luks-device))))))))))
  124. (test-end)