Subject: bug#41541: merge wip-hurd-vm

From: Jan Nieuwenhuizen <[email-masked]>
Date: Tue, 02 Jun 2020 15:39:00 +0200

Ludovic Courtès writes:

Hello!

> Jan Nieuwenhuizen <[email-masked]> skribis:
>
>>> Having an RC argument passed directly by the bootloader seems like a
>>> good way to proceed for me. This is somehow remotely similar to what we
>>> are doing with the "initrd" on Linux (pointing to some piece of code
>>> that needs to be loaded before starting the init process).
>>>
>>> You would also need to store this RC argument in the <boot-parameters>
>>> record, by adding a new field or stuffing it in the "initrd"
>>> field. Then, we wouldn't need an extra service I guess.
>>
>> Hmm...I don't understand...probably I'm missing something.
>>
>> I was thinking to just extend boot-parameters with
>> --rc-file=%hurd-rc-script, and then add %hurd-rc-script to the SYSTEM
>> service...How would I get the RC script into SYSTEM without a service?
>
> Normally, if you have the system (as returned by ‘guix system build’),
> that’s enough to derive any other kind of thing you might want.
>
> So for example, you could have a “startup” (or “rc”) entry in the
> ‘system’ directory by extending ‘system-service-type’.  And since the
> system is known from the boot command line, bingo.
>
> The guideline IMO should be to remain as close as possible to Guix
> System on GNU/Linux.  It’s OK to depart a bit from upstream Hurd though
> because those bits are not actually used (Debian does its own thing).

Okay, that makes sense. Using --system=SYSTEM => SYSTEM/rc now.

>>> If we are going that way, the procedures in (gnu build hurd-boot) could
>>> be passed the "hurd" package to install, and we could maybe get rig of
>>> the "/hurd" symlink?
>>
>> Hehe, that would be nice...but IME /hurd isn't easy to get rid of.
>
> Some of the /hurd names are embedded in libc, via the Hurd’s paths.h.
> Some names are compared by string (!); for instance, symlink.c in libc
> has:
>
>   /* A symlink is a file whose translator is "/hurd/symlink\0target\0".  */
>
>   memcpy (buf, _HURD_SYMLINK, sizeof (_HURD_SYMLINK));
>   memcpy (&buf[sizeof (_HURD_SYMLINK)], from, len);
>
> That makes it next to impossible to remove /hurd.
>
> I think it should be treated like /bin/sh and /run/current-system: set
> up at activation time.

Ah right...I think this is exactly what I found (and forgot).  The file
system embeds the full file-name...that's unfortunate.

>> +(define %hurd-rc-script
>> +  ;; The RC script to be started upon boot.
>> +  (program-file "rc"
>> +                (with-imported-modules '((guix build utils)
>> +                                         (gnu build hurd-boot)
>> +                                         (guix build syscalls))
>
> Probably use ‘source-module-closure’ to be on the safe side.

Nice!

>> +(define (hurd-rc-entry mrc)
>> +  "Return, as a monadic value, an entry for the RC script in the system
>> +directory."
>> +  (mlet %store-monad ((rc mrc))
>> +    (return `(("rc" ,rc)))))
>> +
>> +(define hurd-startup-service-type
>> +  ;; The service that creates the initial RC startup file.
>> +  (service-type (name 'startup)
>> +                (extensions
>> +                 (list (service-extension system-service-type hurd-rc-entry)))
>> +                (compose identity)
>> +                (extend (const (lower-object %hurd-rc-script)))
>> +                (description
>> +                 "Produce the operating system's RC script, which is executed
>> +by RUNSYSTEM.")))
>
> Is this service really meant to be extensible?  If not, we could just do:

(no)

>   (service-type (name 'startup)
>                 (extensions
>                  (list (service-extension system-service-type hurd-rc-entry)))
>                 (default-value %hurd-rc-script))
>
> where:
>
>   (define (hurd-rc-entry rc)
>     (mlet %store-monad ((rc (lower-object rc)))
>       (return `(("rc" ,rc)))))

Thanks, done!

>> +  (append
>> +   (if (hurd-target?)
>> +       (list #~(string-append "--rc-file=" #$%hurd-rc-script))
>> +       '())
>> +   (list (string-append "--root="
>> +                        ;; Note: Always use the DCE format because that's what
>> +                        ;; (gnu build linux-boot) expects for the '--root'
>> +                        ;; kernel command-line option.
>> +                        (file-system-device->string root-device
>> +                                                    #:uuid-type 'dce))
>> +         #~(string-append "--system=" #$system)
>> +         #~(string-append "--load=" #$system "/boot"))))
>
> So my suggestion is to avoid --rc-file since you know that SYSTEM/rc
> exists.

Done!

> Ludo’, who jumps in the middle of the discussion.  :-)

Very helpful indeed :-) -- attaching new version (and much tempted to
push to wip-hurd-vm now).

Any more wishes or ideas, things to be done before merging?  Not all
patches were reviewed in their current form, I think.

Janneke

>From 37c2a57d72f5678ec21a48ed4a3b733a20b71ab1 Mon Sep 17 00:00:00 2001
From: "Jan (janneke) Nieuwenhuizen" <[email-masked]>
Date: Thu, 30 Apr 2020 15:40:07 +0200
Subject: [PATCH v2] gnu: services: Add %hurd-startup-service.

This decouples startup of the Hurd from the "hurd" package, moving the RC
script into SYSTEM.

* gnu/packages/hurd.scm (hurd)[inputs]: Remove hurd-rc-script.
[arguments]: Do not substitute it.  Update "runsystem.sh" to parse kernel
arguments and exec into --system=SYSTEM/rc.
(hurd-rc-script): Move to...
* gnu/services.scm (%hurd-rc-file): ...this new variable.
(hurd-rc-entry): New procedure.
(%hurd-startup-service): Use it in new variable.
* gnu/system.scm (hurd-default-essential-services): Use it.
---
 gnu/packages/hurd.scm | 52 ++++++++++---------------------------------
 gnu/services.scm      | 35 +++++++++++++++++++++++++++++
 gnu/system.scm        |  1 +
 3 files changed, 48 insertions(+), 40 deletions(-)

diff --git a/gnu/packages/hurd.scm b/gnu/packages/hurd.scm
index 5de4acb1c5..9dc03c6c9c 100644
--- a/gnu/packages/hurd.scm
+++ b/gnu/packages/hurd.scm
@@ -310,32 +310,6 @@ Hurd-minimal package which are needed for both glibc and GCC.")
      (base32
       "0p2vhnc18cnbmb39vq4m7hzv4mhnm2l0a2s7gx3ar277fwng3hys"))))
 
-(define (hurd-rc-script)
-  "Return a script to be installed as /libexec/rc in the 'hurd' package.  The
-script takes care of installing the relevant passive translators on the first
-boot, since this cannot be done from GNU/Linux.  Then, it runs system
-activation; starting the Shepherd."
-
-  (define rc
-    (with-imported-modules '((guix build utils)
-                             (gnu build hurd-boot)
-                             (guix build syscalls))
-      #~(begin
-          (use-modules (guix build utils)
-                       (gnu build hurd-boot)
-                       (guix build syscalls)
-                       (ice-9 match)
-                       (system repl repl)
-                       (srfi srfi-1)
-                       (srfi srfi-26))
-
-          (boot-hurd-system))))
-
-  ;; FIXME: We want the program to use the cross-compiled Guile when
-  ;; cross-compiling.  But why do we need to be explicit here?
-  (with-parameters ((%current-target-system "i586-pc-gnu"))
-    (program-file "rc" rc)))
-
 (define dde-sources
   ;; This is the current tip of the dde branch
   (let ((commit "ac1c7eb7a8b24b7469bed5365be38a968d59a136"))
@@ -417,11 +391,19 @@ PATH=@PATH@
 fsck --yes --force /
 fsysopts / --writable
 settrans -c /servers/socket/1 /hurd/pflocal
-echo Starting /libexec/rc ...
-exec /libexec/rc \"$@\"
-")))
-             ))
 
+# parse multiboot arguments
+for i in \"$@\"; do
+    case $i in
+        (--system=*)
+            system=${i#--system=}
+            ;;
+    esac
+done
+
+echo Starting ${system}/rc...
+exec ${system}/rc \"$@\"
+")))))
          (add-before 'build 'set-file-names
            (lambda* (#:key inputs outputs #:allow-other-keys)
              (let* ((out  (assoc-ref outputs "out"))
@@ -483,15 +465,6 @@ exec /libexec/rc \"$@\"
                (mkdir-p datadir)
                (copy-file "unifont"
                           (string-append datadir "/vga-system.bdf"))
-               #t)))
-         (add-after 'install 'install-rc-file
-           (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"))
-                    (coreutils (assoc-ref inputs "coreutils")))
-               (delete-file file)
-               (copy-file rc file)
                #t))))
        #:configure-flags (list (string-append "LDFLAGS=-Wl,-rpath="
                                               %output "/lib")
@@ -506,7 +479,6 @@ exec /libexec/rc \"$@\"
     (build-system gnu-build-system)
     (inputs
      `(("glibc-hurd-headers" ,glibc/hurd-headers)
-       ("hurd-rc" ,(hurd-rc-script))
 
        ("libgcrypt" ,libgcrypt)                  ;for /hurd/random
        ("libdaemon" ,libdaemon)                  ;for /bin/console --daemonize
diff --git a/gnu/services.scm b/gnu/services.scm
index 4e0bbc0249..5a04964790 100644
--- a/gnu/services.scm
+++ b/gnu/services.scm
@@ -94,6 +94,8 @@
             activation-service-type
             activation-service->script
             %linux-bare-metal-service
+            %hurd-rc-script
+            %hurd-startup-service
             special-files-service-type
             extra-special-file
             etc-service-type
@@ -630,6 +632,39 @@ ACTIVATION-SCRIPT-TYPE."
                   activation-service-type
                   %linux-kernel-activation))
 
+(define %hurd-rc-script
+  ;; The RC script to be started upon boot.
+  (program-file "rc"
+                (with-imported-modules (source-module-closure
+                                        '((guix build utils)
+                                          (gnu build hurd-boot)
+                                          (guix build syscalls)))
+                  #~(begin
+                      (use-modules (guix build utils)
+                                   (gnu build hurd-boot)
+                                   (guix build syscalls)
+                                   (ice-9 match)
+                                   (system repl repl)
+                                   (srfi srfi-1)
+                                   (srfi srfi-26))
+                      (boot-hurd-system)))))
+
+(define (hurd-rc-entry rc)
+  "Return, as a monadic value, an entry for the RC script in the system
+directory."
+  (mlet %store-monad ((rc (lower-object rc)))
+    (return `(("rc" ,rc)))))
+
+(define hurd-startup-service-type
+  ;; The service that creates the initial SYSTEM/rc startup file.
+  (service-type (name 'startup)
+                (extensions
+                 (list (service-extension system-service-type hurd-rc-entry)))
+                (default-value %hurd-rc-script)))
+
+(define %hurd-startup-service
+  ;; The service that produces the RC script.
+  (service hurd-startup-service-type %hurd-rc-script))
 
 (define special-files-service-type
   ;; Service to install "special files" such as /bin/sh and /usr/bin/env.
diff --git a/gnu/system.scm b/gnu/system.scm
index 41c551af0b..c20f4649f9 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -610,6 +610,7 @@ bookkeeping."
 (define (hurd-default-essential-services os)
   (list (service system-service-type '())
         %boot-service
+        %hurd-startup-service
         %activation-service
         %shepherd-root-service
         (service user-processes-service-type)
-- 
2.26.2

-- 
Jan Nieuwenhuizen <[email-masked]> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com