{ lib, stdenv, writeText, mappings ? [] }: stdenv.mkDerivation rec { name = "intcp-mapper"; src = writeText "intcp-mapper.c" '' #include #include #include int main(void) { setbuf(stdin, NULL), setbuf(stdout, NULL); struct input_event event; while (fread(&event, sizeof(event), 1, stdin) == 1) { /* Example if (event.type == EV_KEY && event.code == KEY_X) { event.code = KEY_Y; } */ if (event.type == EV_KEY) { ${ lib.concatStrings (map (m: '' if (event.code == ${m.from}) { event.code = ${m.to}; } '') mappings) } } fwrite(&event, sizeof(event), 1, stdout); }; } ''; dontUnpack = true; buildPhase = '' cat $src gcc $src -o mapper ''; installPhase = '' mkdir -p $out/bin install -m 555 mapper $out/bin/mapper ''; }