Subject: [PATCH] Allow customised xkeyboard-config package in initrd

From: Maxime Devos <[email-masked]>
Date: Tue, 05 Jan 2021 22:37:06 +0100

Hi Guix!

This patch *should* allow using a custom xkeyboard-config
package the initrd. (moesasji was interested in such a thing
on January the fourth on #guix)
‘make check’ doesn't give any error messages. However, I don't
have any custom xkeyboard-config package to test this with,
so I'll leave that to interested people.
-- 
Maxime Devos <[email-masked]>
PGP Key: C1F3 3EE2 0C52 8FDB 7DD7  011F 49E3 EE22 1917 25EE
Freenode handle: mdevos
From 85d509121b95d4da7048b045d41d57a2e71efc8f Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Tue, 5 Jan 2021 22:20:42 +0100
Subject: [PATCH] gnu: Allow custom xkeyboard-config package in initrd

* gnu/system/linux-initrd.scm (raw-initrd): New argument xkeyboard-config.
* gnu/system/linux-initrd.scm (base-initrd): Likewise.
* doc/contributing.texi (raw-initrd): Document new argument.
* doc/contributing.texi (base-initrd): Likewise.
---
 doc/guix.texi               | 13 ++++++++++---
 gnu/system/linux-initrd.scm | 17 +++++++++++++++--
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 1081ed26a3..e410ccb141 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -86,6 +86,7 @@ Copyright @copyright{} 2020 raingloom@*
 Copyright @copyright{} 2020 Daniel Brooks@*
 Copyright @copyright{} 2020 John Soo@*
 Copyright @copyright{} 2020 Jonathan Brielmaier@*
+Copyright @copyright{} 2021 Maxime Devos@*
 
 Permission is granted to copy, distribute and/or modify this document
 under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -30631,7 +30632,7 @@ here is how to use it and customize it further.
 @cindex initial RAM disk
 @deffn {Scheme Procedure} raw-initrd @var{file-systems} @
        [#:linux-modules '()] [#:mapped-devices '()] @
-       [#:keyboard-layout #f] @
+       [#:keyboard-layout #f] [#:xkeyboard-config xkeyboard-config] @
        [#:helper-packages '()] [#:qemu-networking? #f] [#:volatile-root? #f]
 Return a derivation that builds a raw initrd.  @var{file-systems} is
 a list of file systems to be mounted by the initrd, possibly in addition to
@@ -30649,6 +30650,9 @@ are set up and before @var{file-systems} are mounted such that, should the
 user need to enter a passphrase or use the REPL, this happens using the
 intended keyboard layout.
 
+When @var{xkeyboard-config} is set, it is the @code{xkeyboard-config} package
+where @var{keyboard-layout} will be searched for.
+
 When @var{qemu-networking?} is true, set up networking with the standard QEMU
 parameters.  When @var{virtio?} is true, load additional modules so that the
 initrd can be used as a QEMU guest with para-virtualized I/O drivers.
@@ -30659,8 +30663,8 @@ to it are lost.
 
 @deffn {Scheme Procedure} base-initrd @var{file-systems} @
        [#:mapped-devices '()] [#:keyboard-layout #f] @
-       [#:qemu-networking? #f] [#:volatile-root? #f] @
-       [#:linux-modules '()]
+       [#:xkeyboard-config xkeyboard-config] [#:qemu-networking? #f] @
+       [#:volatile-root? #f] [#:linux-modules '()]
 Return as a file-like object a generic initrd, with kernel
 modules taken from @var{linux}.  @var{file-systems} is a list of file-systems to be
 mounted by the initrd, possibly in addition to the root file system specified
@@ -30673,6 +30677,9 @@ are set up and before @var{file-systems} are mounted such that, should the
 user need to enter a passphrase or use the REPL, this happens using the
 intended keyboard layout.
 
+When @var{xkeyboard-config} is set, it is the @code{xkeyboard-config} package
+where @var{keyboard-layout} will be searched for.
+
 @var{qemu-networking?} and @var{volatile-root?} behaves as in @code{raw-initrd}.
 
 The initrd is automatically populated with all the kernel modules necessary
diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm
index c6ba9bb560..64305e5fa6 100644
--- a/gnu/system/linux-initrd.scm
+++ b/gnu/system/linux-initrd.scm
@@ -4,6 +4,7 @@
 ;;; Copyright © 2016 Jan Nieuwenhuizen <[email-masked]>
 ;;; Copyright © 2017, 2019 Mathieu Othacehe <[email-masked]>
 ;;; Copyright © 2019, 2020 Tobias Geerinckx-Rice <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -175,6 +176,7 @@ MODULES and taken from LINUX."
                       (mapped-devices '())
                       (keyboard-layout #f)
                       (helper-packages '())
+                      (xkeyboard-config xkeyboard-config)
                       qemu-networking?
                       volatile-root?
                       (on-error 'debug))
@@ -192,6 +194,9 @@ console keyboard layout.  This is done before MAPPED-DEVICES are set up and
 before FILE-SYSTEMS are mounted such that, should the user need to enter a
 passphrase or use the REPL, this happens using the intended keyboard layout.
 
+When XKEYBOARD-CONFIG is set, it is the xkeyboard-config package where
+the KEYBOARD-LAYOUT will be searched for.
+
 When QEMU-NETWORKING? is true, set up networking with the standard QEMU
 parameters.
 
@@ -213,6 +218,10 @@ upon error."
   (define kodir
     (flat-linux-module-directory linux linux-modules))
 
+  (define keymap-file
+    (and keyboard-layout
+         (keyboard-layout->console-keymap
+          keyboard-layout #:xkeyboard-config xkeyboard-config)))
   (expression->initrd
    (with-imported-modules (source-module-closure
                            '((gnu build linux-boot)
@@ -248,8 +257,7 @@ upon error."
                                       (and #$@device-mapping-commands))
                         #:linux-modules '#$linux-modules
                         #:linux-module-directory '#$kodir
-                        #:keymap-file #+(and=> keyboard-layout
-                                               keyboard-layout->console-keymap)
+                        #:keymap-file #+keymap-file
                         #:qemu-guest-networking? #$qemu-networking?
                         #:volatile-root? '#$volatile-root?
                         #:on-error '#$on-error))))
@@ -349,6 +357,7 @@ FILE-SYSTEMS."
                       (linux linux-libre)
                       (linux-modules '())
                       (mapped-devices '())
+                      (xkeyboard-config xkeyboard-config)
                       (keyboard-layout #f)
                       qemu-networking?
                       volatile-root?
@@ -365,6 +374,9 @@ console keyboard layout.  This is done before MAPPED-DEVICES are set up and
 before FILE-SYSTEMS are mounted such that, should the user need to enter a
 passphrase or use the REPL, this happens using the intended keyboard layout.
 
+When XKEYBOARD-CONFIG is set, it is the xkeyboard-config package where
+the KEYBOARD-LAYOUT will be searched for.
+
 QEMU-NETWORKING? and VOLATILE-ROOT? behaves as in raw-initrd.
 
 The initrd is automatically populated with all the kernel modules necessary
@@ -392,6 +404,7 @@ loaded at boot time in the order in which they appear."
               #:linux-modules linux-modules*
               #:mapped-devices mapped-devices
               #:helper-packages helper-packages
+              #:xkeyboard-config xkeyboard-config
               #:keyboard-layout keyboard-layout
               #:qemu-networking? qemu-networking?
               #:volatile-root? volatile-root?
-- 
2.29.2