system.scm 5.8 KB

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