janneke pushed a commit to branch wip-hurd-vm in repository guix. commit 804cb778fda379d22d47b17243d1797ed0eb2ed6 Author: Jan (janneke) Nieuwenhuizen <jann...@gnu.org> AuthorDate: Wed May 6 08:22:41 2020 +0200
gnu: hurd: Create minimal "runsystem" script to invoke "rc". * gnu/packages/hurd.scm (hurd-rc-script): Update to handle "runsystem" tasks. (hurd)[arguments]: Add 'create-runsystem' phase. Do not substitute now unused init.c, runsystem.hurd. --- gnu/packages/hurd.scm | 125 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 90 insertions(+), 35 deletions(-) diff --git a/gnu/packages/hurd.scm b/gnu/packages/hurd.scm index 55c4071..6f77499 100644 --- a/gnu/packages/hurd.scm +++ b/gnu/packages/hurd.scm @@ -331,8 +331,8 @@ boot, since this cannot be done from GNU/Linux." (use-modules (guix build utils) (ice-9 match)) - ;; "@HURD@" is a placeholder. - (setenv "PATH" "@HURD@/bin") + ;; "@HURD@" and "@COREUTILS@" are a placeholders. + (setenv "PATH" "@HURD@/bin:@HURD@/sbin:@COREUTILS@/bin") (define (translated? node) ;; Return true if a translator is installed on NODE. @@ -342,6 +342,15 @@ boot, since this cannot be done from GNU/Linux." (lambda () (zero? (system* "showtrans" "-s" node))))))) + (format #t "Setting / writable...\n") + (unless (zero? (system* "fsysopts" "/" "--update" "--writable")) + (format #t "FAILED...Good luck!\n")) + + (format #t "settrans pflocal...\n") + (mkdir-p "/servers/socket") + (unless (zero? (system* "settrans" "-c" "/servers/socket/1" "/hurd/pflocal")) + (format #t "FAILED...Good luck!\n")) + (for-each (match-lambda ((node command) (unless (translated? node) @@ -349,10 +358,55 @@ boot, since this cannot be done from GNU/Linux." (apply invoke "settrans" "-c" node command)))) '#$translators) - ;; Start the oh-so-fancy console client. - (mkdir-p "/var/run") ;for the PID file - (invoke "console" "--daemonize" "-c" "/dev/vcs" - "-d" "vga" "-d" "pc_kbd" "-d" "generic_speaker")))) + (format #t "Creating essential device nodes...\n") + (with-directory-excursion "/dev" + (invoke "MAKEDEV" "--devdir=/dev" "std") + (invoke "MAKEDEV" "--devdir=/dev" "vcs") + (invoke "MAKEDEV" "--devdir=/dev" "tty1""tty2" "tty3" "tty4" "tty5" "tty6") + (invoke "MAKEDEV" "--devdir=/dev" "ptyp0" "ptyp1" "ptyp2") + (invoke "MAKEDEV" "--devdir=/dev" "std") + (invoke "MAKEDEV" "--devdir=/dev" "console")) + + ;; Setting current system + (unless (file-exists? "/run/current-system/profile") + (format #t "Setting current system...\n") + (mkdir-p "/run/current-system") + (let ((profiles (find-files "/gnu/store" + (lambda (name stat) + (and (string-suffix? "-profile" name) + (eq? 'directory (stat:type stat)))) + #:directories? #t))) + (when (> (length profiles) 1) + (format #t "Too many profiles found...choosing first!\n")) + (if (null? profiles) + (format #t "No profiles found...Good luck!\n") + (symlink (car profiles) "/run/current-system/profile")))) + + ;; Start console? + (system* "/run/current-system/profile/bin/bash" "-c" "echo 1>/dev/console") + + (format #t "Starting pager...\n") + (unless (zero? (system* "/hurd/mach-defpager")) + (format #t "FAILED...Good luck!\n")) + + ;; XXX Activate the system + (format #t "Activating system...\n") + ;; XXX (primitive-load "/boot/activation") + (invoke "/run/current-system/profile/bin/bash" "/boot/activation") + ;; Hand over to the Shepherd + (let ((shepherd.conf + (if (file-exists? "/etc/shepherd.conf") + "/etc/shepherd.conf" + (let ((files (find-files "/gnu/store" ".*-shepherd.conf"))) + (and (pair? files) (car files)))))) + (unless shepherd.conf + (format #t "No shepherd.conf found, dropping to a shell...\n") + (invoke "/run/current-system/profile/bin/bash") + (reboot)) + (false-if-exception (delete-file "/var/run/shepherd/socket")) + (format #t "Starting the Shepherd... ~a\n" shepherd.conf) + (execl "/run/current-system/profile/bin/shepherd" "shepherd" + "--config" shepherd.conf))))) ;; FIXME: We want the program to use the cross-compiled Guile when ;; cross-compiling. But why do we need to be explicit here? @@ -424,19 +478,38 @@ boot, since this cannot be done from GNU/Linux." (substitute* '("daemons/Makefile" "utils/Makefile") (("-o root -m 4755") "")) #t)) + (add-after 'unpack 'create-runsystem + (lambda _ + ;; XXX Work towards having startup.c invoke the Guile rc + (delete-file "daemons/runsystem.sh") + (with-output-to-file "daemons/runsystem.sh" + (lambda _ + (display "#! /bin/bash + +# XXX Guile needs pipe support for its finalizer thread, to start. +# Remove this script when Linux and the Hurd have xattr patches. +PATH=@PATH@ + +fsck --yes --force / +fsysopts / --writable +settrans -c /servers/socket/1 /hurd/pflocal +echo Starting /libexec/rc ... +exec /libexec/rc +"))) + )) + (add-before 'build 'set-file-names (lambda* (#:key inputs outputs #:allow-other-keys) (let* ((out (assoc-ref outputs "out")) (bash (assoc-ref inputs "bash-minimal")) (coreutils (assoc-ref inputs "coreutils")) (sed (assoc-ref inputs "sed")) - (grep (assoc-ref inputs "grep")) (util-linux (assoc-ref inputs "util-linux"))) (substitute* '("daemons/runttys.c" "daemons/getty.c" "utils/login.c") (("/bin/login") (string-append out "/bin/login")) (("/bin/bash") (string-append bash "/bin/bash"))) - (substitute* '("startup/startup.c" "init/init.c" "config/ttys") + (substitute* '("startup/startup.c" "config/ttys") (("/libexec/") (string-append out "/libexec/"))) (substitute* '("utils/uptime.sh") @@ -445,36 +518,17 @@ boot, since this cannot be done from GNU/Linux." (substitute* "daemons/console-run.c" (("/hurd/") (string-append out "/hurd/"))) - (substitute* '("daemons/runsystem.sh" - "daemons/runsystem.hurd.sh" "sutils/MAKEDEV.sh") (("^PATH=.*") - (string-append "PATH=" out "/bin:" out "/sbin:" - coreutils "/bin:" - sed "/bin:" grep "/bin:" - util-linux "/bin\n")) - (("^SHELL=.*") - (string-append "SHELL=" bash "/bin/bash\n")) + (string-append "PATH=" out "/bin" + ":" out "/sbin" + ":" coreutils "/bin" + ":" sed "/bin" + ":" util-linux "/sbin\n")) (("/sbin/") (string-append out "/sbin/")) (("/libexec/") (string-append out "/libexec/")) (("/hurd/") (string-append out "/hurd/"))) - - (substitute* "daemons/runsystem.sh" - (("export PATH") - (string-append "export PATH\n" - "\ -fsysopts / --writable - -# MAKEDEV relies on pipes so this needs to be set up. -settrans -c /servers/socket/1 /hurd/pflocal - -(cd /dev; MAKEDEV -D /dev std vcs tty{1,2,3,4,5,6})\n"))) - - (substitute* "daemons/runsystem.hurd.sh" - (("export PATH") - "export PATH -fsysopts / --writable\n")) #t))) (add-after 'patch-shebangs 'patch-libexec-shebangs (lambda* (#:key inputs outputs #:allow-other-keys) @@ -510,11 +564,13 @@ fsysopts / --writable\n")) (lambda* (#:key inputs outputs #:allow-other-keys) (let* ((out (assoc-ref outputs "out")) (file (string-append out "/libexec/rc")) - (rc (assoc-ref inputs "hurd-rc"))) + (rc (assoc-ref inputs "hurd-rc")) + (coreutils (assoc-ref inputs "coreutils"))) (delete-file file) (copy-file rc file) (substitute* file - (("@HURD@") out)) + (("@HURD@") out) + (("@COREUTILS@") coreutils)) #t)))) #:configure-flags (list (string-append "LDFLAGS=-Wl,-rpath=" %output "/lib") @@ -543,7 +599,6 @@ fsysopts / --writable\n")) ("bash-minimal" ,bash-minimal) ("coreutils" ,coreutils) ("sed" ,sed) - ("grep" ,grep) ("util-linux" ,util-linux))) (native-inputs `(("autoconf" ,autoconf)