nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 fetchFromGitHub,
4 runCommand,
5 stdenv,
6 testers,
7
8 keymap-drawer,
9 yamllint,
10}:
11let
12 runKeymapDrawer =
13 name:
14 runCommand "keymap-drawer-${name}" {
15 nativeBuildInputs = [ keymap-drawer ];
16 };
17
18 MattSturgeon-example = fetchFromGitHub {
19 owner = "MattSturgeon";
20 repo = "glove80-config";
21 rev = "d55267dd26593037256b35a5d6ebba0f75541da5";
22 hash = "sha256-MV6cNpgHBuaGvpu2aR1aBNMpwPnDqOSbGf+2ykxocP4=";
23 nonConeMode = true;
24 sparseCheckout = [
25 "config"
26 "img"
27 ];
28 };
29
30 # MattSturgeon's example requires MDI icons
31 mdi = fetchFromGitHub {
32 owner = "Templarian";
33 repo = "MaterialDesign-SVG";
34 tag = "v7.4.47";
35 hash = "sha256-NoSSRT1ID38MT70IZ+7h/gMVCNsjNs3A2RX6ePGwuQ0=";
36 };
37in
38{
39 dump-config = runKeymapDrawer "dump-config" ''
40 keymap dump-config --output "$out"
41
42 if [ ! -s "$out" ]; then
43 >&2 echo 'Expected `dump-config` to have content.'
44 exit 1
45 fi
46
47 ${lib.getExe yamllint} --strict --config-data relaxed "$out"
48 '';
49
50 parse-zmk = testers.testEqualContents {
51 assertion = "keymap parse --zmk-keymap produces expected YAML";
52 expected = "${MattSturgeon-example}/img/glove80.yaml";
53 actual = runKeymapDrawer "parse" ''
54 keymap \
55 --config ${MattSturgeon-example}/config/keymap_drawer.yaml \
56 parse --zmk-keymap ${MattSturgeon-example}/config/glove80.keymap \
57 --output "$out"
58 '';
59 checkMetadata = stdenv.buildPlatform.isLinux;
60 };
61
62 draw = testers.testEqualContents {
63 assertion = "keymap draw produces expected SVG";
64 expected = "${MattSturgeon-example}/img/glove80.svg";
65 actual = runKeymapDrawer "draw" ''
66 ${lib.optionalString stdenv.buildPlatform.isLinux ''
67 export XDG_CACHE_HOME="$PWD/cache"
68 glyphs="$XDG_CACHE_HOME/keymap-drawer/glyphs"
69 ''}
70 ${lib.optionalString stdenv.buildPlatform.isDarwin ''
71 export HOME="$PWD/home"
72 glyphs="$HOME/Library/Caches/keymap-drawer/glyphs"
73 ''}
74 mkdir -p "$glyphs"
75
76 # Unpack MDI icons into the cache
77 for file in ${mdi}/svg/*
78 do
79 ln -s "$file" "$glyphs/mdi:$(basename "$file")"
80 done
81
82 keymap \
83 --config ${MattSturgeon-example}/config/keymap_drawer.yaml \
84 draw ${MattSturgeon-example}/img/glove80.yaml \
85 --output "$out"
86 '';
87 checkMetadata = stdenv.buildPlatform.isLinux;
88 };
89}