projects/guix·blob java-team · refs

196 lines · 8.2 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2013 Andreas Enge <[email protected]>
3;;; Copyright © 2016 Ludovic Courtès <[email protected]>
4;;; Copyright © 2019–2021 Tobias Geerinckx-Rice <[email protected]>
5;;; Copyright © 2024 Efraim Flashner <[email protected]>
6;;; Copyright © 2025 Antoine Côté <[email protected]>
7;;; Copyright © 2024, 2025 Janneke Nieuwenhuizen <[email protected]>
8;;;
9;;; This file is part of GNU Guix.
10;;;
11;;; GNU Guix is free software; you can redistribute it and/or modify it
12;;; under the terms of the GNU General Public License as published by
13;;; the Free Software Foundation; either version 3 of the License, or (at
14;;; your option) any later version.
15;;;
16;;; GNU Guix is distributed in the hope that it will be useful, but
17;;; WITHOUT ANY WARRANTY; without even the implied warranty of
18;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;;; GNU General Public License for more details.
20;;;
21;;; You should have received a copy of the GNU General Public License
22;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
23
24(define-module (gnu packages cryptsetup)
25 #:use-module ((guix licenses) #:prefix license:)
26 #:use-module (guix packages)
27 #:use-module (guix download)
28 #:use-module (guix build-system cmake)
29 #:use-module (guix build-system gnu)
30 #:use-module (guix gexp)
31 #:use-module (guix utils)
32 #:use-module (gnu packages)
33 #:use-module (gnu packages gnupg)
34 #:use-module (gnu packages password-utils)
35 #:use-module (gnu packages pkg-config)
36 #:use-module (gnu packages popt)
37 #:use-module (gnu packages linux)
38 #:use-module (gnu packages ruby-xyz)
39 #:use-module (gnu packages web))
40
41(define-public cryptsetup-minimal
42 (package
43 (name "cryptsetup-minimal")
44 (version "2.8.4")
45 (source (origin
46 (method url-fetch)
47 (uri (string-append "mirror://kernel.org/linux/utils/cryptsetup/v"
48 (version-major+minor version)
49 "/cryptsetup-" version ".tar.xz"))
50 (sha256
51 (base32
52 "10wa3vx0dx04kv2wy165gvnyi81swawgnnj51xwcr6jcjvw4cgj4"))))
53 (build-system gnu-build-system)
54 (arguments
55 `(#:configure-flags
56 (append
57 (if (assoc-ref %build-inputs "ruby-asciidoctor")
58 '()
59 (list "--disable-asciidoc"))
60 (list
61 ;; Argon2 is always enabled, this just selects the (faster) full version.
62 "--enable-libargon2"
63 ;; The default is OpenSSL which provides better PBKDF performance.
64 "--with-crypto_backend=gcrypt"
65 ;; GRUB 2.06 supports LUKS2, but does it reliably support all set-ups…?
66 "--with-default-luks-format=LUKS1"
67 ;; External tokens would need an env variable to work on Guix, and we
68 ;; don't have users for it yet.
69 "--disable-external-tokens"
70 "--disable-ssh-token"
71 ;; libgcrypt is not found otherwise when cross-compiling.
72 ;; <https://issues.guix.gnu.org/63864>
73 (string-append "--with-libgcrypt-prefix="
74 (assoc-ref %build-inputs "libgcrypt"))))))
75 (native-inputs
76 (list pkg-config))
77 (inputs
78 (list argon2
79 json-c
80 libgcrypt
81 lvm2 ; device-mapper
82 popt
83 `(,util-linux "lib"))) ;libuuid
84 (synopsis "Set up transparent encryption of block devices using dm-crypt")
85 (description
86 "Cryptsetup is a utility used to conveniently set up disk encryption based
87on the @code{dm-crypt} Linux kernel module. It is most often used to manage
88LUKS volumes but also supports plain dm-crypt volumes and loop-AES, TrueCrypt
89(including VeraCrypt extension), and BitLocker formats.
90
91@acronym{LUKS, Linux Unified Key Setup} is the standard for hard disk encryption
92with the kernel Linux. It provides a standard on-disk-format compatible amongst
93distributions as well as secure management of multiple user passwords. LUKS
94stores all necessary setup information in the partition header to facilitate
95data transport and migration.
96
97The package also includes the @command{veritysetup} and @command{integritysetup}
98utilities to conveniently configure the @code{dm-verity} and @code{dm-integrity}
99block integrity kernel modules.")
100 (license license:gpl2)
101 (home-page "https://gitlab.com/cryptsetup/cryptsetup")))
102
103(define-public cryptsetup
104 (package/inherit cryptsetup-minimal
105 (name "cryptsetup")
106 (native-inputs `(,(if (supported-package? ruby-asciidoctor/minimal)
107 `("ruby-asciidoctor" ,ruby-asciidoctor/minimal)
108 '())
109 ,@(package-native-inputs cryptsetup-minimal)))))
110
111(define-public (libcryptsetup-propagated-inputs)
112 (list argon2
113 json-c
114 libgcrypt
115 lvm2
116 `(,util-linux "lib")))
117
118(define (static-library library)
119 "Return a variant of package LIBRARY that provides static libraries ('.a'
120files). This assumes LIBRARY uses Libtool."
121 (package
122 (inherit library)
123 (name (string-append (package-name library) "-static"))
124 (arguments
125 (substitute-keyword-arguments arguments
126 ((#:configure-flags flags #~'())
127 (let* ((build-system (package-build-system library))
128 (static-flags (cond ((eq? build-system cmake-build-system)
129 '("-DBUILD_SHARED_LIBS=OFF"))
130 (else
131 '("--disable-shared" "--enable-static")))))
132 #~(append '#$static-flags
133 #$flags)))))))
134
135(define-public cryptsetup-static
136 ;; Stripped-down statically-linked 'cryptsetup' command for use in initrds.
137 (package
138 (inherit cryptsetup-minimal)
139 (name "cryptsetup-static")
140 (arguments
141 (substitute-keyword-arguments arguments
142 ((#:configure-flags flags ''())
143 `(cons* "--disable-shared"
144 "--enable-static-cryptsetup"
145
146 "--disable-veritysetup"
147 "--disable-integritysetup"
148 ;; Bypass broken pkg-config paths for the static output of
149 ;; util-linux. Only blkid is located through pkg-config, not
150 ;; uuid.
151 (format #f "BLKID_CFLAGS=-I~a"
152 (search-input-directory %build-inputs "include/blkid"))
153 (format #f "BLKID_LIBS=-L~a -lblkid"
154 (dirname (search-input-file %build-inputs "lib/libblkid.a")))
155 ,flags))
156 ((#:allowed-references refs '())
157 '())
158 ((#:modules modules '())
159 '((ice-9 ftw)
160 (ice-9 match)
161 (guix build utils)
162 (guix build gnu-build-system)))
163 ((#:phases phases #~%standard-phases)
164 #~(modify-phases #$phases
165 (add-after 'install 'remove-cruft
166 (lambda* (#:key outputs #:allow-other-keys)
167 ;; Remove everything except the 'cryptsetup' command.
168 (let ((out (assoc-ref outputs "out")))
169 (with-directory-excursion out
170 (let ((dirs (scandir "."
171 (match-lambda
172 ((or "." "..") #f)
173 (_ #t)))))
174 (for-each delete-file-recursively
175 (delete "sbin" dirs))
176 (for-each (lambda (file)
177 (rename-file (string-append file
178 ".static")
179 file)
180 (remove-store-references file))
181 '("sbin/cryptsetup"))
182 #t)))))))))
183 (inputs
184 (let ((libgcrypt-static
185 (package
186 (inherit (static-library libgcrypt))
187 (propagated-inputs
188 `(("libgpg-error-host" ,(static-library libgpg-error)))))))
189 `(("argon2" ,(static-library argon2))
190 ("json-c" ,(static-library json-c))
191 ("libgcrypt" ,libgcrypt-static)
192 ("lvm2" ,lvm2-static)
193 ("util-linux" ,util-linux "static")
194 ("util-linux" ,util-linux "lib")
195 ("popt" ,(static-library popt)))))
196 (synopsis "Hard disk encryption tool (statically linked)")))