gnu: hurd: Add dependency on libgcrypt.
[jackhill/guix/guix.git] / gnu / packages / hurd.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015, 2016, 2017 Manolis Fragkiskos Ragkousis <manolis837@gmail.com>
3 ;;; Copyright © 2018, 2020 Ludovic Courtès <ludo@gnu.org>
4 ;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
5 ;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
6 ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
7 ;;;
8 ;;; This file is part of GNU Guix.
9 ;;;
10 ;;; GNU Guix is free software; you can redistribute it and/or modify it
11 ;;; under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or (at
13 ;;; your option) any later version.
14 ;;;
15 ;;; GNU Guix is distributed in the hope that it will be useful, but
16 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
19 ;;;
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22
23 (define-module (gnu packages hurd)
24 #:use-module (guix licenses)
25 #:use-module (guix download)
26 #:use-module (guix packages)
27 #:use-module (gnu packages)
28 #:use-module (guix gexp)
29 #:use-module (guix utils)
30 #:use-module (guix build-system gnu)
31 #:use-module (guix build-system trivial)
32 #:use-module (gnu packages autotools)
33 #:use-module (gnu packages flex)
34 #:use-module (gnu packages gnupg)
35 #:use-module (gnu packages bison)
36 #:use-module (gnu packages linux)
37 #:use-module (gnu packages perl)
38 #:use-module (gnu packages base)
39 #:use-module (gnu packages bash)
40 #:use-module (gnu packages texinfo)
41 #:use-module (guix git-download)
42 #:export (hurd-system?
43 hurd-target?
44 hurd-triplet?))
45
46 (define (hurd-triplet? triplet)
47 (and (string-suffix? "-gnu" triplet)
48 (not (string-contains triplet "linux"))))
49
50 (define (hurd-target?)
51 "Return true if the cross-compilation target or the current system is
52 GNU/Hurd."
53 (or (and=> (%current-target-system) hurd-triplet?)
54 (and (not (%current-target-system))
55 (and=> (%current-system) hurd-triplet?))))
56
57 (define (hurd-system?)
58 "Return true if the current system is the Hurd."
59 (and=> (%current-system) hurd-triplet?))
60
61 (define (hurd-source-url version)
62 (string-append "mirror://gnu/hurd/hurd-"
63 version ".tar.gz"))
64
65 (define-public gnumach-headers
66 (let ((commit "097f9cf735ffa1212b828682ad92f0f6c5f1c552")
67 (revision "1"))
68 (package
69 (name "gnumach-headers")
70 (version (git-version "1.8" revision commit))
71 (source
72 (origin
73 (method git-fetch)
74 (uri (git-reference
75 (url "https://git.savannah.gnu.org/git/hurd/gnumach.git")
76 (commit commit)))
77 (file-name (git-file-name "gnumach" version))
78 (sha256
79 (base32
80 "0q36z7k02bykrld90zaxbhyzxlmwlqqs4divgir6ix38zsp6icqk"))))
81 (build-system gnu-build-system)
82 (arguments
83 `(#:phases
84 (modify-phases %standard-phases
85 (replace 'install
86 (lambda _
87 (invoke "make" "install-data")))
88 (delete 'build))
89
90 ;; GNU Mach supports only IA32 currently, so cheat so that we can at
91 ;; least install its headers.
92 ,@(if (%current-target-system)
93 '()
94 ;; See <http://lists.gnu.org/archive/html/bug-hurd/2015-06/msg00042.html>
95 ;; <http://lists.gnu.org/archive/html/guix-devel/2015-06/msg00716.html>
96 '(#:configure-flags '("--build=i586-pc-gnu"
97 "--host=i686-linux-gnu")))
98
99 #:tests? #f))
100 (native-inputs
101 `(("autoconf" ,autoconf)
102 ("automake" ,automake)
103 ("texinfo" ,texinfo-4)))
104 (home-page "https://www.gnu.org/software/hurd/microkernel/mach/gnumach.html")
105 (synopsis "GNU Mach kernel headers")
106 (description
107 "Headers of the GNU Mach kernel.")
108 (license gpl2+))))
109
110 (define-public mig
111 (package
112 (name "mig")
113 (version "1.8")
114 (source
115 (origin
116 (method url-fetch)
117 (uri (string-append "mirror://gnu/mig/mig-"
118 version ".tar.gz"))
119 (sha256
120 (base32
121 "1gyda8sq6b379nx01hkpbd85lz39irdvz2b9wbr63gicicx8i706"))))
122 (build-system gnu-build-system)
123 ;; Flex is needed both at build and run time.
124 (inputs `(("gnumach-headers" ,gnumach-headers)
125 ("flex" ,flex)))
126 (native-inputs
127 `(("flex" ,flex)
128 ("bison" ,bison)))
129 (arguments `(#:tests? #f))
130 (home-page "https://www.gnu.org/software/hurd/microkernel/mach/mig/gnu_mig.html")
131 (synopsis "Mach 3.0 interface generator for the Hurd")
132 (description
133 "GNU MIG is the GNU distribution of the Mach 3.0 interface generator
134 MIG, as maintained by the GNU Hurd developers for the GNU project.
135 You need this tool to compile the GNU Mach and GNU Hurd distributions,
136 and to compile the GNU C library for the Hurd. Also, you will need it
137 for other software in the GNU system that uses Mach-based inter-process
138 communication.")
139 (license gpl2+)))
140
141 (define-public hurd-headers
142 ;; Resort to a post-0.9 snapshot that provides the 'file_utimens' and
143 ;; 'file_exec_paths' RPCs that glibc 2.28 expects.
144 (let ((revision "1")
145 (commit "91a51672ff4cfe1f1a0712b4c542ded3081c825b"))
146 (package
147 (name "hurd-headers")
148 (version (git-version "0.9" revision commit))
149 (source (origin
150 (method git-fetch)
151 (uri (git-reference
152 (url "https://git.savannah.gnu.org/git/hurd/hurd.git")
153 (commit commit)))
154 (sha256
155 (base32
156 "16k9wkahz9wasviijz53n6i13nmiwa9fs64ikf1jqh8rl60hw7cz"))
157 (file-name (git-file-name name version))))
158 (build-system gnu-build-system)
159 (native-inputs
160 `(("mig" ,mig)
161 ("autoconf" ,autoconf)
162 ("automake" ,automake)))
163 (arguments
164 `(#:phases
165 (modify-phases %standard-phases
166 (replace 'install
167 (lambda _
168 (invoke "make" "install-headers" "no_deps=t")))
169 (delete 'build))
170
171 #:configure-flags '( ;; Pretend we're on GNU/Hurd; 'configure' wants
172 ;; that.
173 ,@(if (%current-target-system)
174 '()
175 '("--host=i586-pc-gnu"))
176
177 ;; Reduce set of dependencies.
178 "--without-parted"
179 "--disable-ncursesw"
180 "--disable-test"
181 "--without-libbz2"
182 "--without-libcrypt"
183 "--without-libz"
184 ;; Skip the clnt_create check because it expects
185 ;; a working glibc causing a circular dependency.
186 "ac_cv_search_clnt_create=no"
187
188 ;; Annihilate the checks for the 'file_exec_paths'
189 ;; & co. libc functions to avoid "link tests are
190 ;; not allowed after AC_NO_EXECUTABLES" error.
191 "ac_cv_func_file_exec_paths=no"
192 "ac_cv_func_exec_exec_paths=no"
193 "ac_cv_func__hurd_exec_paths=no"
194 "ac_cv_func_file_futimens=no")
195
196 #:tests? #f))
197 (home-page "https://www.gnu.org/software/hurd/hurd.html")
198 (synopsis "GNU Hurd headers")
199 (description
200 "This package provides C headers of the GNU Hurd, used to build the GNU C
201 Library and other user programs.")
202 (license gpl2+))))
203
204 (define-public hurd-minimal
205 (package (inherit hurd-headers)
206 (name "hurd-minimal")
207 (inputs `(("glibc-hurd-headers" ,glibc/hurd-headers)))
208 (arguments
209 (substitute-keyword-arguments (package-arguments hurd-headers)
210 ((#:phases _)
211 '(modify-phases %standard-phases
212 (replace 'install
213 (lambda* (#:key outputs #:allow-other-keys)
214 (let ((out (assoc-ref outputs "out")))
215 ;; We need to copy libihash.a to the output directory manually,
216 ;; since there is no target for that in the makefile.
217 (mkdir-p (string-append out "/include"))
218 (copy-file "libihash/ihash.h"
219 (string-append out "/include/ihash.h"))
220 (mkdir-p (string-append out "/lib"))
221 (copy-file "libihash/libihash.a"
222 (string-append out "/lib/libihash.a"))
223 #t)))
224 (replace 'build
225 (lambda _
226 ;; Install <assert-backtrace.h> & co.
227 (invoke "make" "-Clibshouldbeinlibc"
228 "../include/assert-backtrace.h")
229
230 ;; Build libihash.
231 (invoke "make" "-Clibihash" "libihash.a")))))))
232 (home-page "https://www.gnu.org/software/hurd/hurd.html")
233 (synopsis "GNU Hurd libraries")
234 (description
235 "This package provides libihash, needed to build the GNU C
236 Library for GNU/Hurd.")
237 (license gpl2+)))
238
239 (define-public hurd-core-headers
240 (package
241 (name "hurd-core-headers")
242 (version (package-version hurd-headers))
243 (source #f)
244 (build-system trivial-build-system)
245 (arguments
246 '(#:modules ((guix build union))
247 #:builder (begin
248 (use-modules (ice-9 match)
249 (guix build union))
250 (match %build-inputs
251 (((names . directories) ...)
252 (union-build (assoc-ref %outputs "out")
253 directories)
254 #t)))))
255 (inputs `(("gnumach-headers" ,gnumach-headers)
256 ("hurd-headers" ,hurd-headers)
257 ("hurd-minimal" ,hurd-minimal)))
258 (synopsis "Union of the Hurd headers and libraries")
259 (description
260 "This package contains the union of the Mach and Hurd headers and the
261 Hurd-minimal package which are needed for both glibc and GCC.")
262 (home-page (package-home-page hurd-headers))
263 (license (package-license hurd-headers))))
264
265 (define-public gnumach
266 (package
267 (inherit gnumach-headers)
268 (name "gnumach")
269 (arguments
270 (substitute-keyword-arguments (package-arguments gnumach-headers)
271 ((#:configure-flags flags ''())
272 `(cons "--enable-kdb" ,flags)) ;enable kernel debugger
273 ((#:phases phases '%standard-phases)
274 `(modify-phases %standard-phases
275 (add-after 'install 'produce-image
276 (lambda* (#:key outputs #:allow-other-keys)
277 (let* ((out (assoc-ref outputs "out"))
278 (boot (string-append out "/boot")))
279 (invoke "make" "gnumach.gz")
280 (install-file "gnumach.gz" boot)
281 #t)))))))
282 (native-inputs
283 `(("mig" ,mig)
284 ("perl" ,perl)
285 ("autoconf" ,autoconf)
286 ("automake" ,automake)
287 ("texinfo" ,texinfo-4)))
288 (supported-systems (cons "i686-linux" %hurd-systems))
289 (synopsis "Microkernel of the GNU system")
290 (description
291 "GNU Mach is the microkernel upon which a GNU Hurd system is based.")))
292
293 (define (hurd-rc-script)
294 "Return a script to be installed as /libexec/rc in the 'hurd' package. The
295 script takes care of installing the relevant passive translators on the first
296 boot, since this cannot be done from GNU/Linux."
297 (define translators
298 '(("/servers/crash-dump-core" ("/hurd/crash" "--dump-core"))
299 ("/servers/crash-kill" ("/hurd/crash" "--kill"))
300 ("/servers/crash-suspend" ("/hurd/crash" "--suspend"))
301 ("/servers/password" ("/hurd/password"))
302 ("/servers/socket/1" ("/hurd/pflocal"))
303 ("/servers/socket/2" ("/hurd/pfinet" "--interface" "eth0"
304 "--address" "10.0.2.77"
305 "--netmask" "255.255.255.0"
306 "--gateway" "10.0.2.2"
307 "--ipv6" "/servers/socket/16"))))
308
309 (define rc
310 (with-imported-modules '((guix build utils))
311 #~(begin
312 (use-modules (guix build utils)
313 (ice-9 match))
314
315 ;; "@HURD@" is a placeholder.
316 (setenv "PATH" "@HURD@/bin")
317
318 (define (translated? node)
319 ;; Return true if a translator is installed on NODE.
320 (with-output-to-port (%make-void-port "w")
321 (lambda ()
322 (with-error-to-port (%make-void-port "w")
323 (lambda ()
324 (zero? (system* "showtrans" "-s" node)))))))
325
326 (for-each (match-lambda
327 ((node command)
328 (unless (translated? node)
329 (mkdir-p (dirname node))
330 (apply invoke "settrans" "-c" node command))))
331 '#$translators))))
332
333 ;; FIXME: We want the program to use the cross-compiled Guile when
334 ;; cross-compiling. But why do we need to be explicit here?
335 (with-parameters ((%current-target-system "i586-pc-gnu"))
336 (program-file "rc" rc)))
337
338 (define-public hurd
339 (package
340 (name "hurd")
341 (version (package-version hurd-headers))
342 (source (origin (inherit (package-source hurd-headers))
343 (patches (search-patches "hurd-cross.patch"))))
344 (arguments
345 `(#:phases
346 (modify-phases %standard-phases
347 (add-before 'build 'pre-build
348 (lambda _
349 ;; Don't change the ownership of any file at this time.
350 (substitute* '("daemons/Makefile" "utils/Makefile")
351 (("-o root -m 4755") ""))
352 #t))
353 (add-before 'build 'set-file-names
354 (lambda* (#:key inputs outputs #:allow-other-keys)
355 (let* ((out (assoc-ref outputs "out"))
356 (bash (assoc-ref inputs "bash-minimal"))
357 (coreutils (assoc-ref inputs "coreutils"))
358 (sed (assoc-ref inputs "sed"))
359 (grep (assoc-ref inputs "grep"))
360 (util-linux (assoc-ref inputs "util-linux")))
361 (substitute* '("daemons/runttys.c" "daemons/getty.c" "utils/login.c")
362 (("/bin/login")
363 (string-append out "/bin/login"))
364 (("/bin/bash") (string-append bash "/bin/bash")))
365 (substitute* '("startup/startup.c" "init/init.c" "config/ttys")
366 (("/libexec/")
367 (string-append out "/libexec/")))
368 (substitute* "daemons/console-run.c"
369 (("/hurd/")
370 (string-append out "/hurd/")))
371
372 (substitute* '("daemons/runsystem.sh"
373 "daemons/runsystem.hurd.sh"
374 "sutils/MAKEDEV.sh")
375 (("^PATH=.*")
376 (string-append "PATH=" out "/bin:" out "/sbin:"
377 coreutils "/bin:"
378 sed "/bin:" grep "/bin:"
379 util-linux "/bin\n"))
380 (("^SHELL=.*")
381 (string-append "SHELL=" bash "/bin/bash\n"))
382 (("/sbin/") (string-append out "/sbin/"))
383 (("/libexec/") (string-append out "/libexec/"))
384 (("/hurd/") (string-append out "/hurd/")))
385
386 (substitute* "daemons/runsystem.sh"
387 (("export PATH")
388 (string-append "export PATH\n"
389 "\
390 fsysopts / --writable
391
392 # MAKEDEV relies on pipes so this needs to be set up.
393 settrans -c /servers/socket/1 /hurd/pflocal
394
395 (cd /dev; MAKEDEV -D /dev std vcs tty{1,2,3,4,5,6})\n")))
396
397 (substitute* "daemons/runsystem.hurd.sh"
398 (("export PATH")
399 "export PATH
400 fsysopts / --writable\n"))
401 #t)))
402 (add-after 'patch-shebangs 'patch-libexec-shebangs
403 (lambda* (#:key inputs outputs #:allow-other-keys)
404 ;; XXX: Since the 'patch-shebangs' phase doesn't traverse
405 ;; /libexec, do it here.
406 (let* ((out (assoc-ref outputs "out"))
407 (bash (assoc-ref inputs "bash-minimal"))
408 (path (list (string-append bash "/bin"))))
409 (for-each (lambda (file)
410 (patch-shebang file path))
411 (find-files (string-append out "/libexec")))
412 #t)))
413 (add-after 'install 'install-goodies
414 (lambda* (#:key outputs #:allow-other-keys)
415 ;; Install additional goodies.
416 ;; TODO: Build & install *.msgids for rpctrace.
417 (let ((out (assoc-ref outputs "out")))
418 ;; Install the fancy UTF-8 motd.
419 (mkdir-p (string-append out "/etc"))
420 (copy-file "console/motd.UTF8"
421 (string-append out "/etc/motd"))
422 #t)))
423 (add-after 'install 'install-rc-file
424 (lambda* (#:key inputs outputs #:allow-other-keys)
425 (let* ((out (assoc-ref outputs "out"))
426 (file (string-append out "/libexec/rc"))
427 (rc (assoc-ref inputs "hurd-rc")))
428 (delete-file file)
429 (copy-file rc file)
430 (substitute* file
431 (("@HURD@") out))
432 #t))))
433 #:configure-flags (list (string-append "LDFLAGS=-Wl,-rpath="
434 %output "/lib")
435 "--disable-ncursesw"
436 "--without-libbz2"
437 "--without-libz"
438 "--without-parted")))
439 (build-system gnu-build-system)
440 (inputs
441 `(("glibc-hurd-headers" ,glibc/hurd-headers)
442 ("hurd-rc" ,(hurd-rc-script))
443
444 ("libgcrypt" ,libgcrypt) ;for /hurd/random
445 ;; Tools for the /libexec/* scripts.
446 ("bash-minimal" ,bash-minimal)
447 ("coreutils" ,coreutils)
448 ("sed" ,sed)
449 ("grep" ,grep)
450 ("util-linux" ,util-linux)))
451 (native-inputs
452 `(("autoconf" ,autoconf)
453 ("automake" ,automake)
454 ("libgcrypt" ,libgcrypt) ;for 'libgcrypt-config'
455 ("mig" ,(if (%current-target-system)
456 ;; XXX: When targeting i586-pc-gnu, we need a 32-bit MiG,
457 ;; hence this hack.
458 (package
459 (inherit mig)
460 (arguments `(#:system "i686-linux")))
461 mig))
462 ("perl" ,perl)
463 ("texinfo" ,texinfo-4)))
464 (supported-systems %hurd-systems)
465 (home-page "https://www.gnu.org/software/hurd/hurd.html")
466 (synopsis "The kernel servers for the GNU operating system")
467 (description
468 "The Hurd is the kernel for the GNU system, a replacement and
469 augmentation of standard Unix kernels. It is a collection of protocols for
470 system interaction (file systems, networks, authentication), and servers
471 implementing them.")
472 (license gpl2+)))