system: hurd: Add "/etc/fstab".
[jackhill/guix/guix.git] / gnu / system / hurd.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2020 Ludovic Courtès <ludo@gnu.org>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
10 ;;;
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19 (define-module (gnu system hurd)
20 #:use-module (guix gexp)
21 #:use-module (guix utils)
22 #:use-module (gnu bootloader grub)
23 #:use-module (gnu packages base)
24 #:use-module (gnu packages cross-base)
25 #:use-module (gnu packages hurd)
26 #:use-module (gnu system vm)
27 #:export (cross-hurd-image))
28
29 ;;; Commentary:
30 ;;;
31 ;;; This module provides tools to (cross-)build GNU/Hurd virtual machine
32 ;;; images.
33 ;;;
34 ;;; Code:
35
36 (define* (cross-hurd-image #:key (hurd hurd) (gnumach gnumach))
37 "Return a cross-built GNU/Hurd image."
38 (define hurd-os
39 (let-syntax ((for-hurd (syntax-rules ()
40 ((_ things ...)
41 (list (with-parameters ((%current-target-system
42 "i586-pc-gnu"))
43 things) ...)))))
44 (directory-union "gnu+hurd"
45 (cons (with-parameters ((%current-system "i686-linux"))
46 gnumach)
47 (for-hurd hurd coreutils grep sed)))))
48
49 (define grub.cfg
50 (let ((hurd (with-parameters ((%current-target-system "i586-pc-gnu"))
51 hurd))
52 (mach (with-parameters ((%current-system "i686-linux"))
53 gnumach))
54 (libc (cross-libc "i586-pc-gnu")))
55 (computed-file "grub.cfg"
56 #~(call-with-output-file #$output
57 (lambda (port)
58 (format port "
59 set timeout=2
60 search.file ~a/boot/gnumach
61
62 menuentry \"GNU\" {
63 multiboot ~a/boot/gnumach root=device:hd0s1
64 module ~a/hurd/ext2fs.static ext2fs \\
65 --multiboot-command-line='${kernel-command-line}' \\
66 --host-priv-port='${host-port}' \\
67 --device-master-port='${device-port}' \\
68 --exec-server-task='${exec-task}' -T typed '${root}' \\
69 '$(task-create)' '$(task-resume)'
70 module ~a/lib/ld.so.1 exec ~a/hurd/exec '$(exec-task=task-create)'
71 }\n"
72 #+mach #+mach #+hurd
73 #+libc #+hurd))))))
74
75 (define fstab
76 (plain-file "fstab"
77 "# This file was generated from your Guix configuration. Any changes
78 # will be lost upon reboot or reconfiguration.
79
80 /dev/hd0s1 / ext2 defaults
81 "))
82
83 (define hurd-directives
84 `((directory "/servers")
85 ,@(map (lambda (server)
86 `(file ,(string-append "/servers/" server)))
87 '("startup" "exec" "proc" "password"
88 "default-pager" "crash-dump-core"
89 "kill" "suspend"))
90 ("/servers/crash" -> "crash-dump-core")
91 (directory "/servers/socket")
92 (file "/servers/socket/1")
93 (file "/servers/socket/2")
94 (file "/servers/socket/16")
95 ("/servers/socket/local" -> "1")
96 ("/servers/socket/inet" -> "2")
97 ("/servers/socket/inet6" -> "16")
98 (file "/etc/resolv.conf"
99 "nameserver 10.0.2.3\n")
100 (directory "/boot")
101 ("/boot/grub.cfg" -> ,grub.cfg) ;XXX: not strictly needed
102 ("/hurd" -> ,(file-append (with-parameters ((%current-target-system
103 "i586-pc-gnu"))
104 hurd)
105 "/hurd"))
106 ("/etc/fstab" -> ,fstab)))
107
108 (qemu-image #:file-system-type "ext2"
109 #:file-system-options '("-o" "hurd")
110 #:device-nodes 'hurd
111 #:inputs `(("system" ,hurd-os)
112 ("grub.cfg" ,grub.cfg)
113 ("fstab" , fstab))
114 #:copy-inputs? #t
115 #:os hurd-os
116 #:bootcfg-drv grub.cfg
117 #:bootloader grub-bootloader
118 #:register-closures? #f
119 #:extra-directives hurd-directives))
120
121 ;; Return this thunk so one can type "guix build -f gnu/system/hurd.scm".
122 cross-hurd-image