Commit | Line | Data |
---|---|---|
a9f7993e LC |
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) | |
fe1f9646 | 24 | #:use-module (gnu packages bash) |
a9f7993e LC |
25 | #:use-module (gnu packages cross-base) |
26 | #:use-module (gnu packages hurd) | |
27 | #:use-module (gnu system vm) | |
28 | #:export (cross-hurd-image)) | |
29 | ||
30 | ;;; Commentary: | |
31 | ;;; | |
32 | ;;; This module provides tools to (cross-)build GNU/Hurd virtual machine | |
33 | ;;; images. | |
34 | ;;; | |
35 | ;;; Code: | |
36 | ||
37 | (define* (cross-hurd-image #:key (hurd hurd) (gnumach gnumach)) | |
38 | "Return a cross-built GNU/Hurd image." | |
39 | (define hurd-os | |
40 | (let-syntax ((for-hurd (syntax-rules () | |
41 | ((_ things ...) | |
42 | (list (with-parameters ((%current-target-system | |
43 | "i586-pc-gnu")) | |
44 | things) ...))))) | |
45 | (directory-union "gnu+hurd" | |
46 | (cons (with-parameters ((%current-system "i686-linux")) | |
47 | gnumach) | |
fe1f9646 | 48 | (for-hurd hurd bash coreutils grep sed))))) |
a9f7993e LC |
49 | |
50 | (define grub.cfg | |
51 | (let ((hurd (with-parameters ((%current-target-system "i586-pc-gnu")) | |
52 | hurd)) | |
53 | (mach (with-parameters ((%current-system "i686-linux")) | |
54 | gnumach)) | |
55 | (libc (cross-libc "i586-pc-gnu"))) | |
56 | (computed-file "grub.cfg" | |
57 | #~(call-with-output-file #$output | |
58 | (lambda (port) | |
59 | (format port " | |
60 | set timeout=2 | |
61 | search.file ~a/boot/gnumach | |
62 | ||
63 | menuentry \"GNU\" { | |
64 | multiboot ~a/boot/gnumach root=device:hd0s1 | |
65 | module ~a/hurd/ext2fs.static ext2fs \\ | |
66 | --multiboot-command-line='${kernel-command-line}' \\ | |
67 | --host-priv-port='${host-port}' \\ | |
68 | --device-master-port='${device-port}' \\ | |
69 | --exec-server-task='${exec-task}' -T typed '${root}' \\ | |
70 | '$(task-create)' '$(task-resume)' | |
71 | module ~a/lib/ld.so.1 exec ~a/hurd/exec '$(exec-task=task-create)' | |
72 | }\n" | |
73 | #+mach #+mach #+hurd | |
74 | #+libc #+hurd)))))) | |
75 | ||
379d0f51 JN |
76 | (define fstab |
77 | (plain-file "fstab" | |
78 | "# This file was generated from your Guix configuration. Any changes | |
79 | # will be lost upon reboot or reconfiguration. | |
80 | ||
81 | /dev/hd0s1 / ext2 defaults | |
82 | ")) | |
83 | ||
6598c614 JN |
84 | (define passwd |
85 | (plain-file "passwd" | |
86 | "root:x:0:0:root:/root:/bin/sh | |
87 | " | |
88 | )) | |
89 | ||
90 | (define shadow | |
91 | (plain-file "shadow" | |
92 | "root::0:0:0:0::: | |
93 | " | |
94 | )) | |
95 | ||
a9f7993e LC |
96 | (define hurd-directives |
97 | `((directory "/servers") | |
98 | ,@(map (lambda (server) | |
99 | `(file ,(string-append "/servers/" server))) | |
100 | '("startup" "exec" "proc" "password" | |
101 | "default-pager" "crash-dump-core" | |
102 | "kill" "suspend")) | |
103 | ("/servers/crash" -> "crash-dump-core") | |
104 | (directory "/servers/socket") | |
105 | (file "/servers/socket/1") | |
106 | (file "/servers/socket/2") | |
107 | (file "/servers/socket/16") | |
108 | ("/servers/socket/local" -> "1") | |
109 | ("/servers/socket/inet" -> "2") | |
110 | ("/servers/socket/inet6" -> "16") | |
a9f7993e LC |
111 | (directory "/boot") |
112 | ("/boot/grub.cfg" -> ,grub.cfg) ;XXX: not strictly needed | |
113 | ("/hurd" -> ,(file-append (with-parameters ((%current-target-system | |
114 | "i586-pc-gnu")) | |
115 | hurd) | |
379d0f51 | 116 | "/hurd")) |
5fbf4f85 LC |
117 | |
118 | ;; TODO: Create those during activation, eventually. | |
119 | (directory "/root") | |
cd4faab5 | 120 | ("/etc/fstab" -> ,fstab) |
6598c614 JN |
121 | ("/etc/passwd" -> ,passwd) |
122 | ("/etc/shadow" -> ,shadow) | |
5fbf4f85 LC |
123 | (file "/etc/hostname" "guixygnu") |
124 | (file "/etc/resolv.conf" | |
125 | "nameserver 10.0.2.3\n") | |
126 | ||
127 | ("/etc/motd" -> ,(file-append (with-parameters ((%current-target-system | |
128 | "i586-pc-gnu")) | |
129 | hurd) | |
130 | "/etc/motd")) | |
131 | ("/etc/login" -> ,(file-append (with-parameters ((%current-target-system | |
132 | "i586-pc-gnu")) | |
133 | hurd) | |
134 | "/etc/login")) | |
135 | ||
136 | ||
cd4faab5 JN |
137 | ;; XXX can we instead, harmlessly set _PATH_TTYS (from glibc) in runttys.c? |
138 | ("/etc/ttys" -> ,(file-append (with-parameters ((%current-target-system | |
139 | "i586-pc-gnu")) | |
140 | hurd) | |
fe1f9646 JN |
141 | "/etc/ttys")) |
142 | ("/bin/sh" -> ,(file-append (with-parameters ((%current-target-system | |
143 | "i586-pc-gnu")) | |
144 | bash) | |
145 | "/bin/sh")))) | |
a9f7993e LC |
146 | |
147 | (qemu-image #:file-system-type "ext2" | |
148 | #:file-system-options '("-o" "hurd") | |
149 | #:device-nodes 'hurd | |
150 | #:inputs `(("system" ,hurd-os) | |
379d0f51 | 151 | ("grub.cfg" ,grub.cfg) |
6598c614 JN |
152 | ("fstab" ,fstab) |
153 | ("passwd" ,passwd) | |
154 | ("shadow" ,shadow)) | |
a9f7993e LC |
155 | #:copy-inputs? #t |
156 | #:os hurd-os | |
157 | #:bootcfg-drv grub.cfg | |
158 | #:bootloader grub-bootloader | |
159 | #:register-closures? #f | |
160 | #:extra-directives hurd-directives)) | |
161 | ||
162 | ;; Return this thunk so one can type "guix build -f gnu/system/hurd.scm". | |
163 | cross-hurd-image |