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>
5 ;;; This file is part of GNU Guix.
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.
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.
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/>.
20 (define-module (test-system)
22 #:use-module ((gnu services) #:select (service-value))
23 #:use-module (guix store)
24 #:use-module (guix monads)
25 #:use-module ((guix gexp) #:select (lower-object))
26 #:use-module ((guix utils) #:select (%current-system))
27 #:use-module (guix grafts)
28 #:use-module (srfi srfi-1)
29 #:use-module (srfi srfi-64))
31 ;; Test the (gnu system) module.
35 (device (file-system-label "my-root"))
41 (host-name "komputilo")
42 (timezone "Europe/Berlin")
44 (bootloader (bootloader-configuration
45 (bootloader grub-bootloader)
46 (targets '("/dev/sdX"))))
47 (file-systems (cons %root-fs %base-file-systems))
49 (users %base-user-accounts)))
53 (source "/dev/foo") (target "my-luks-device")
54 (type luks-device-mapping)))
56 (define %os-with-mapped-device
58 (host-name "komputilo")
59 (timezone "Europe/Berlin")
61 (bootloader (bootloader-configuration
62 (bootloader grub-bootloader)
63 (targets '("/dev/sdX"))))
64 (mapped-devices (list %luks-device))
65 (file-systems (cons (file-system
67 (dependencies (list %luks-device)))
69 (users %base-user-accounts)))
76 (test-assert "operating-system-store-file-system"
77 ;; %BASE-FILE-SYSTEMS defines a bind-mount for /gnu/store, but this
78 ;; shouldn't be a problem.
80 (operating-system-store-file-system %os)))
82 (test-assert "operating-system-store-file-system, prefix"
83 (let* ((gnu (file-system
85 (mount-point (dirname (%store-prefix)))
89 (file-systems (cons* gnu %root-fs
90 %base-file-systems)))))
91 (eq? gnu (operating-system-store-file-system os))))
93 (test-assert "operating-system-store-file-system, store"
94 (let* ((gnu (file-system
96 (mount-point (%store-prefix))
100 (file-systems (cons* gnu %root-fs
101 %base-file-systems)))))
102 (eq? gnu (operating-system-store-file-system os))))
104 (test-equal "operating-system-user-mapped-devices"
106 (operating-system-user-mapped-devices %os-with-mapped-device))
108 (test-equal "operating-system-boot-mapped-devices"
110 (operating-system-boot-mapped-devices %os-with-mapped-device))
112 (test-equal "operating-system-boot-mapped-devices, implicit dependency"
115 ;; Here we expect the implicit dependency between "/" and
116 ;; "/dev/mapper/my-luks-device" to be found, in spite of the lack of a
117 ;; 'dependencies' field in the root file system.
118 (operating-system-boot-mapped-devices
120 (inherit %os-with-mapped-device)
121 (file-systems (cons (file-system
122 (device "/dev/mapper/my-luks-device")
125 %base-file-systems)))))
127 (test-equal "non-boot-file-system-service"
130 ;; Make sure that mapped devices with at least one needed-for-boot user are
131 ;; handled exclusively from the initrd. See <https://bugs.gnu.org/31889>.
132 (append-map file-system-dependencies
134 ((@@ (gnu system) non-boot-file-system-service)
136 (inherit %os-with-mapped-device)
139 (mount-point "/foo/bar")
142 (dependencies (list %luks-device)))
144 (device (file-system-label "my-root"))
147 (dependencies (list %luks-device))))))))))
149 (test-assert "lower-object, %current-system sensitivity"
150 ;; Make sure that 'lower-object' returns the same derivation, no matter what
151 ;; '%current-system' is. See <https://issues.guix.gnu.org/55951>.
152 (let ((drv1 (with-store store
153 (parameterize ((%current-system "x86_64-linux"))
154 (run-with-store store
155 (lower-object %os "aarch64-linux")))))
156 (drv2 (with-store store
157 (parameterize ((%current-system "aarch64-linux"))
158 (run-with-store store
159 (lower-object %os "aarch64-linux"))))))