Skip to content

Instantly share code, notes, and snippets.

@ftrvxmtrx
Last active May 22, 2024 16:50
Show Gist options
  • Save ftrvxmtrx/95beaabb6faa3d815713bd3b339d438f to your computer and use it in GitHub Desktop.
Save ftrvxmtrx/95beaabb6faa3d815713bd3b339d438f to your computer and use it in GitHub Desktop.
VueScan for NixOS
{ stdenv
, lib
, gawk
, fetchurl
, gnutar
, autoPatchelfHook
, glibc
, gtk2
, xorg
, libgudev
, undmg
, makeDesktopItem
, epkowa
, buildFHSEnv
, writeScript
}:
let
inherit (stdenv.hostPlatform) system;
throwSystem = throw "Unsupported system: ${system}";
pname = "vuescan";
version = "9.8.33";
desktopItem = makeDesktopItem {
name = "VueScan";
desktopName = "VueScan";
genericName = "Scanning Program";
comment = "Scanning Program";
icon = "vuescan";
terminal = false;
type = "Application";
startupNotify = true;
categories = [ "Graphics" "Utility" ];
keywords = [ "scan" "scanner" ];
exec = "vuescan";
};
# Minor versions are released using the same file name
versionItems = builtins.splitVersion version;
versionString = (builtins.elemAt versionItems 0) + (builtins.elemAt versionItems 1);
src = let
base = "https://www.hamrick.com/files/";
in {
x86_64-linux = fetchurl {
url = "${base}/vuex64${versionString}.tgz";
sha256 = "sha256-INaNs6tES9aGyilmI3LmfDOwOCPeYPW7u+jCqYi1qo4=";
};
}.${system} or throwSystem;
meta = with lib; {
description = "Scanner software supporting a wide range of devices";
homepage = "https://hamrick.com/";
license = licenses.unfree;
maintainers = with maintainers; [ ftrvxmtrx ];
platforms = [
"x86_64-linux"
];
};
vuescan = stdenv.mkDerivation rec {
inherit pname version src meta;
# Stripping the binary breaks the license form
dontStrip = true;
nativeBuildInputs = [
gawk
gnutar
autoPatchelfHook
];
buildInputs = [
glibc
gtk2
xorg.libSM
libgudev
];
preferLocalBuild = true;
unpackPhase = ''
tar xfz $src
'';
patchPhase = ''
# replace "/opt/iscan" -> "/tmp/iscan"
printf '/tmp/iscan' | dd of=VueScan/vuescan bs=1 seek=17467012 conv=notrunc
'';
installPhase = ''
install -m755 -D VueScan/vuescan $out/bin/vuescan
mkdir -p $out/share/icons/hicolor/scalable/apps/
cp VueScan/vuescan.svg $out/share/icons/hicolor/scalable/apps/vuescan.svg
mkdir -p $out/lib/udev/rules.d/
cp VueScan/vuescan.rul $out/lib/udev/rules.d/60-vuescan.rules
mkdir -p $out/share/applications/
ln -s ${desktopItem}/share/applications/* $out/share/applications
'';
};
in
buildFHSEnv rec {
name = "vuescan";
passthru = {
inherit pname version meta;
};
targetPkgs = pkgs: [
epkowa
vuescan
];
extraBwrapArgs = [
"--tmpfs /tmp"
"--dir /tmp/iscan"
];
runScript = writeScript "${name}-wrapper" ''
set -e
cat ${epkowa}/var/lib/iscan/interpreter | \
while read -r _ _ _ _ so bin;
do
ln -sf $so.so $bin /tmp/iscan/
done
ISCAN_FW_DIR=/tmp/iscan exec vuescan $@
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment