summaryrefslogtreecommitdiff
path: root/gnu/build
diff options
context:
space:
mode:
authorJan (janneke) Nieuwenhuizen <janneke@gnu.org>2020-06-01 09:46:39 +0200
committerJan Nieuwenhuizen <janneke@gnu.org>2020-06-08 14:26:14 +0200
commitb37c544196898cc3dfa3da07ed344fbe11abc120 (patch)
tree78d72f743763b699ed29402aab35699286b81db7 /gnu/build
parent11e4200feeffcf1abdd1559c9fca48373599ab10 (diff)
hurd-boot: Further cleanup of "rc".
* gnu/packages/hurd.scm (hurd-rc-script): Move implementation to ... * gnu/build/hurd-boot.scm (boot-hurd-system): ...here, new file. * gnu/build/linux-boot.scm (make-hurd-device-nodes): Move there likewise. * gnu/local.mk (GNU_SYSTEM_MODULES): Add it.
Diffstat (limited to 'gnu/build')
-rw-r--r--gnu/build/hurd-boot.scm202
-rw-r--r--gnu/build/linux-boot.scm48
2 files changed, 203 insertions, 47 deletions
diff --git a/gnu/build/hurd-boot.scm b/gnu/build/hurd-boot.scm
new file mode 100644
index 00000000000..729822dcbd8
--- /dev/null
+++ b/gnu/build/hurd-boot.scm
@@ -0,0 +1,202 @@
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2020 Ludovic Courtès <ludo@gnu.org>
3;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
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 build hurd-boot)
21 #:use-module (system repl error-handling)
22 #:autoload (system repl repl) (start-repl)
23 #:use-module (srfi srfi-1)
24 #:use-module (srfi srfi-26)
25 #:use-module (ice-9 match)
26 #:use-module (guix build utils)
27 #:use-module ((guix build syscalls)
28 #:hide (file-system-type))
29 #:export (make-hurd-device-nodes
30 boot-hurd-system))
31
32;;; Commentary:
33;;;
34;;; Utility procedures useful to boot a Hurd system.
35;;;
36;;; Code:
37
38;; XXX FIXME c&p from linux-boot.scm
39(define (find-long-option option arguments)
40 "Find OPTION among ARGUMENTS, where OPTION is something like \"--load\".
41Return the value associated with OPTION, or #f on failure."
42 (let ((opt (string-append option "=")))
43 (and=> (find (cut string-prefix? opt <>)
44 arguments)
45 (lambda (arg)
46 (substring arg (+ 1 (string-index arg #\=)))))))
47
48;; XXX FIXME c&p from guix/utils.scm
49(define (readlink* file)
50 "Call 'readlink' until the result is not a symlink."
51 (define %max-symlink-depth 50)
52
53 (let loop ((file file)
54 (depth 0))
55 (define (absolute target)
56 (if (absolute-file-name? target)
57 target
58 (string-append (dirname file) "/" target)))
59
60 (if (>= depth %max-symlink-depth)
61 file
62 (call-with-values
63 (lambda ()
64 (catch 'system-error
65 (lambda ()
66 (values #t (readlink file)))
67 (lambda args
68 (let ((errno (system-error-errno args)))
69 (if (or (= errno EINVAL))
70 (values #f file)
71 (apply throw args))))))
72 (lambda (success? target)
73 (if success?
74 (loop (absolute target) (+ depth 1))
75 file))))))
76
77(define* (make-hurd-device-nodes #:optional (root "/"))
78 "Make some of the nodes needed on GNU/Hurd."
79 (define (scope dir)
80 (string-append root (if (string-suffix? "/" root) "" "/") dir))
81
82 (mkdir (scope "dev"))
83 (for-each (lambda (file)
84 (call-with-output-file (scope file)
85 (lambda (port)
86 (display file port) ;avoid hard-linking
87 (chmod port #o666))))
88 '("dev/null"
89 "dev/zero"
90 "dev/full"
91 "dev/random"
92 "dev/urandom"))
93 ;; Don't create /dev/console, /dev/vcs, etc.: they are created by
94 ;; console-run on first boot.
95
96 (mkdir (scope "servers"))
97 (for-each (lambda (file)
98 (call-with-output-file (scope (string-append "servers/" file))
99 (lambda (port)
100 (display file port) ;avoid hard-linking
101 (chmod port #o444))))
102 '("startup"
103 "exec"
104 "proc"
105 "password"
106 "default-pager"
107 "crash-dump-core"
108 "kill"
109 "suspend"))
110
111 (mkdir (scope "servers/socket"))
112 ;; Don't create /servers/socket/1 & co: runsystem does that on first boot.
113
114 ;; TODO: Set the 'gnu.translator' extended attribute for passive translator
115 ;; settings?
116 )
117
118
119(define* (boot-hurd-system #:key (on-error 'debug))
120 "This procedure is meant to be called from an early RC script.
121
122Install the relevant passive translators on the first boot. Then, run system
123activation by using the kernel command-line options '--system' and '--load';
124starting the Shepherd.
125
126XXX TODO: see linux-boot.scm:boot-system.
127XXX TODO: add proper file-system checking, mounting
128XXX TODO: move bits to (new?) (hurd?) (activation?) services
129XXX TODO: use settrans/setxattr instead of MAKEDEV
130
131"
132 (define translators
133 '(("/servers/crash-dump-core" ("/hurd/crash" "--dump-core"))
134 ("/servers/crash-kill" ("/hurd/crash" "--kill"))
135 ("/servers/crash-suspend" ("/hurd/crash" "--suspend"))
136 ("/servers/password" ("/hurd/password"))
137 ("/servers/socket/1" ("/hurd/pflocal"))
138 ("/servers/socket/2" ("/hurd/pfinet" "--interface" "eth0"
139 "--address" "10.0.2.15" ;the default QEMU guest IP
140 "--netmask" "255.255.255.0"
141 "--gateway" "10.0.2.2"
142 "--ipv6" "/servers/socket/16"))))
143
144 (display "Welcome, this is GNU's early boot Guile.\n")
145 (display "Use '--repl' for an initrd REPL.\n\n")
146
147 (call-with-error-handling
148 (lambda ()
149
150 (define (translated? node)
151 ;; Return true if a translator is installed on NODE.
152 (with-output-to-port (%make-void-port "w")
153 (lambda ()
154 (with-error-to-port (%make-void-port "w")
155 (lambda ()
156 (zero? (system* "showtrans" "-s" node)))))))
157
158 (for-each (match-lambda
159 ((node command)
160 (unless (translated? node)
161 (mkdir-p (dirname node))
162 (apply invoke "settrans" "-c" node command))))
163 translators)
164
165 (format #t "Creating essential device nodes...\n")
166 (with-directory-excursion "/dev"
167 (invoke "MAKEDEV" "--devdir=/dev" "std")
168 (invoke "MAKEDEV" "--devdir=/dev" "vcs")
169 (invoke "MAKEDEV" "--devdir=/dev" "tty1""tty2" "tty3" "tty4" "tty5" "tty6")
170 (invoke "MAKEDEV" "--devdir=/dev" "ptyp0" "ptyp1" "ptyp2")
171 (invoke "MAKEDEV" "--devdir=/dev" "console"))
172
173 (let* ((args (command-line))
174 (system (find-long-option "--system" args))
175 (to-load (find-long-option "--load" args)))
176
177 (false-if-exception (delete-file "/hurd"))
178 (let ((hurd/hurd (readlink* (string-append system "/profile/hurd"))))
179 (symlink hurd/hurd "/hurd"))
180
181 (format #t "Starting pager...\n")
182 (unless (zero? (system* "/hurd/mach-defpager"))
183 (format #t "FAILED...Good luck!\n"))
184
185 (cond ((member "--repl" args)
186 (format #t "Starting repl...\n")
187 (start-repl))
188 (to-load
189 (format #t "loading '~a'...\n" to-load)
190 (primitive-load to-load)
191 (format (current-error-port)
192 "boot program '~a' terminated, rebooting~%"
193 to-load)
194 (sleep 2)
195 (reboot))
196 (else
197 (display "no boot file passed via '--load'\n")
198 (display "entering a warm and cozy REPL\n")
199 (start-repl)))))
200 #:on-error on-error))
201
202;;; hurd-boot.scm ends here
diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm
index d62c6706845..80fe0cfb9da 100644
--- a/gnu/build/linux-boot.scm
+++ b/gnu/build/linux-boot.scm
@@ -40,7 +40,6 @@
40 find-long-option 40 find-long-option
41 find-long-options 41 find-long-options
42 make-essential-device-nodes 42 make-essential-device-nodes
43 make-hurd-device-nodes
44 make-static-device-nodes 43 make-static-device-nodes
45 configure-qemu-networking 44 configure-qemu-networking
46 45
@@ -324,51 +323,6 @@ one specific hardware device. These we have to create."
324 ;; File systems in user space (FUSE). 323 ;; File systems in user space (FUSE).
325 (mknod (scope "dev/fuse") 'char-special #o666 (device-number 10 229))) 324 (mknod (scope "dev/fuse") 'char-special #o666 (device-number 10 229)))
326 325
327(define* (make-hurd-device-nodes #:optional (root "/"))
328 "Make some of the nodes needed on GNU/Hurd."
329 (define (scope dir)
330 (string-append root
331 (if (string-suffix? "/" root)
332 ""
333 "/")
334 dir))
335
336 (mkdir (scope "dev"))
337 (for-each (lambda (file)
338 (call-with-output-file (scope file)
339 (lambda (port)
340 (display file port) ;avoid hard-linking
341 (chmod port #o666))))
342 '("dev/null"
343 "dev/zero"
344 "dev/full"
345 "dev/random"
346 "dev/urandom"))
347 ;; Don't create /dev/console, /dev/vcs, etc.: they are created by
348 ;; console-run on first boot.
349
350 (mkdir (scope "servers"))
351 (for-each (lambda (file)
352 (call-with-output-file (scope (string-append "servers/" file))
353 (lambda (port)
354 (display file port) ;avoid hard-linking
355 (chmod port #o444))))
356 '("startup"
357 "exec"
358 "proc"
359 "password"
360 "default-pager"
361 "crash-dump-core"
362 "kill"
363 "suspend"))
364
365 (mkdir (scope "servers/socket"))
366 ;; Don't create /servers/socket/1 & co: runsystem does that on first boot.
367
368 ;; TODO: Set the 'gnu.translator' extended attribute for passive translator
369 ;; settings?
370 )
371
372(define %host-qemu-ipv4-address 326(define %host-qemu-ipv4-address
373 (inet-pton AF_INET "10.0.2.10")) 327 (inet-pton AF_INET "10.0.2.10"))
374 328
@@ -610,4 +564,4 @@ upon error."
610 (start-repl))))) 564 (start-repl)))))
611 #:on-error on-error)) 565 #:on-error on-error))
612 566
613;;; linux-initrd.scm ends here 567;;; linux-boot.scm ends here