plover.nix

Branches > main > ee9bf10 > files / nixos / pkgs / plover.nix

{ appimageTools, fetchurl, runCommand, git, runtimeShell }:

let
  pname = "plover";
  version = "5.4.2";
  src = fetchurl {
    url = "https://github.com/openstenoproject/plover/releases/download/v${version}/plover-${version}-x86_64.AppImage";
    hash = "sha256-icM3+C1IQSgaghLKm31Xjr5PYNKF06guMJdEvOLSm8c=";
  };
  extracted = appimageTools.extractType2 { inherit pname version src; };
  ## The udev rule and group live in configuration.nix, the FHS sandbox hides both from AppRun
  ## AppRun's LD_LIBRARY_PATH makes nix git load the bundled (old) libssl, so git gets a clean env
  contents = runCommand "${pname}-${version}-patched" {} ''
    cp -r ${extracted} $out
    chmod -R u+w $out
    substituteInPlace $out/AppRun \
      --replace-fail 'if [ ! -f "$UDEV_RULE_FILE" ] || ! grep -q "^plover:" /etc/group || ! groups | grep -qw "plover"; then' 'if false; then'
    cat > $out/usr/bin/git <<WRAPPER
    #!${runtimeShell}
    unset LD_LIBRARY_PATH LDFLAGS
    exec ${git}/bin/git "\$@"
    WRAPPER
    chmod +x $out/usr/bin/git
  '';
in
appimageTools.wrapAppImage {
  inherit pname version;
  src = contents;
  extraPkgs = pkgs: [ pkgs.xcb-util-cursor ];

  extraInstallCommands = ''
    for f in ${contents}/*.desktop; do
      install -Dm444 "$f" $out/share/applications/plover.desktop
    done
    substituteInPlace $out/share/applications/plover.desktop \
      --replace-quiet 'Exec=AppRun' 'Exec=plover'
    cp -r ${contents}/usr/share/icons $out/share/ 2>/dev/null || true
  '';
}