Unverified Commit a13ff3e2 authored by Fernando Rodrigues's avatar Fernando Rodrigues Committed by GitHub
Browse files

karabiner-elements: fix notarization for drivers, karabiner-dk: init at 6.2.0,...

karabiner-elements: fix notarization for drivers, karabiner-dk: init at 6.2.0, kanata: Fix darwin drivers based on karabiner-elements, haskellPackages.kmonad: add output for darwinDriver (#445407)
parents 1e18cf3a 2db6f4e8
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -2482,6 +2482,12 @@
    githubId = 574938;
    name = "Jonathan Glines";
  };
  auscyber = {
    email = "ivyp@outlook.com.au";
    github = "auscyber";
    name = "Ivy Pierlot";
    githubId = 12080502;
  };
  austin-artificial = {
    email = "austin.platt@artificial.io";
    github = "austin-artificial";
+34 −6
Original line number Diff line number Diff line
{
  stdenv,
  lib,
  gnused,
  apple-sdk_13,
  darwinMinVersionHook,
  rustPlatform,
  karabiner-dk,
  fetchFromGitHub,
  versionCheckHook,
  nix-update-script,
  common-updater-scripts,
  yq,
  curl,
  jq,
  writeShellApplication,
  writeShellScriptBin,
  withCmd ? false,
}:
rustPlatform.buildRustPackage rec {
rustPlatform.buildRustPackage (finalAttrs: {
  pname = "kanata";
  version = "1.9.0";

  src = fetchFromGitHub {
    owner = "jtroo";
    repo = "kanata";
    rev = "v${version}";
    rev = "v${finalAttrs.version}";
    sha256 = "sha256-xxAIwiwCQugDXpWga9bQ9ZGfem46rwDlmf64dX/tw7g=";
  };

@@ -46,15 +52,37 @@ rustPlatform.buildRustPackage rec {
  ];

  passthru = {
    updateScript = nix-update-script { };
    darwinDriverVersion = "5.0.0"; # needs to be updated if karabiner-driverkit changes
    updateScript = lib.getExe (writeShellApplication {
      name = "update-script-kanata";
      runtimeInputs = [
        curl
        gnused
        yq
        jq
        common-updater-scripts
      ];
      text = builtins.readFile ./update.sh;
    });

    darwinDriver =
      if stdenv.hostPlatform.isDarwin then
        (karabiner-dk.override {
          driver-version = finalAttrs.passthru.darwinDriverVersion;
        })
      else
        null;
  };

  meta = with lib; {
    description = "Tool to improve keyboard comfort and usability with advanced customization";
    homepage = "https://github.com/jtroo/kanata";
    license = licenses.lgpl3Only;
    maintainers = with maintainers; [ linj ];
    maintainers = with maintainers; [
      linj
      auscyber
    ];
    platforms = platforms.unix;
    mainProgram = "kanata";
  };
}
})
+8 −0
Original line number Diff line number Diff line
NEW_VERSION="$(curl --silent https://api.github.com/repos/jtroo/kanata/releases/latest  ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""}  | jq '.tag_name | ltrimstr("v")' --raw-output)"
update-source-version "kanata" "$NEW_VERSION" --ignore-same-version
karabinerDriverCrateVersion="$(curl -L "https://raw.githubusercontent.com/jtroo/kanata/refs/tags/v$NEW_VERSION/Cargo.lock" | tomlq | jq --raw-output '.package[] | select(.name |  test("karabiner-driverkit")) |.version')"
newKarabinerDkVersion="$(curl -L "https://crates.io/api/v1/crates/karabiner-driverkit/$karabinerDriverCrateVersion/download" | tar xzvf - --strip-components=1 -O "karabiner-driverkit-$karabinerDriverCrateVersion/c_src/Karabiner-DriverKit-VirtualHIDDevice/version.json" | jq --raw-output0 .package_version)"
importTree="(let tree = import ./.; in if builtins.isFunction tree then tree {} else tree)"
oldDarwinVersion=$(nix-instantiate --eval -E "with $importTree; kanata.passthru.darwinDriverVersion" | tr -d '"')
nixFile=$(nix-instantiate --eval --strict -A "kanata.meta.position" | sed -re 's/^"(.*):[0-9]+"$/\1/')
sed -i "$nixFile" -re "s|\"$oldDarwinVersion\"|\"$newKarabinerDkVersion\"|"
+59 −0
Original line number Diff line number Diff line
{
  libarchive,
  xar,
  lib,
  stdenv,
  fetchFromGitHub,
  common-updater-scripts,
  writeShellScript,
  curl,
  jq,
  driver-version ? null,
}:
stdenv.mkDerivation (finalAttrs: {
  pname = "karabiner-dk";
  sourceVersion = "6.3.0";
  version = lib.defaultTo finalAttrs.sourceVersion driver-version;

  src = fetchFromGitHub {
    owner = "pqrs-org";
    repo = "Karabiner-DriverKit-VirtualHIDDevice";
    tag = "v${finalAttrs.sourceVersion}";
    hash = "sha256-nLu//qG3RzrEDWvNmSJH7YmgVgiTiYTg5FaliiEtdpo=";
  };

  nativeBuildInputs = [
    libarchive
    xar
  ];

  unpackPhase = ''
    runHook preUnpack
    xar -xf $src/dist/Karabiner-DriverKit-VirtualHIDDevice-${finalAttrs.version}.pkg
    zcat Payload | bsdcpio -i
    runHook postUnpack
  '';

  installPhase = ''
    runHook preInstall
    mkdir -p $out
    cp -R ./Applications ./Library $out
    runHook postInstall
  '';
  dontFixup = true;

  passthru.updateScript = writeShellScript "karabiner-dk" ''
    NEW_VERSION=$(${lib.getExe curl} --silent https://api.github.com/repos/pqrs-org/Karabiner-DriverKit-VirtualHIDDevice/releases/latest $${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} | ${lib.getExe jq} '.tag_name | ltrimstr("v")' --raw-output)
    ${lib.getExe' common-updater-scripts "update-source-version"} "karabiner-dk" "$NEW_VERSION" --ignore-same-version --version-key="sourceVersion";
  '';

  meta = {
    changelog = "https://github.com/pqrs-org/Karabiner-DriverKit-VirtualHIDDevice/releases/tag/${finalAttrs.src.tag}";
    description = "Virtual keyboard and virtual mouse using DriverKit on macOS";
    homepage = "https://karabiner-elements.pqrs.org/";
    maintainers = with lib.maintainers; [ auscyber ];
    license = lib.licenses.unlicense;
    platforms = lib.platforms.darwin;
    sourceProvenance = [ lib.sourceTypes.binaryNativeCode ];
  };
})
+9 −5
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
  lib,
  stdenv,
  fetchurl,
  cpio,
  libarchive,
  xar,
  undmg,
  nix-update-script,
@@ -23,7 +23,7 @@ stdenv.mkDerivation (finalAttrs: {
  ];

  nativeBuildInputs = [
    cpio
    libarchive
    xar
    undmg
  ];
@@ -32,9 +32,9 @@ stdenv.mkDerivation (finalAttrs: {
    undmg $src
    xar -xf Karabiner-Elements.pkg
    cd Installer.pkg
    zcat Payload | cpio -i
    zcat Payload | bsdcpio -i
    cd ../Karabiner-DriverKit-VirtualHIDDevice.pkg
    zcat Payload | cpio -i
    zcat Payload | bsdcpio -i
    cd ..
  '';

@@ -49,13 +49,17 @@ stdenv.mkDerivation (finalAttrs: {
  '';

  installPhase = ''
    runHook preInstall
    mkdir -p $out $driver
    cp -R Installer.pkg/Applications Installer.pkg/Library $out
    cp -R Karabiner-DriverKit-VirtualHIDDevice.pkg/Applications Karabiner-DriverKit-VirtualHIDDevice.pkg/Library $driver

    cp "$out/Library/Application Support/org.pqrs/Karabiner-Elements/package-version" "$out/Library/Application Support/org.pqrs/Karabiner-Elements/version"
    runHook postInstall
  '';

  dontFixup = true; # notarization breaks if fixup is enabled

  passthru.updateScript = nix-update-script { };

  meta = {
@@ -63,7 +67,7 @@ stdenv.mkDerivation (finalAttrs: {
    description = "Powerful utility for keyboard customization on macOS Ventura (13) or later";
    homepage = "https://karabiner-elements.pqrs.org/";
    license = lib.licenses.unlicense;
    maintainers = [ ];
    maintainers = with lib.maintainers; [ auscyber ];
    platforms = lib.platforms.darwin;
  };
})
Loading