From 5612630ea4324339322ba726846d1962aaa86dc8 Mon Sep 17 00:00:00 2001 From: nee Date: Sat, 5 Jan 2019 22:07:30 +0100 Subject: [PATCH] bootloader: grub custom keyboard-layout, but luks password prompts are still unaffected --- gnu/bootloader/grub.scm | 128 +++++++++++++++++++++++------------ gnu/packages/bootloaders.scm | 11 +++ gnu/packages/xorg.scm | 121 +++++++++++++++++++++++++++++++++ 3 files changed, 215 insertions(+), 45 deletions(-) diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm index 161e8b3d0..ca9f2f565 100644 --- a/gnu/bootloader/grub.scm +++ b/gnu/bootloader/grub.scm @@ -29,6 +29,7 @@ #:use-module (gnu system file-systems) #:autoload (gnu packages bootloaders) (grub) #:autoload (gnu packages gtk) (guile-cairo guile-rsvg) + #:autoload (gnu packages xorg) (xkeyboard-config) #:use-module (ice-9 match) #:use-module (ice-9 regex) #:use-module (srfi srfi-1) @@ -46,6 +47,8 @@ %background-image %default-theme + grub-keyboard-layout-file + grub-bootloader grub-efi-bootloader grub-mkrescue-bootloader @@ -219,11 +222,35 @@ fi~%" ;;; Configuration file. ;;; +(define* (grub-keyboard-layout-file + #:key + (layout #f) ; something like "fr" "de" "ru" + (grub grub) + (xkeyboard-config xkeyboard-config)) + "Returns a Gexp that generates a xkb keyboard LAYOUT file that GRUB can load. +The LAYOUT must be present in XKEYBOARD-CONFIGs share/X11xkb/symbols/ directory. +When LAYOUT is #f no file will be generated and 'no-keymap-used is +returned in a gexp." + (define builder + #~(zero? + (system* (string-append #$grub "/bin/grub-kbdcomp") + (string-append #$xkeyboard-config + "/share/X11/xkb/symbols/" #$layout) + (string-append "-I" #$xkeyboard-config + "/share/X11/xkb") + "-rules" "base" + "-o" #$output))) + + (if layout + (computed-file "keyboard-layout.xkb" builder) + (gexp 'no-keymap-used))) + + (define (grub-setup-io config) "Return GRUB commands to configure the input / output interfaces. The result is a string that can be inserted in grub.cfg." (let* ((symbols->string (lambda (list) - (string-join (map symbol->string list) " "))) + (string-join (map symbol->string list) " "))) (outputs (bootloader-configuration-terminal-outputs config)) (inputs (bootloader-configuration-terminal-inputs config)) (unit (bootloader-configuration-serial-unit config)) @@ -233,41 +260,41 @@ is a string that can be inserted in grub.cfg." ;; as documented in GRUB manual section "Simple Configuration ;; Handling". (valid-outputs '(console serial serial_0 serial_1 serial_2 serial_3 - gfxterm vga_text mda_text morse spkmodem)) + gfxterm vga_text mda_text morse spkmodem)) (valid-inputs '(console serial serial_0 serial_1 serial_2 serial_3 - at_keyboard usb_keyboard)) + at_keyboard usb_keyboard)) (io (string-append - "terminal_output " - (symbols->string - (map - (lambda (output) - (if (memq output valid-outputs) output #f)) outputs)) "\n" - (if (null? inputs) - "" - (string-append - "terminal_input " - (symbols->string - (map - (lambda (input) - (if (memq input valid-inputs) input #f)) inputs)) "\n")) - ;; UNIT and SPEED are arguments to the same GRUB command - ;; ("serial"), so we process them together. - (if (or unit speed) - (string-append - "serial" - (if unit - ;; COM ports 1 through 4 - (if (and (exact-integer? unit) (<= unit 3) (>= unit 0)) - (string-append " --unit=" (number->string unit)) - #f) - "") - (if speed - (if (exact-integer? speed) - (string-append " --speed=" (number->string speed)) - #f) - "")) - "")))) + "terminal_output " + (symbols->string + (map + (lambda (output) + (if (memq output valid-outputs) output #f)) outputs)) "\n" + (if (null? inputs) + "" + (string-append + "terminal_input " + (symbols->string + (map + (lambda (input) + (if (memq input valid-inputs) input #f)) inputs)) "\n")) + ;; UNIT and SPEED are arguments to the same GRUB command + ;; ("serial"), so we process them together. + (if (or unit speed) + (string-append + "serial" + (if unit + ;; COM ports 1 through 4 + (if (and (exact-integer? unit) (<= unit 3) (>= unit 0)) + (string-append " --unit=" (number->string unit)) + #f) + "") + (if speed + (if (exact-integer? speed) + (string-append " --speed=" (number->string speed)) + #f) + "")) + "")))) (format #f "~a" io))) (define (grub-root-search device file) @@ -293,6 +320,8 @@ code." (define* (grub-configuration-file config entries #:key + (keyboard-layout-file + (grub-keyboard-layout-file)) (system (%current-system)) (old-entries '())) "Return the GRUB configuration file corresponding to CONFIG, a @@ -329,6 +358,14 @@ entries corresponding to old generations of the system." (menu-entry-device-mount-point (first all-entries)) #:system system #:port #~port)) + (define keyboard-layout-config + #~(let ((keymap #$keyboard-layout-file)) + (if (eq? 'no-keymap-used keymap) + (format port "") + (format port "terminal_input at_keyboard +insmod keylayouts +keymap ~a +" keymap)))) (define builder #~(call-with-output-file #$output @@ -338,6 +375,7 @@ entries corresponding to old generations of the system." # will be lost upon reconfiguration. ") #$sugar + #$keyboard-layout-config (format port " set default=~a set timeout=~a~%" @@ -426,17 +464,17 @@ submenu \"GNU system, old configurations...\" {~%") (define-syntax grub-configuration (syntax-rules (grub) - ((_ (grub package) fields ...) - (if (eq? package grub) - (bootloader-configuration - (bootloader grub-bootloader) - fields ...) - (bootloader-configuration - (bootloader grub-efi-bootloader) - fields ...))) - ((_ fields ...) - (bootloader-configuration - (bootloader grub-bootloader) - fields ...)))) + ((_ (grub package) fields ...) + (if (eq? package grub) + (bootloader-configuration + (bootloader grub-bootloader) + fields ...) + (bootloader-configuration + (bootloader grub-efi-bootloader) + fields ...))) + ((_ fields ...) + (bootloader-configuration + (bootloader grub-bootloader) + fields ...)))) ;;; grub.scm ends here diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm index 2a595fafa..3cc331dcb 100644 --- a/gnu/packages/bootloaders.scm +++ b/gnu/packages/bootloaders.scm @@ -55,6 +55,7 @@ #:use-module (gnu packages swig) #:use-module (gnu packages valgrind) #:use-module (gnu packages virtualization) + #:use-module (gnu packages xorg) #:use-module (gnu packages web) #:use-module (guix build-system gnu) #:use-module (guix download) @@ -110,6 +111,12 @@ ;; Make the font visible. (copy-file (assoc-ref inputs "unifont") "unifont.bdf.gz") (system* "gunzip" "unifont.bdf.gz") + + ;; patch the path to ckbcomp + (substitute* "util/grub-kbdcomp.in" + (("^ckbcomp ") + (string-append (assoc-ref inputs "console-setup") + "/bin/ckbcomp "))) #t)) (add-before 'check 'disable-flaky-test (lambda _ @@ -134,6 +141,10 @@ ;; to determine whether the root file system is RAID. ("mdadm" ,mdadm) + ;; console-setup's ckbcomp is invoked by grub-kbdcomp + ;; it is required for generating alternative keyboard layouts + ("console-setup" ,console-setup) + ("freetype" ,freetype) ;; ("libusb" ,libusb) ;; ("fuse" ,fuse) diff --git a/gnu/packages/xorg.scm b/gnu/packages/xorg.scm index 9aa65291b..0a95a21cf 100644 --- a/gnu/packages/xorg.scm +++ b/gnu/packages/xorg.scm @@ -46,6 +46,7 @@ #:use-module (gnu packages) #:use-module (gnu packages anthy) #:use-module (gnu packages autotools) + #:use-module (gnu packages base) #:use-module (gnu packages bison) #:use-module (gnu packages check) #:use-module (gnu packages compression) @@ -6258,3 +6259,123 @@ selecting windows by pointing select actual focused X11 window, selecting by window name or id, forcing toggle, increase or decrease opacity.") (home-page "http://forchheimer.se/transset-df/") (license license:x11))) + +(define-public bdfresize + (package + (name "bdfresize") + (version "1.5-11") + (source + (origin + (method url-fetch) + (uri (string-append "https://salsa.debian.org/debian/bdfresize/-/archive/debian/" + version "/bdfresize-debian-"version ".tar.bz2")) + (sha256 + (base32 + "1fcn0hhzk8g3h0x50n982jwgsivhkqfd50bqs3iv2db3j4bnxp51")))) + (build-system gnu-build-system) + (arguments + '(;; #:make-flags + ;; (let ((bash (assoc-ref %build-inputs "bash")) + ;; (out (assoc-ref %outputs "out"))) + ;; (list (string-append "SHELL=" bash "/bin/bash") + ;; ;; (string-append "prefix=" out) + ;; )) + #:phases + (modify-phases %standard-phases + (replace 'configure + (lambda* (#:key build configure-flags outputs inputs + #:allow-other-keys #:rest args) + (let ((out (assoc-ref outputs "out"))) + ;; The default configure tries to pass + ;; SHELL=/gnu/store/…-bash-minimal-4.4.23/bin/bash + ;; This breaks the configure script with: + ;; "error: can only configure for one host and one target at a time" + (setenv "CONFIG_SHELL" + (string-append (assoc-ref %build-inputs "bash") + "/bin/bash")) + (zero? (system* "./configure" + + "--build" build + "--prefix" out))))) + (add-after 'configure 'fix-for-new-gcc + ;; TODO might upstream, once upstream is back + (lambda _ + (substitute* "charresize.c" + (("char\t\\*malloc\\(\\);") + "")) + #t))))) + (native-inputs + `(("pkg-config" ,pkg-config))) + (inputs `(("perl" ,perl))) + (synopsis "") + (description "") + ;; latest upstream vanished, using debian fork for now + ;; used to be: http://openlab.jp/efont/ + (home-page "https://tracker.debian.org/pkg/bdfresize") + (license license:x11)) ) + +(define-public console-setup + (package + (name "console-setup") + (version "1.188") + (source + (origin + (method url-fetch) + (uri (string-append "https://salsa.debian.org/installer-team/console-setup/-/archive/" + version "/console-setup-" version ".tar.bz2")) + (sha256 + (base32 + "1v6zfnsp1fakv1q8b68wdjjxscpw2sbmw2fpqw5af4b3isha5sgr")))) + (build-system gnu-build-system) + (arguments + '(#:make-flags + (let ((bash (assoc-ref %build-inputs "bash")) + (out (assoc-ref %outputs "out"))) + (list (string-append "SHELL=" bash "/bin/bash") + ;; (string-append "prefix=" out) + )) + #:phases + (modify-phases %standard-phases + (delete 'configure) + (add-before 'build 'make-doubled-bdfs + (lambda* (#:key inputs #:allow-other-keys) + (with-directory-excursion "Fonts" + (zero? (system* (string-append (assoc-ref inputs "make") + "/bin/make") + "doubled_bdfs" + (string-append "SHELL=" + (assoc-ref inputs "bash") + "/bin/bash")))))) + (delete 'check) + (replace 'install + (lambda* (#:key inputs outputs #:allow-other-keys) + (let ((out (assoc-ref %outputs "out"))) + (zero? (system* (string-append (assoc-ref inputs "make") + "/bin/make") + "install-linux" + (string-append "prefix=" out) + (string-append "SHELL=" + (assoc-ref inputs "bash") + "/bin/bash"))))))))) + (native-inputs + `(("pkg-config" ,pkg-config) + ;; ("bash" ,bash) + ("bdftopcf" ,bdftopcf) + ("bdfresize" ,bdfresize) + ("sharutils" ,sharutils) + ("make" ,gnu-make) + )) + (inputs `(("perl" ,perl))) + (synopsis "") + (description "console-setup provides the console with the same +keyboard configuration scheme that X Window System has. +In result, there is no need to duplicate or change the console keyboard +files just to make simple customizations such as the use of dead keys, +the key functioning as AltGr or Compose key, the key(s) to switch between +Latin and non-Latin layouts, etc. Besides the keyboard, +the package configures also the font on the console. +It includes a rich collection of fonts and supports several languages that + would be otherwise unsupported on the console (such as Armenian, Georgian, + Lao and Thai).") + (home-page "https://salsa.debian.org/installer-team/console-setup/") + (license license:x11))) -- 2.20.1