gnu: hurd: Provide our own /libexec/rc script.
[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 bison)
35 #:use-module (gnu packages perl)
36 #:use-module (gnu packages base)
37 #:use-module (gnu packages texinfo)
38 #:use-module (guix git-download)
39 #:export (hurd-system?
40 hurd-target?
41 hurd-triplet?))
42
43 (define (hurd-triplet? triplet)
44 (and (string-suffix? "-gnu" triplet)
45 (not (string-contains triplet "linux"))))
46
47 (define (hurd-target?)
48 "Return true if the cross-compilation target or the current system is
49 GNU/Hurd."
50 (or (and=> (%current-target-system) hurd-triplet?)
51 (and (not (%current-target-system))
52 (and=> (%current-system) hurd-triplet?))))
53
54 (define (hurd-system?)
55 "Return true if the current system is the Hurd."
56 (and=> (%current-system) hurd-triplet?))
57
58 (define (hurd-source-url version)
59 (string-append "mirror://gnu/hurd/hurd-"
60 version ".tar.gz"))
61
62 (define-public gnumach-headers
63 (let ((commit "097f9cf735ffa1212b828682ad92f0f6c5f1c552")
64 (revision "1"))
65 (package
66 (name "gnumach-headers")
67 (version (git-version "1.8" revision commit))
68 (source
69 (origin
70 (method git-fetch)
71 (uri (git-reference
72 (url "https://git.savannah.gnu.org/git/hurd/gnumach.git")
73 (commit commit)))
74 (file-name (git-file-name "gnumach" version))
75 (sha256
76 (base32
77 "0q36z7k02bykrld90zaxbhyzxlmwlqqs4divgir6ix38zsp6icqk"))))
78 (build-system gnu-build-system)
79 (arguments
80 `(#:phases
81 (modify-phases %standard-phases
82 (replace 'install
83 (lambda _
84 (invoke "make" "install-data")))
85 (delete 'build))
86
87 ;; GNU Mach supports only IA32 currently, so cheat so that we can at
88 ;; least install its headers.
89 ,@(if (%current-target-system)
90 '()
91 ;; See <http://lists.gnu.org/archive/html/bug-hurd/2015-06/msg00042.html>
92 ;; <http://lists.gnu.org/archive/html/guix-devel/2015-06/msg00716.html>
93 '(#:configure-flags '("--build=i586-pc-gnu"
94 "--host=i686-linux-gnu")))
95
96 #:tests? #f))
97 (native-inputs
98 `(("autoconf" ,autoconf)
99 ("automake" ,automake)
100 ("texinfo" ,texinfo-4)))
101 (home-page "https://www.gnu.org/software/hurd/microkernel/mach/gnumach.html")
102 (synopsis "GNU Mach kernel headers")
103 (description
104 "Headers of the GNU Mach kernel.")
105 (license gpl2+))))
106
107 (define-public mig
108 (package
109 (name "mig")
110 (version "1.8")
111 (source
112 (origin
113 (method url-fetch)
114 (uri (string-append "mirror://gnu/mig/mig-"
115 version ".tar.gz"))
116 (sha256
117 (base32
118 "1gyda8sq6b379nx01hkpbd85lz39irdvz2b9wbr63gicicx8i706"))))
119 (build-system gnu-build-system)
120 ;; Flex is needed both at build and run time.
121 (inputs `(("gnumach-headers" ,gnumach-headers)
122 ("flex" ,flex)))
123 (native-inputs
124 `(("flex" ,flex)
125 ("bison" ,bison)))
126 (arguments `(#:tests? #f))
127 (home-page "https://www.gnu.org/software/hurd/microkernel/mach/mig/gnu_mig.html")
128 (synopsis "Mach 3.0 interface generator for the Hurd")
129 (description
130 "GNU MIG is the GNU distribution of the Mach 3.0 interface generator
131 MIG, as maintained by the GNU Hurd developers for the GNU project.
132 You need this tool to compile the GNU Mach and GNU Hurd distributions,
133 and to compile the GNU C library for the Hurd. Also, you will need it
134 for other software in the GNU system that uses Mach-based inter-process
135 communication.")
136 (license gpl2+)))
137
138 (define-public hurd-headers
139 ;; Resort to a post-0.9 snapshot that provides the 'file_utimens' and
140 ;; 'file_exec_paths' RPCs that glibc 2.28 expects.
141 (let ((revision "1")
142 (commit "91a51672ff4cfe1f1a0712b4c542ded3081c825b"))
143 (package
144 (name "hurd-headers")
145 (version (git-version "0.9" revision commit))
146 (source (origin
147 (method git-fetch)
148 (uri (git-reference
149 (url "https://git.savannah.gnu.org/git/hurd/hurd.git")
150 (commit commit)))
151 (sha256
152 (base32
153 "16k9wkahz9wasviijz53n6i13nmiwa9fs64ikf1jqh8rl60hw7cz"))
154 (file-name (git-file-name name version))))
155 (build-system gnu-build-system)
156 (native-inputs
157 `(("mig" ,mig)
158 ("autoconf" ,autoconf)
159 ("automake" ,automake)))
160 (arguments
161 `(#:phases
162 (modify-phases %standard-phases
163 (replace 'install
164 (lambda _
165 (invoke "make" "install-headers" "no_deps=t")))
166 (delete 'build))
167
168 #:configure-flags '( ;; Pretend we're on GNU/Hurd; 'configure' wants
169 ;; that.
170 ,@(if (%current-target-system)
171 '()
172 '("--host=i586-pc-gnu"))
173
174 ;; Reduce set of dependencies.
175 "--without-parted"
176 "--disable-ncursesw"
177 "--disable-test"
178 "--without-libbz2"
179 "--without-libcrypt"
180 "--without-libz"
181 ;; Skip the clnt_create check because it expects
182 ;; a working glibc causing a circular dependency.
183 "ac_cv_search_clnt_create=no"
184
185 ;; Annihilate the checks for the 'file_exec_paths'
186 ;; & co. libc functions to avoid "link tests are
187 ;; not allowed after AC_NO_EXECUTABLES" error.
188 "ac_cv_func_file_exec_paths=no"
189 "ac_cv_func_exec_exec_paths=no"
190 "ac_cv_func__hurd_exec_paths=no"
191 "ac_cv_func_file_futimens=no")
192
193 #:tests? #f))
194 (home-page "https://www.gnu.org/software/hurd/hurd.html")
195 (synopsis "GNU Hurd headers")
196 (description
197 "This package provides C headers of the GNU Hurd, used to build the GNU C
198 Library and other user programs.")
199 (license gpl2+))))
200
201 (define-public hurd-minimal
202 (package (inherit hurd-headers)
203 (name "hurd-minimal")
204 (inputs `(("glibc-hurd-headers" ,glibc/hurd-headers)))
205 (arguments
206 (substitute-keyword-arguments (package-arguments hurd-headers)
207 ((#:phases _)
208 '(modify-phases %standard-phases
209 (replace 'install
210 (lambda* (#:key outputs #:allow-other-keys)
211 (let ((out (assoc-ref outputs "out")))
212 ;; We need to copy libihash.a to the output directory manually,
213 ;; since there is no target for that in the makefile.
214 (mkdir-p (string-append out "/include"))
215 (copy-file "libihash/ihash.h"
216 (string-append out "/include/ihash.h"))
217 (mkdir-p (string-append out "/lib"))
218 (copy-file "libihash/libihash.a"
219 (string-append out "/lib/libihash.a"))
220 #t)))
221 (replace 'build
222 (lambda _
223 ;; Install <assert-backtrace.h> & co.
224 (invoke "make" "-Clibshouldbeinlibc"
225 "../include/assert-backtrace.h")
226
227 ;; Build libihash.
228 (invoke "make" "-Clibihash" "libihash.a")))))))
229 (home-page "https://www.gnu.org/software/hurd/hurd.html")
230 (synopsis "GNU Hurd libraries")
231 (description
232 "This package provides libihash, needed to build the GNU C
233 Library for GNU/Hurd.")
234 (license gpl2+)))
235
236 (define-public hurd-core-headers
237 (package
238 (name "hurd-core-headers")
239 (version (package-version hurd-headers))
240 (source #f)
241 (build-system trivial-build-system)
242 (arguments
243 '(#:modules ((guix build union))
244 #:builder (begin
245 (use-modules (ice-9 match)
246 (guix build union))
247 (match %build-inputs
248 (((names . directories) ...)
249 (union-build (assoc-ref %outputs "out")
250 directories)
251 #t)))))
252 (inputs `(("gnumach-headers" ,gnumach-headers)
253 ("hurd-headers" ,hurd-headers)
254 ("hurd-minimal" ,hurd-minimal)))
255 (synopsis "Union of the Hurd headers and libraries")
256 (description
257 "This package contains the union of the Mach and Hurd headers and the
258 Hurd-minimal package which are needed for both glibc and GCC.")
259 (home-page (package-home-page hurd-headers))
260 (license (package-license hurd-headers))))
261
262 (define-public gnumach
263 (package
264 (inherit gnumach-headers)
265 (name "gnumach")
266 (arguments
267 (substitute-keyword-arguments (package-arguments gnumach-headers)
268 ((#:configure-flags flags ''())
269 `(cons "--enable-kdb" ,flags)) ;enable kernel debugger
270 ((#:phases phases '%standard-phases)
271 `(modify-phases %standard-phases
272 (add-after 'install 'produce-image
273 (lambda* (#:key outputs #:allow-other-keys)
274 (let* ((out (assoc-ref outputs "out"))
275 (boot (string-append out "/boot")))
276 (invoke "make" "gnumach.gz")
277 (install-file "gnumach.gz" boot)
278 #t)))))))
279 (native-inputs
280 `(("mig" ,mig)
281 ("perl" ,perl)
282 ("autoconf" ,autoconf)
283 ("automake" ,automake)
284 ("texinfo" ,texinfo-4)))
285 (supported-systems (cons "i686-linux" %hurd-systems))
286 (synopsis "Microkernel of the GNU system")
287 (description
288 "GNU Mach is the microkernel upon which a GNU Hurd system is based.")))
289
290 (define (hurd-rc-script)
291 "Return a script to be installed as /libexec/rc in the 'hurd' package. The
292 script takes care of installing the relevant passive translators on the first
293 boot, since this cannot be done from GNU/Linux."
294 (define translators
295 '(("/servers/crash-dump-core" ("/hurd/crash" "--dump-core"))
296 ("/servers/crash-kill" ("/hurd/crash" "--kill"))
297 ("/servers/crash-suspend" ("/hurd/crash" "--suspend"))
298 ("/servers/password" ("/hurd/password"))
299 ("/servers/socket/1" ("/hurd/pflocal"))
300 ("/servers/socket/2" ("/hurd/pfinet" "--interface" "eth0"
301 "--address" "10.0.2.77"
302 "--netmask" "255.255.255.0"
303 "--gateway" "10.0.2.2"
304 "--ipv6" "/servers/socket/16"))))
305
306 (define rc
307 (with-imported-modules '((guix build utils))
308 #~(begin
309 (use-modules (guix build utils)
310 (ice-9 match))
311
312 ;; "@HURD@" is a placeholder.
313 (setenv "PATH" "@HURD@/bin")
314
315 (define (translated? node)
316 ;; Return true if a translator is installed on NODE.
317 (with-output-to-port (%make-void-port "w")
318 (lambda ()
319 (with-error-to-port (%make-void-port "w")
320 (lambda ()
321 (zero? (system* "showtrans" "-s" node)))))))
322
323 (for-each (match-lambda
324 ((node command)
325 (unless (translated? node)
326 (mkdir-p (dirname node))
327 (apply invoke "settrans" "-c" node command))))
328 '#$translators))))
329
330 ;; FIXME: We want the program to use the cross-compiled Guile when
331 ;; cross-compiling. But why do we need to be explicit here?
332 (with-parameters ((%current-target-system "i586-pc-gnu"))
333 (program-file "rc" rc)))
334
335 (define-public hurd
336 (package
337 (name "hurd")
338 (version (package-version hurd-headers))
339 (source (origin (inherit (package-source hurd-headers))
340 (patches (search-patches "hurd-cross.patch"))))
341 (arguments
342 `(#:phases
343 (modify-phases %standard-phases
344 (add-before 'build 'pre-build
345 (lambda _
346 ;; Don't change the ownership of any file at this time.
347 (substitute* '("daemons/Makefile" "utils/Makefile")
348 (("-o root -m 4755") ""))
349 #t))
350 (add-after 'install 'install-rc-file
351 (lambda* (#:key inputs outputs #:allow-other-keys)
352 (let* ((out (assoc-ref outputs "out"))
353 (file (string-append out "/libexec/rc"))
354 (rc (assoc-ref inputs "hurd-rc")))
355 (delete-file file)
356 (copy-file rc file)
357 (substitute* file
358 (("@HURD@") out))
359 #t))))
360 #:configure-flags (list (string-append "LDFLAGS=-Wl,-rpath="
361 %output "/lib")
362 "--disable-ncursesw"
363 "--without-libbz2"
364 "--without-libz"
365 "--without-parted")))
366 (build-system gnu-build-system)
367 (inputs
368 `(("glibc-hurd-headers" ,glibc/hurd-headers)
369 ("hurd-rc" ,(hurd-rc-script))))
370 (native-inputs
371 `(("autoconf" ,autoconf)
372 ("automake" ,automake)
373 ("mig" ,mig)
374 ("perl" ,perl)
375 ("texinfo" ,texinfo-4)))
376 (supported-systems %hurd-systems)
377 (home-page "https://www.gnu.org/software/hurd/hurd.html")
378 (synopsis "The kernel servers for the GNU operating system")
379 (description
380 "The Hurd is the kernel for the GNU system, a replacement and
381 augmentation of standard Unix kernels. It is a collection of protocols for
382 system interaction (file systems, networks, authentication), and servers
383 implementing them.")
384 (license gpl2+)))