system: hurd: Add /etc/{passwd,shadow}.
[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 passwd
84 (plain-file "passwd"
85 "root:x:0:0:root:/root:/bin/sh
86 "
87 ))
88
89 (define shadow
90 (plain-file "shadow"
91 "root::0:0:0:0:::
92 "
93 ))
94
95 (define hurd-directives
96 `((directory "/servers")
97 ,@(map (lambda (server)
98 `(file ,(string-append "/servers/" server)))
99 '("startup" "exec" "proc" "password"
100 "default-pager" "crash-dump-core"
101 "kill" "suspend"))
102 ("/servers/crash" -> "crash-dump-core")
103 (directory "/servers/socket")
104 (file "/servers/socket/1")
105 (file "/servers/socket/2")
106 (file "/servers/socket/16")
107 ("/servers/socket/local" -> "1")
108 ("/servers/socket/inet" -> "2")
109 ("/servers/socket/inet6" -> "16")
110 (file "/etc/resolv.conf"
111 "nameserver 10.0.2.3\n")
112 (directory "/boot")
113 ("/boot/grub.cfg" -> ,grub.cfg) ;XXX: not strictly needed
114 ("/hurd" -> ,(file-append (with-parameters ((%current-target-system
115 "i586-pc-gnu"))
116 hurd)
117 "/hurd"))
118 ("/etc/fstab" -> ,fstab)
119 ("/etc/passwd" -> ,passwd)
120 ("/etc/shadow" -> ,shadow)
121 ;; XXX can we instead, harmlessly set _PATH_TTYS (from glibc) in runttys.c?
122 ("/etc/ttys" -> ,(file-append (with-parameters ((%current-target-system
123 "i586-pc-gnu"))
124 hurd)
125 "/etc/ttys"))))
126
127 (qemu-image #:file-system-type "ext2"
128 #:file-system-options '("-o" "hurd")
129 #:device-nodes 'hurd
130 #:inputs `(("system" ,hurd-os)
131 ("grub.cfg" ,grub.cfg)
132 ("fstab" ,fstab)
133 ("passwd" ,passwd)
134 ("shadow" ,shadow))
135 #:copy-inputs? #t
136 #:os hurd-os
137 #:bootcfg-drv grub.cfg
138 #:bootloader grub-bootloader
139 #:register-closures? #f
140 #:extra-directives hurd-directives))
141
142 ;; Return this thunk so one can type "guix build -f gnu/system/hurd.scm".
143 cross-hurd-image