1{ lib
2, stdenv
3, fetchurl
4, nixosTests
5, autoreconfHook
6, pkg-config
7, flex
8, check
9, pam
10, coreutils
11, gzip
12, bzip2
13, xz
14, zstd
15, gitUpdater
16}:
17
18stdenv.mkDerivation rec {
19 pname = "kbd";
20 version = "2.6.3";
21
22 src = fetchurl {
23 url = "mirror://kernel/linux/utils/kbd/${pname}-${version}.tar.xz";
24 sha256 = "sha256-BJlsCNfRxGCWb7JEo9OIM1LCZ0t61SIAPZ9Oy4q0jes=";
25 };
26
27 # vlock is moved into its own output, since it depends on pam. This
28 # reduces closure size for most use cases.
29 outputs = [ "out" "vlock" "dev" ];
30
31 configureFlags = [
32 "--enable-optional-progs"
33 "--enable-libkeymap"
34 "--disable-nls"
35 ];
36
37 patches = [
38 ./search-paths.patch
39 ];
40
41 postPatch =
42 ''
43 # Renaming keymaps with name clashes, because loadkeys just picks
44 # the first keymap it sees. The clashing names lead to e.g.
45 # "loadkeys no" defaulting to a norwegian dvorak map instead of
46 # the much more common qwerty one.
47 pushd data/keymaps/i386
48 mv qwertz/cz{,-qwertz}.map
49 mv olpc/es{,-olpc}.map
50 mv olpc/pt{,-olpc}.map
51 mv fgGIod/trf{,-fgGIod}.map
52 mv colemak/{en-latin9,colemak}.map
53 popd
54
55 # Fix paths to decompressors. Trailing space to avoid replacing `xz` in `".xz"`.
56 substituteInPlace src/libkbdfile/kbdfile.c \
57 --replace 'gzip ' '${gzip}/bin/gzip ' \
58 --replace 'bzip2 ' '${bzip2.bin}/bin/bzip2 ' \
59 --replace 'xz ' '${xz.bin}/bin/xz ' \
60 --replace 'zstd ' '${zstd.bin}/bin/zstd '
61
62 sed -i '
63 1i prefix:=$(vlock)
64 1i bindir := $(vlock)/bin' \
65 src/vlock/Makefile.in \
66 src/vlock/Makefile.am
67 '';
68
69 postInstall = ''
70 for i in $out/bin/unicode_{start,stop}; do
71 substituteInPlace "$i" \
72 --replace /usr/bin/tty ${coreutils}/bin/tty
73 done
74 '';
75
76 buildInputs = [ check pam ];
77 NIX_LDFLAGS = lib.optional stdenv.hostPlatform.isStatic "-laudit";
78 nativeBuildInputs = [ autoreconfHook pkg-config flex ];
79
80 passthru.tests = {
81 inherit (nixosTests) keymap kbd-setfont-decompress kbd-update-search-paths-patch;
82 };
83 passthru = {
84 gzip = gzip;
85 updateScript = gitUpdater {
86 # No nicer place to find latest release.
87 url = "https://github.com/legionus/kbd.git";
88 rev-prefix = "v";
89 };
90 };
91
92 meta = with lib; {
93 homepage = "https://kbd-project.org/";
94 description = "Linux keyboard tools and keyboard maps";
95 platforms = platforms.linux;
96 license = licenses.gpl2Plus;
97 maintainers = with maintainers; [ davidak ];
98 };
99}