From 87a52da7d0da82bd8df9c86dcac7029c375b50c0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
Date: Fri, 16 May 2014 23:31:48 +0200
Subject: [PATCH] linux-initrd: Factorize kernel command-line option parsing.

* guix/build/linux-initrd.scm (find-long-option): New procedure.
  (boot-system): Use it instead of the local 'option'.
---
 guix/build/linux-initrd.scm | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/guix/build/linux-initrd.scm b/guix/build/linux-initrd.scm
index a89ff86bbb2..9093e726950 100644
--- a/guix/build/linux-initrd.scm
+++ b/guix/build/linux-initrd.scm
@@ -28,6 +28,7 @@ (define-module (guix build linux-initrd)
   #:use-module (guix build utils)
   #:export (mount-essential-file-systems
             linux-command-line
+            find-long-option
             make-essential-device-nodes
             configure-qemu-networking
             check-file-system
@@ -78,6 +79,15 @@ (define (linux-command-line)
    (call-with-input-file "/proc/cmdline"
      get-string-all)))
 
+(define (find-long-option option arguments)
+  "Find OPTION among ARGUMENTS, where OPTION is something like \"--load\".
+Return the value associated with OPTION, or #f on failure."
+  (let ((opt (string-append option "=")))
+    (and=> (find (cut string-prefix? opt <>)
+                 arguments)
+           (lambda (arg)
+             (substring arg (+ 1 (string-index arg #\=)))))))
+
 (define* (make-essential-device-nodes #:key (root "/"))
   "Make essential device nodes under ROOT/dev."
   ;; The hand-made udev!
@@ -411,14 +421,8 @@ (define root-fs-type
 
   (mount-essential-file-systems)
   (let* ((args    (linux-command-line))
-         (option  (lambda (opt)
-                    (let ((opt (string-append opt "=")))
-                      (and=> (find (cut string-prefix? opt <>)
-                                   args)
-                             (lambda (arg)
-                               (substring arg (+ 1 (string-index arg #\=))))))))
-         (to-load (option "--load"))
-         (root    (option "--root")))
+         (to-load (find-long-option "--load" args))
+         (root    (find-long-option "--root" args)))
 
     (when (member "--repl" args)
       (start-repl))
-- 
GitLab