Commit | Line | Data |
---|---|---|
a9f7993e LC |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2020 Ludovic Courtès <ludo@gnu.org> | |
3eb4b466 | 3 | ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> |
a9f7993e LC |
4 | ;;; |
5 | ;;; This file is part of GNU Guix. | |
6 | ;;; | |
7 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
8 | ;;; under the terms of the GNU General Public License as published by | |
9 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
10 | ;;; your option) any later version. | |
11 | ;;; | |
12 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
13 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | ;;; GNU General Public License for more details. | |
16 | ;;; | |
17 | ;;; You should have received a copy of the GNU General Public License | |
18 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
19 | ||
20 | (define-module (gnu system hurd) | |
21 | #:use-module (guix gexp) | |
c6212694 | 22 | #:use-module (guix profiles) |
a9f7993e LC |
23 | #:use-module (guix utils) |
24 | #:use-module (gnu bootloader grub) | |
db047a48 | 25 | #:use-module (gnu packages admin) |
a9f7993e | 26 | #:use-module (gnu packages base) |
fe1f9646 | 27 | #:use-module (gnu packages bash) |
a9f7993e | 28 | #:use-module (gnu packages cross-base) |
da987ece JN |
29 | #:use-module (gnu packages file) |
30 | #:use-module (gnu packages guile) | |
5084fd38 | 31 | #:use-module (gnu packages guile-xyz) |
a9f7993e | 32 | #:use-module (gnu packages hurd) |
9b0c047c | 33 | #:use-module (gnu packages less) |
a9f7993e LC |
34 | #:use-module (gnu system vm) |
35 | #:export (cross-hurd-image)) | |
36 | ||
37 | ;;; Commentary: | |
38 | ;;; | |
39 | ;;; This module provides tools to (cross-)build GNU/Hurd virtual machine | |
40 | ;;; images. | |
41 | ;;; | |
42 | ;;; Code: | |
43 | ||
da987ece | 44 | (define %base-packages/hurd |
5084fd38 LC |
45 | (list hurd bash coreutils file findutils grep sed |
46 | guile-3.0 guile-colorized guile-readline | |
9b0c047c | 47 | net-base inetutils less which)) |
da987ece | 48 | |
a9f7993e LC |
49 | (define* (cross-hurd-image #:key (hurd hurd) (gnumach gnumach)) |
50 | "Return a cross-built GNU/Hurd image." | |
da987ece | 51 | |
c6212694 LC |
52 | (define (cross-built thing) |
53 | (with-parameters ((%current-target-system "i586-pc-gnu")) | |
54 | thing)) | |
55 | ||
56 | (define (cross-built-entry entry) | |
57 | (manifest-entry | |
58 | (inherit entry) | |
59 | (item (cross-built (manifest-entry-item entry))) | |
60 | (dependencies (map cross-built-entry | |
61 | (manifest-entry-dependencies entry))))) | |
da987ece | 62 | |
c6212694 | 63 | (define system-profile |
c041c360 LC |
64 | (profile |
65 | (content | |
66 | (map-manifest-entries cross-built-entry | |
67 | (packages->manifest %base-packages/hurd))))) | |
a9f7993e LC |
68 | |
69 | (define grub.cfg | |
c6212694 | 70 | (let ((hurd (cross-built hurd)) |
a9f7993e LC |
71 | (mach (with-parameters ((%current-system "i686-linux")) |
72 | gnumach)) | |
73 | (libc (cross-libc "i586-pc-gnu"))) | |
74 | (computed-file "grub.cfg" | |
75 | #~(call-with-output-file #$output | |
76 | (lambda (port) | |
77 | (format port " | |
78 | set timeout=2 | |
79 | search.file ~a/boot/gnumach | |
80 | ||
81 | menuentry \"GNU\" { | |
82 | multiboot ~a/boot/gnumach root=device:hd0s1 | |
83 | module ~a/hurd/ext2fs.static ext2fs \\ | |
84 | --multiboot-command-line='${kernel-command-line}' \\ | |
85 | --host-priv-port='${host-port}' \\ | |
86 | --device-master-port='${device-port}' \\ | |
87 | --exec-server-task='${exec-task}' -T typed '${root}' \\ | |
88 | '$(task-create)' '$(task-resume)' | |
89 | module ~a/lib/ld.so.1 exec ~a/hurd/exec '$(exec-task=task-create)' | |
90 | }\n" | |
91 | #+mach #+mach #+hurd | |
92 | #+libc #+hurd)))))) | |
93 | ||
379d0f51 JN |
94 | (define fstab |
95 | (plain-file "fstab" | |
da987ece | 96 | "# This file was generated from your Guix configuration. Any changes |
379d0f51 JN |
97 | # will be lost upon reboot or reconfiguration. |
98 | ||
99 | /dev/hd0s1 / ext2 defaults | |
100 | ")) | |
101 | ||
6598c614 JN |
102 | (define passwd |
103 | (plain-file "passwd" | |
da987ece | 104 | "root:x:0:0:root:/root:/bin/sh |
3eb4b466 JN |
105 | guixbuilder:x:1:1:guixbuilder:/var/empty:/bin/no-sh |
106 | ")) | |
107 | ||
108 | (define group | |
109 | (plain-file "group" | |
110 | "guixbuild:x:1:guixbuilder | |
da987ece | 111 | ")) |
6598c614 JN |
112 | |
113 | (define shadow | |
114 | (plain-file "shadow" | |
da987ece JN |
115 | "root::0:0:0:0::: |
116 | ")) | |
6598c614 | 117 | |
c6212694 LC |
118 | (define etc-profile |
119 | (plain-file "profile" | |
120 | "\ | |
121 | export PS1='\\u@\\h\\$ ' | |
122 | ||
123 | GUIX_PROFILE=\"/run/current-system/profile\" | |
124 | . \"$GUIX_PROFILE/etc/profile\" | |
125 | ||
126 | GUIX_PROFILE=\"$HOME/.guix-profile\" | |
127 | if [ -f \"$GUIX_PROFILE/etc/profile\" ]; then | |
128 | . \"$GUIX_PROFILE/etc/profile\" | |
129 | fi\n")) | |
130 | ||
a9f7993e LC |
131 | (define hurd-directives |
132 | `((directory "/servers") | |
133 | ,@(map (lambda (server) | |
134 | `(file ,(string-append "/servers/" server))) | |
135 | '("startup" "exec" "proc" "password" | |
136 | "default-pager" "crash-dump-core" | |
137 | "kill" "suspend")) | |
138 | ("/servers/crash" -> "crash-dump-core") | |
139 | (directory "/servers/socket") | |
140 | (file "/servers/socket/1") | |
141 | (file "/servers/socket/2") | |
142 | (file "/servers/socket/16") | |
143 | ("/servers/socket/local" -> "1") | |
144 | ("/servers/socket/inet" -> "2") | |
145 | ("/servers/socket/inet6" -> "16") | |
a9f7993e | 146 | (directory "/boot") |
da987ece | 147 | ("/boot/grub.cfg" -> ,grub.cfg) ;XXX: not strictly needed |
a9f7993e LC |
148 | ("/hurd" -> ,(file-append (with-parameters ((%current-target-system |
149 | "i586-pc-gnu")) | |
150 | hurd) | |
379d0f51 | 151 | "/hurd")) |
5fbf4f85 LC |
152 | |
153 | ;; TODO: Create those during activation, eventually. | |
154 | (directory "/root") | |
5084fd38 LC |
155 | (file "/root/.guile" |
156 | ,(object->string | |
157 | '(begin | |
158 | (use-modules (ice-9 readline) (ice-9 colorized)) | |
159 | (activate-readline) (activate-colorized)))) | |
c6212694 LC |
160 | (directory "/run") |
161 | (directory "/run/current-system") | |
162 | ("/run/current-system/profile" -> ,system-profile) | |
163 | ("/etc/profile" -> ,etc-profile) | |
cd4faab5 | 164 | ("/etc/fstab" -> ,fstab) |
3eb4b466 | 165 | ("/etc/group" -> ,group) |
6598c614 JN |
166 | ("/etc/passwd" -> ,passwd) |
167 | ("/etc/shadow" -> ,shadow) | |
5fbf4f85 LC |
168 | (file "/etc/hostname" "guixygnu") |
169 | (file "/etc/resolv.conf" | |
170 | "nameserver 10.0.2.3\n") | |
db047a48 JN |
171 | ("/etc/services" -> ,(file-append (with-parameters ((%current-target-system |
172 | "i586-pc-gnu")) | |
173 | net-base) | |
174 | "/etc/services")) | |
175 | ("/etc/protocols" -> ,(file-append (with-parameters ((%current-target-system | |
176 | "i586-pc-gnu")) | |
177 | net-base) | |
178 | "/etc/protocols")) | |
5fbf4f85 LC |
179 | ("/etc/motd" -> ,(file-append (with-parameters ((%current-target-system |
180 | "i586-pc-gnu")) | |
181 | hurd) | |
182 | "/etc/motd")) | |
183 | ("/etc/login" -> ,(file-append (with-parameters ((%current-target-system | |
da987ece JN |
184 | "i586-pc-gnu")) |
185 | hurd) | |
5fbf4f85 LC |
186 | "/etc/login")) |
187 | ||
188 | ||
cd4faab5 JN |
189 | ;; XXX can we instead, harmlessly set _PATH_TTYS (from glibc) in runttys.c? |
190 | ("/etc/ttys" -> ,(file-append (with-parameters ((%current-target-system | |
da987ece JN |
191 | "i586-pc-gnu")) |
192 | hurd) | |
193 | "/etc/ttys")) | |
fe1f9646 JN |
194 | ("/bin/sh" -> ,(file-append (with-parameters ((%current-target-system |
195 | "i586-pc-gnu")) | |
196 | bash) | |
197 | "/bin/sh")))) | |
a9f7993e LC |
198 | |
199 | (qemu-image #:file-system-type "ext2" | |
200 | #:file-system-options '("-o" "hurd") | |
201 | #:device-nodes 'hurd | |
c6212694 | 202 | #:inputs `(("system" ,system-profile) |
379d0f51 | 203 | ("grub.cfg" ,grub.cfg) |
6598c614 JN |
204 | ("fstab" ,fstab) |
205 | ("passwd" ,passwd) | |
3eb4b466 | 206 | ("group" ,group) |
c6212694 | 207 | ("etc-profile" ,etc-profile) |
6598c614 | 208 | ("shadow" ,shadow)) |
a9f7993e | 209 | #:copy-inputs? #t |
c6212694 | 210 | #:os system-profile |
a9f7993e LC |
211 | #:bootcfg-drv grub.cfg |
212 | #:bootloader grub-bootloader | |
213 | #:register-closures? #f | |
214 | #:extra-directives hurd-directives)) | |
215 | ||
216 | ;; Return this thunk so one can type "guix build -f gnu/system/hurd.scm". | |
217 | cross-hurd-image |