From ae1e3d4601eaca91cdd10230ed210e817a236148 Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Tue, 7 Nov 2023 10:27:49 -0500 Subject: [PATCH] uhk-agent: use electron from nixpkgs --- pkgs/os-specific/linux/uhk-agent/default.nix | 58 +++++++++++++++---- .../linux/uhk-udev-rules/default.nix | 2 +- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/pkgs/os-specific/linux/uhk-agent/default.nix b/pkgs/os-specific/linux/uhk-agent/default.nix index dfc43cba01c2..9ce8c102c25a 100644 --- a/pkgs/os-specific/linux/uhk-agent/default.nix +++ b/pkgs/os-specific/linux/uhk-agent/default.nix @@ -1,7 +1,18 @@ -{ appimageTools, lib, fetchurl }: +{ lib +, stdenvNoCC +, fetchurl +, appimageTools +, electron +, makeWrapper +, asar +, autoPatchelfHook +, libusb1 +}: + let pname = "uhk-agent"; version = "3.1.0"; + src = fetchurl { url = "https://github.com/UltimateHackingKeyboard/agent/releases/download/v${version}/UHK.Agent-${version}-linux-x86_64.AppImage"; name = "${pname}-${version}.AppImage"; @@ -12,22 +23,45 @@ let name = "${pname}-${version}"; inherit src; }; -in appimageTools.wrapType2 { +in +stdenvNoCC.mkDerivation { inherit pname version src; - extraPkgs = pkgs: with pkgs; [ polkit udev ]; + dontUnpack = true; - extraInstallCommands = '' - mv $out/bin/${pname}-${version} $out/bin/${pname} + nativeBuildInputs = [ + asar + makeWrapper + autoPatchelfHook + ]; - install -m 444 -D ${appimageContents}/${pname}.desktop -t $out/share/applications - install -m 644 -D ${appimageContents}/resources/rules/50-uhk60.rules $out/rules/50-uhk60.rules - substituteInPlace $out/share/applications/${pname}.desktop \ - --replace 'Exec=AppRun' 'Exec=${pname}' - cp -r ${appimageContents}/usr/share/icons $out/share + buildInputs = [ + libusb1 + ]; + + installPhase = '' + runHook preInstall + + mkdir -p "$out"/{opt,share/applications} + + cp -r --no-preserve=mode "${appimageContents}/resources" "$out/opt/${pname}" + cp -r --no-preserve=mode "${appimageContents}/usr/share/icons" "$out/share/icons" + cp -r --no-preserve=mode "${appimageContents}/${pname}.desktop" "$out/share/applications/${pname}.desktop" + + substituteInPlace "$out/share/applications/${pname}.desktop" \ + --replace "Exec=AppRun" "Exec=${pname}" + + asar extract "$out/opt/${pname}/app.asar" "$out/opt/${pname}/app.asar.unpacked" + rm "$out/opt/${pname}/app.asar" + + makeWrapper "${electron}/bin/electron" "$out/bin/${pname}" \ + --add-flags "$out/opt/${pname}/app.asar.unpacked" \ + --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \ + --set-default ELECTRON_IS_DEV 0 \ + --inherit-argv0 + + runHook postInstall ''; - # wrapType2 does not passthru pname+version - passthru.version = version; meta = with lib; { description = "Agent is the configuration application of the Ultimate Hacking Keyboard"; diff --git a/pkgs/os-specific/linux/uhk-udev-rules/default.nix b/pkgs/os-specific/linux/uhk-udev-rules/default.nix index bcb7799731f6..1b68c46b6571 100644 --- a/pkgs/os-specific/linux/uhk-udev-rules/default.nix +++ b/pkgs/os-specific/linux/uhk-udev-rules/default.nix @@ -8,7 +8,7 @@ stdenv.mkDerivation { dontBuild = true; installPhase = '' runHook preInstall - install -D -m 644 ${uhk-agent.out}/rules/50-uhk60.rules $out/lib/udev/rules.d/50-uhk60.rules + install -D -m 644 ${uhk-agent.out}/opt/uhk-agent/rules/50-uhk60.rules $out/lib/udev/rules.d/50-uhk60.rules runHook postInstall '';