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