file-systems.scm 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015, 2017 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
  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-file-systems)
  20. #:use-module (guix store)
  21. #:use-module (guix modules)
  22. #:use-module (gnu system file-systems)
  23. #:use-module (srfi srfi-1)
  24. #:use-module (srfi srfi-64)
  25. #:use-module (ice-9 match))
  26. ;; Test the (gnu system file-systems) module.
  27. (test-begin "file-systems")
  28. (test-assert "file-system-needed-for-boot?"
  29. (let-syntax ((dummy-fs (syntax-rules ()
  30. ((_ directory)
  31. (file-system
  32. (device "foo")
  33. (mount-point directory)
  34. (type "ext4"))))))
  35. (parameterize ((%store-prefix "/gnu/guix/store"))
  36. (and (file-system-needed-for-boot? (dummy-fs "/"))
  37. (file-system-needed-for-boot? (dummy-fs "/gnu"))
  38. (file-system-needed-for-boot? (dummy-fs "/gnu/guix"))
  39. (file-system-needed-for-boot? (dummy-fs "/gnu/guix/store"))
  40. (not (file-system-needed-for-boot?
  41. (dummy-fs "/gnu/guix/store/foo")))
  42. (not (file-system-needed-for-boot? (dummy-fs "/gn")))
  43. (not (file-system-needed-for-boot?
  44. (file-system
  45. (inherit (dummy-fs (%store-prefix)))
  46. (device "/foo")
  47. (flags '(bind-mount read-only)))))))))
  48. (test-assert "does not pull (guix config)"
  49. ;; This module is meant both for the host side and "build side", so make
  50. ;; sure it doesn't pull in (guix config), which depends on the user's
  51. ;; config.
  52. (not (member '(guix config)
  53. (source-module-closure '((gnu system file-systems))))))
  54. (test-equal "does not pull (gnu packages …)"
  55. ;; Same story: (gnu packages …) should not be pulled.
  56. #f
  57. (find (match-lambda
  58. (('gnu 'packages _ ..1) #t)
  59. (_ #f))
  60. (source-module-closure '((gnu system file-systems)))))
  61. (test-equal "file-system-options->alist"
  62. '("autodefrag" ("subvol" . "home") ("compress" . "lzo"))
  63. (file-system-options->alist "autodefrag,subvol=home,compress=lzo"))
  64. (test-equal "file-system-options->alist (#f)"
  65. '()
  66. (file-system-options->alist #f))
  67. (test-equal "alist->file-system-options"
  68. "autodefrag,subvol=root,compress=lzo"
  69. (alist->file-system-options '("autodefrag"
  70. ("subvol" . "root")
  71. ("compress" . "lzo"))))
  72. (test-equal "alist->file-system-options (null)"
  73. #f
  74. (alist->file-system-options '()))
  75. ;;;
  76. ;;; Btrfs related.
  77. ;;;
  78. (define %btrfs-root-subvolume
  79. (file-system
  80. (device (file-system-label "btrfs-pool"))
  81. (mount-point "/")
  82. (type "btrfs")
  83. (options "subvol=rootfs,compress=zstd")))
  84. (define %btrfs-store-subvolid
  85. (file-system
  86. (device (file-system-label "btrfs-pool"))
  87. (mount-point "/gnu/store")
  88. (type "btrfs")
  89. (options "subvolid=10,compress=zstd")
  90. (dependencies (list %btrfs-root-subvolume))))
  91. (define %btrfs-store-subvolume
  92. (file-system
  93. (device (file-system-label "btrfs-pool"))
  94. (mount-point "/gnu/store")
  95. (type "btrfs")
  96. (options "subvol=/some/nested/file/name")
  97. (dependencies (list %btrfs-root-subvolume))))
  98. (test-assert "btrfs-subvolume? (subvol)"
  99. (btrfs-subvolume? %btrfs-root-subvolume))
  100. (test-assert "btrfs-subvolume? (subvolid)"
  101. (btrfs-subvolume? %btrfs-store-subvolid))
  102. (test-equal "btrfs-store-subvolume-file-name"
  103. "/some/nested/file/name"
  104. (parameterize ((%store-prefix "/gnu/store"))
  105. (btrfs-store-subvolume-file-name (list %btrfs-root-subvolume
  106. %btrfs-store-subvolume))))
  107. (test-error "btrfs-store-subvolume-file-name (subvolid)"
  108. (parameterize ((%store-prefix "/gnu/store"))
  109. (btrfs-store-subvolume-file-name (list %btrfs-root-subvolume
  110. %btrfs-store-subvolid))))
  111. (test-end)