aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu system keyboard)
  #:use-module (guix gexp)
  #:use-module ((gnu packages xorg)
                #:select (xkeyboard-config console-setup))
  #:use-module (srfi srfi-9 gnu)
  #:use-module (ice-9 match)
  #:export (keyboard-layout?
            keyboard-layout
            keyboard-layout-name
            keyboard-layout-variant
            keyboard-layout-model
            keyboard-layout-options

            keyboard-layout->console-keymap))

;;; Commentary:
;;;
;;; This module provides a data structure to represent keyboard layouts
;;; according to the XKB naming and classification (see the 'xkeyboard-config'
;;; package).
;;;
;;; Code:

(define-immutable-record-type <keyboard-layout>
  (%keyboard-layout name variant model options)
  keyboard-layout?
  (name      keyboard-layout-name)                ;string
  (variant   keyboard-layout-variant)             ;#f | string
  (model     keyboard-layout-model)               ;#f | string
  (options   keyboard-layout-options))            ;list of strings

(define* (keyboard-layout name #:optional variant
                          #:key model (options '()))
  "Return a new keyboard layout with the given NAME and VARIANT.

NAME must be a string such as \"fr\"; VARIANT must be a string such as
\"bepo\" or \"nodeadkeys\".  See the 'xkeyboard-config' package for valid
options."
  (%keyboard-layout name variant model options))

(define* (keyboard-layout->console-keymap layout
                                          #:key
                                          (xkeyboard-config xkeyboard-config))
  "Return a Linux console keymap file for LAYOUT, a <keyboard-layout> record.
Layout information is taken from the XKEYBOARD-CONFIG package."
  (define build
    (with-imported-modules '((guix build utils))
      #~(begin
          (use-modules (guix build utils)
                       (ice-9 popen)
                       (ice-9 match))

          (define pipe
            (open-pipe* OPEN_READ
                        #+(file-append console-setup "/bin/ckbcomp")
                        (string-append "-I"
                                       #+(file-append xkeyboard-config
                                                      "/share/X11/xkb"))
                        "-rules" "base"
                        #$@(match (keyboard-layout-model layout)
                             (#f      '())
                             (model   `("-model" ,model)))
                        #$(keyboard-layout-name layout)
                        #$(or (keyboard-layout-variant layout)
                              "")
                        #$(string-join (keyboard-layout-options layout) ",")))

          (call-with-output-file #$output
            (lambda (output)
              (dump-port pipe output)))

          ;; Note: ckbcomp errors out when the layout name is unknown, but
          ;; merely emits a warning when the variant is unknown.
          (unless (zero? (close-pipe pipe))
            (error "failed to create console keymap for keyboard layout"
                   #$(keyboard-layout-name layout))))))

  (computed-file (string-append "console-keymap."
                                (string-map (match-lambda
                                              (#\, #\-)
                                              (chr chr))
                                            (keyboard-layout-name layout)))
                 build))
'>...Efraim Flashner 2024-01-14mapped-devices: Allow unlocking by a key file....Tomas Volf 2024-01-08system: hurd: Use the Shepherd 0.10.x....Ludovic Courtès 2024-01-08scripts: system: Build layered images....Oleg Pykhalov 2023-12-30gnu: vm-image.tmpl: Improve SPICE dynamic resizing....Maxim Cournoyer 2023-12-22images: Add orangepi-r1-plus-lts image....Herman Rimm 2023-12-10file-systems: Add tracefs to %pseudo-file-system-types....Leo Nikkilä 2023-12-02gnu: Use ‘libc-utf8-locales-for-target’....Janneke Nieuwenhuizen 2023-10-29system: vm: Include the cirrus driver in the initrd....Tobias Geerinckx-Rice 2023-10-30gnu: file-systems: Add xenfs to %pseudo-file-system-types....Skyler Ferris 2023-10-06system: Modify bash skeleton to colorize 'ip' output....Bruno Victal 2023-10-05system: bare-bones: Add comments about nss-cert and NTP service....Nikolaos Chatzikonstantinou 2023-10-05Revert "system: accounts: Export <user-account>."...Ludovic Courtès 2023-10-01system: vm: Remove unused variable....Ludovic Courtès 2023-10-01image: Product hybrid qcow2 images....Mathieu Othacehe 2023-09-20image: Do not allow BIOS bootloader and GPT....Mathieu Othacehe 2023-09-20image: Introduce the mbr-hybrid-raw image type....Mathieu Othacehe 2023-09-17gnu: file-systems: Add variable %base-live-file-systems....Nicolas Graves 2023-09-16system: hurd: Override locale-libcs harder....Janneke Nieuwenhuizen 2023-09-16system: hurd: Add nss-certs to %base-packages/hurd....Janneke Nieuwenhuizen 2023-09-16system: hurd: Add procps to %base-packages/hurd....Janneke Nieuwenhuizen 2023-09-16locale: Set %default-locale-definitions to glibc/hurd on the Hurd....Janneke Nieuwenhuizen 2023-09-11system: vm-image: Remove duplicate packages....Efraim Flashner 2023-08-20Revert "gnu: system: Add home-directory-permissions field to <user-account>."...Tobias Geerinckx-Rice 2023-08-25gnu: system: Add home-directory-permissions field to <user-account>....David Thompson 2023-08-25image: Add mbr-raw-image-type and use by default....Josselin Poiret 2023-08-22examples: Avoid duplicate SDDM service for Plasma on aarch64-linux....Ludovic Courtès 2023-08-21examples: Avoid 'modify-services' to remove GDM....Ludovic Courtès 2023-08-11Merge remote-tracking branch 'origin/master' into kde-updates宋文武 2023-08-03examples: Add plasma operating-system example template....Zheng Junjie 2023-08-08file-systems: Use cgroups v2....Sam Lockart 2023-07-26system: accounts: Export <user-account>.Maxim Cournoyer 2023-07-13system: hurd: Add netdde to %base-packages/hurd....Janneke Nieuwenhuizen 2023-07-13services: childhurd: Bump default qemu memory to 2048MB....Janneke Nieuwenhuizen 2023-07-07image: Prefer gpt partition table for efi images...Sergey Trofimov