Skip to content

Commit

Permalink
[nixos] fix crash on file browsing in uhk-agent adding/fixing gtk3
Browse files Browse the repository at this point in the history
Prompts with file selector (used when reading or writing config file
to disk) would crash uhk-agent because `$XDG_DATA_DIRS` wasn't set
correctly.

Changed from using `appimage-run` to `appimageTools`. I read a post
where the author of the former called it a quick hack, others
discourage using it, and encourage the latter instead. Also I found a
working example with the latter :-)
  • Loading branch information
kidmose committed Jun 17, 2020
1 parent 1865cb2 commit f39f4bb
Showing 1 changed file with 63 additions and 30 deletions.
93 changes: 63 additions & 30 deletions nixos/apps/uhk.nix
@@ -1,44 +1,77 @@
# https://github.com/garbas/dotfiles/blob/76f9da7c5d84b1595e8b9af31505bb13968ba7a4/nixos/grayworm.nix#L63
# https://www.reddit.com/r/NixOS/comments/f98mou/buildfhsuserenvappimage_recipe_for_gtk_programs/

{ config, lib, pkgs, ... }:

let
custom_pkgs = self: super: {

uhk-agent =
# version >1.3.0 causes it to hang on launch ("Loading configuration. Hang on")
let
version = "1.3.0";
image = self.stdenv.mkDerivation {
name = "uhk-agent-image";
src = self.fetchurl {
url = "https://github.com/UltimateHackingKeyboard/agent/releases/download/v${version}/UHK.Agent-${version}-linux-x86_64.AppImage";
# sha256 = "1gr3q37ldixcqbwpxchhldlfjf7wcygxvnv6ff9nl7l8gxm732l6"; # 1.2.12 - good
sha256 = "09k09yn0iyivc9hf283cxrcrcyswgg2jslc85k4dwvp1pc6bpp07"; # 1.3.0 - good
# sha256 = "0inps9q6f6cmlnl3knmfm2mmgqb5frl4ghxplbzvas7kmrd2wg4k"; # 1.3.1 - bad
# sha256 = "1y2n2kkkkqsqxw7rsya7qxh8m5nh0n93axcssi54srp3h7040w3h"; # 1.3.2 - bad
# sha256 = "1y6gy3zlj0pkvydby7ibm7hx83lmc3vs2m0bfww5dq1114j99dy5"; # 1.4.0 - bad
};
buildCommand = ''
mkdir -p $out
cp $src $out/appimage
chmod ugo+rx $out/appimage
'';
name = "uhk-agent-${version}";
version = "1.3.0"; # version >1.3.0 causes it to hang on launch ("Loading configuration. Hang on")
src = builtins.fetchurl {
url = "https://github.com/UltimateHackingKeyboard/agent/releases/download/v${version}/UHK.Agent-${version}-linux-x86_64.AppImage";
sha256 = {
# I've tested the following releases, noting in the
# comment which works for me (Lenovo thinkpad t450s in
# dock - which might complicate things)
"1.2.12" = "1gr3q37ldixcqbwpxchhldlfjf7wcygxvnv6ff9nl7l8gxm732l6"; # good
"1.3.0" = "09k09yn0iyivc9hf283cxrcrcyswgg2jslc85k4dwvp1pc6bpp07"; # good
"1.3.1" = "0inps9q6f6cmlnl3knmfm2mmgqb5frl4ghxplbzvas7kmrd2wg4k"; # bad
"1.3.2" = "1y2n2kkkkqsqxw7rsya7qxh8m5nh0n93axcssi54srp3h7040w3h"; # bad
"1.4.0" = "1y6gy3zlj0pkvydby7ibm7hx83lmc3vs2m0bfww5dq1114j99dy5"; # bad
}."${version}";
};
in self.runCommand "uhk-agent" {} ''
mkdir -p $out/bin $out/etc/udev/rules.d
echo "${self.appimage-run}/bin/appimage-run ${image}/appimage" > $out/bin/uhk-agent
chmod +x $out/bin/uhk-agent
cat > $out/etc/udev/rules.d/50-uhk60.rules <<EOF
# Ultimate Hacking Keyboard rules
# These are the udev rules for accessing the USB interfaces of the UHK as non-root users.
# Copy this file to /etc/udev/rules.d and physically reconnect the UHK afterwards.
SUBSYSTEM=="input", GROUP="input", MODE="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="612[0-7]", MODE:="0666", GROUP="plugdev"
KERNEL=="hidraw*", ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="612[0-7]", MODE="0666", GROUP="plugdev"
EOF
'';

xdg_dirs = builtins.concatStringsSep ":" [
"${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}"
];

# not necessary, here for debugging purposes
# adapted from the original runScript of appimageTools
extracted_source = pkgs.appimageTools.extractType2 { inherit name src; };
debugScript = pkgs.writeScript "run" ''
#!${pkgs.stdenv.shell}
export APPDIR=${extracted_source}
export APPIMAGE_SILENT_INSTALL=1
# >>> inspect the script running environment here <<<
echo "INSPECT: ''${GIO_EXTRA_MODULES:-no extra modules!}"
echo "INSPECT: ''${GSETTINGS_SCHEMA_DIR:-no schemas!}"
echo "INSPECT: ''${XDG_DATA_DIRS:-no data dirs!}"
cd $APPDIR
exec ./AppRun "$@"
'';
in pkgs.appimageTools.wrapType2 {
inherit name src;

# for debugging purposes only
# runScript = debugScript;

extraPkgs = pkgs: with pkgs; [
# put runtime dependencies if any here
];

extraInstallCommands = ''
ln -s "$out/bin/${name}" "$out/bin/uhk-agent";
mkdir -p $out/etc/udev/rules.d
cat > $out/etc/udev/rules.d/50-uhk60.rules <<EOF
# Ultimate Hacking Keyboard rules
# These are the udev rules for accessing the USB interfaces of the UHK as non-root users.
# Copy this file to /etc/udev/rules.d and physically reconnect the UHK afterwards.
SUBSYSTEM=="input", GROUP="input", MODE="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="612[0-7]", MODE:="0666", GROUP="plugdev"
KERNEL=="hidraw*", ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="612[0-7]", MODE="0666", GROUP="plugdev"
EOF
'';
profile = ''
export XDG_DATA_DIRS="${xdg_dirs}''${XDG_DATA_DIRS:+:}"
export APPIMAGE=''${APPIMAGE-""} # Kill a seemingly useless error message
'';
};
};
in
{
Expand Down

0 comments on commit f39f4bb

Please sign in to comment.