1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (gnu system keyboard)
20 #:use-module (guix gexp)
21 #:use-module ((gnu packages xorg)
22 #:select (xkeyboard-config console-setup))
23 #:use-module (srfi srfi-9 gnu)
24 #:use-module (ice-9 match)
25 #:export (keyboard-layout?
28 keyboard-layout-variant
30 keyboard-layout-options
32 keyboard-layout->console-keymap))
36 ;;; This module provides a data structure to represent keyboard layouts
37 ;;; according to the XKB naming and classification (see the 'xkeyboard-config'
42 (define-immutable-record-type <keyboard-layout>
43 (%keyboard-layout name variant model options)
45 (name keyboard-layout-name) ;string
46 (variant keyboard-layout-variant) ;#f | string
47 (model keyboard-layout-model) ;#f | string
48 (options keyboard-layout-options)) ;list of strings
50 (define* (keyboard-layout name #:optional variant
51 #:key model (options '()))
52 "Return a new keyboard layout with the given NAME and VARIANT.
54 NAME must be a string such as \"fr\"; VARIANT must be a string such as
55 \"bepo\" or \"nodeadkeys\". See the 'xkeyboard-config' package for valid
57 (%keyboard-layout name variant model options))
59 (define* (keyboard-layout->console-keymap layout
61 (xkeyboard-config xkeyboard-config))
62 "Return a Linux console keymap file for LAYOUT, a <keyboard-layout> record.
63 Layout information is taken from the XKEYBOARD-CONFIG package."
65 (with-imported-modules '((guix build utils))
67 (use-modules (guix build utils)
73 #+(file-append console-setup "/bin/ckbcomp")
75 #+(file-append xkeyboard-config
78 #$@(match (keyboard-layout-model layout)
80 (model `("-model" ,model)))
81 #$(keyboard-layout-name layout)
82 #$(or (keyboard-layout-variant layout)
84 #$(string-join (keyboard-layout-options layout) ",")))
86 (call-with-output-file #$output
88 (dump-port pipe output)))
90 ;; Note: ckbcomp errors out when the layout name is unknown, but
91 ;; merely emits a warning when the variant is unknown.
92 (unless (zero? (close-pipe pipe))
93 (error "failed to create console keymap for keyboard layout"
94 #$(keyboard-layout-name layout))))))
96 (computed-file (string-append "console-keymap."
97 (keyboard-layout-name layout))