lol
1{ lib, stdenv, fetchurl, cpio, xar, undmg }:
2
3stdenv.mkDerivation rec {
4 pname = "karabiner-elements";
5 version = "14.11.0";
6
7 src = fetchurl {
8 url = "https://github.com/pqrs-org/Karabiner-Elements/releases/download/v${version}/Karabiner-Elements-${version}.dmg";
9 sha256 = "sha256-InuSfXbaSYsncq8jVO15LbQmDTguRHlOiE/Pj5EfX5c=";
10 };
11
12 outputs = [ "out" "driver" ];
13
14 nativeBuildInputs = [ cpio xar undmg ];
15
16 unpackPhase = ''
17 undmg $src
18 xar -xf Karabiner-Elements.pkg
19 cd Installer.pkg
20 zcat Payload | cpio -i
21 cd ../Karabiner-DriverKit-VirtualHIDDevice.pkg
22 zcat Payload | cpio -i
23 cd ..
24 '';
25
26 sourceRoot = ".";
27
28 postPatch = ''
29 for f in *.pkg/Library/Launch{Agents,Daemons}/*.plist; do
30 substituteInPlace $f \
31 --replace "/Library/" "$out/Library/"
32 done
33 '';
34
35 installPhase = ''
36 mkdir -p $out $driver
37 cp -R Installer.pkg/Applications Installer.pkg/Library $out
38 cp -R Karabiner-DriverKit-VirtualHIDDevice.pkg/Applications Karabiner-DriverKit-VirtualHIDDevice.pkg/Library $driver
39
40 cp "$out/Library/Application Support/org.pqrs/Karabiner-Elements/package-version" "$out/Library/Application Support/org.pqrs/Karabiner-Elements/version"
41 '';
42
43 passthru.updateScript = ./updater.sh;
44
45 meta = with lib; {
46 description = "Karabiner-Elements is a powerful utility for keyboard customization on macOS Sierra (10.12) or later.";
47 homepage = "https://karabiner-elements.pqrs.org/";
48 platforms = platforms.darwin;
49 maintainers = with maintainers; [ Enzime ];
50 license = licenses.unlicense;
51 };
52}