kanata: added update script darwinDriverVersion

This commit is contained in:
Ivy Pierlot
2025-09-25 10:40:11 +10:00
parent fdd5c16358
commit 8dfe5d494e
2 changed files with 34 additions and 8 deletions

View File

@@ -1,20 +1,24 @@
{
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 (finalAttrs: {
pname = "kanata";
version = "1.9.0";
darwinDriverVersion = "5.0.0"; # needs to be updated if karabiner-driverkit changes
src = fetchFromGitHub {
owner = "jtroo";
@@ -48,12 +52,26 @@ rustPlatform.buildRustPackage (finalAttrs: {
];
passthru = {
updateScript = nix-update-script { };
darwinDriver = lib.optional stdenv.hostPlatform.isDarwin (
karabiner-dk.override {
driver-version = finalAttrs.darwinDriverVersion;
}
);
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; {

View File

@@ -0,0 +1,8 @@
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\"|"