cryptsetup.scm 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013 Andreas Enge <andreas@enge.fr>
  3. ;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
  4. ;;; Copyright © 2019–2021 Tobias Geerinckx-Rice <me@tobias.gr>
  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. (define-module (gnu packages cryptsetup)
  21. #:use-module ((guix licenses) #:prefix license:)
  22. #:use-module (guix packages)
  23. #:use-module (guix download)
  24. #:use-module (guix build-system gnu)
  25. #:use-module (guix utils)
  26. #:use-module (gnu packages)
  27. #:use-module (gnu packages gnupg)
  28. #:use-module (gnu packages password-utils)
  29. #:use-module (gnu packages pkg-config)
  30. #:use-module (gnu packages popt)
  31. #:use-module (gnu packages linux)
  32. #:use-module (gnu packages web))
  33. (define-public cryptsetup
  34. (package
  35. (name "cryptsetup")
  36. (version "2.3.6")
  37. (source (origin
  38. (method url-fetch)
  39. (uri (string-append "mirror://kernel.org/linux/utils/cryptsetup/v"
  40. (version-major+minor version)
  41. "/cryptsetup-" version ".tar.xz"))
  42. (sha256
  43. (base32
  44. "0pv34l6230ba1i5p0z6zmvfqvv3as0cwn731h2qw4xm53sibg5mj"))))
  45. (build-system gnu-build-system)
  46. (arguments
  47. `(#:configure-flags
  48. (list
  49. ;; Argon2 is always enabled, this just selects the (faster) full version.
  50. "--enable-libargon2"
  51. ;; The default is OpenSSL which provides better PBKDF performance.
  52. "--with-crypto_backend=gcrypt"
  53. ;; GRUB 2.06 supports LUKS2, but does it reliably support all set-ups…?
  54. "--with-default-luks-format=LUKS1")))
  55. (native-inputs
  56. `(("pkg-config" ,pkg-config)))
  57. (inputs
  58. `(("argon2" ,argon2)
  59. ("json-c" ,json-c)
  60. ("libgcrypt" ,libgcrypt)
  61. ("lvm2" ,lvm2) ; device-mapper
  62. ("popt" ,popt)
  63. ("util-linux" ,util-linux "lib"))) ;libuuid
  64. (synopsis "Set up transparent encryption of block devices using dm-crypt")
  65. (description
  66. "Cryptsetup is a utility used to conveniently set up disk encryption based
  67. on the @code{dm-crypt} Linux kernel module. It is most often used to manage
  68. LUKS volumes but also supports plain dm-crypt volumes and loop-AES, TrueCrypt
  69. (including VeraCrypt extension), and BitLocker formats.
  70. @acronym{LUKS, Linux Unified Key Setup} is the standard for hard disk encryption
  71. with the kernel Linux. It provides a standard on-disk-format compatible amongst
  72. distributions as well as secure management of multiple user passwords. LUKS
  73. stores all necessary setup information in the partition header to facilitate
  74. data transport and migration.
  75. The package also includes the @command{veritysetup} and @command{integritysetup}
  76. utilities to conveniently configure the @code{dm-verity} and @code{dm-integrity}
  77. block integrity kernel modules.")
  78. (license license:gpl2)
  79. (home-page "https://gitlab.com/cryptsetup/cryptsetup")))
  80. (define (static-library library)
  81. "Return a variant of package LIBRARY that provides static libraries ('.a'
  82. files). This assumes LIBRARY uses Libtool."
  83. (package
  84. (inherit library)
  85. (name (string-append (package-name library) "-static"))
  86. (arguments
  87. (substitute-keyword-arguments (package-arguments library)
  88. ((#:configure-flags flags ''())
  89. `(append '("--disable-shared" "--enable-static")
  90. ,flags))))))
  91. (define-public cryptsetup-static
  92. ;; Stripped-down statically-linked 'cryptsetup' command for use in initrds.
  93. (package
  94. (inherit cryptsetup)
  95. (name "cryptsetup-static")
  96. (arguments
  97. '(#:configure-flags '("--disable-shared"
  98. "--enable-static-cryptsetup"
  99. "--disable-veritysetup"
  100. "--disable-cryptsetup-reencrypt"
  101. "--disable-integritysetup"
  102. ;; The default is OpenSSL which provides better PBKDF performance.
  103. "--with-crypto_backend=gcrypt"
  104. "--disable-blkid"
  105. ;; 'libdevmapper.a' pulls in libpthread, libudev and libm.
  106. "LIBS=-ludev -pthread -lm")
  107. #:allowed-references () ;this should be self-contained
  108. #:modules ((ice-9 ftw)
  109. (ice-9 match)
  110. (guix build utils)
  111. (guix build gnu-build-system))
  112. #:phases (modify-phases %standard-phases
  113. (add-after 'install 'remove-cruft
  114. (lambda* (#:key outputs #:allow-other-keys)
  115. ;; Remove everything except the 'cryptsetup' command.
  116. (let ((out (assoc-ref outputs "out")))
  117. (with-directory-excursion out
  118. (let ((dirs (scandir "."
  119. (match-lambda
  120. ((or "." "..") #f)
  121. (_ #t)))))
  122. (for-each delete-file-recursively
  123. (delete "sbin" dirs))
  124. (for-each (lambda (file)
  125. (rename-file (string-append file
  126. ".static")
  127. file)
  128. (remove-store-references file))
  129. '("sbin/cryptsetup"))
  130. #t))))))))
  131. (inputs
  132. (let ((libgcrypt-static
  133. (package
  134. (inherit (static-library libgcrypt))
  135. (propagated-inputs
  136. `(("libgpg-error-host" ,(static-library libgpg-error)))))))
  137. `(("json-c" ,json-c-0.13)
  138. ("libgcrypt" ,libgcrypt-static)
  139. ("lvm2" ,lvm2-static)
  140. ("util-linux" ,util-linux "static")
  141. ("util-linux" ,util-linux "lib")
  142. ("popt" ,popt))))
  143. (synopsis "Hard disk encryption tool (statically linked)")))