From dd366aa20eeb2b01de8f52795b7c78757066ef5b Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Mon, 9 Mar 2026 02:33:10 -0600 Subject: [PATCH] trivionomicon: athena-bccr: patch hard-coded FHS paths in idopte driver --- modules/athena-bccr/sys.nix | 10 +++++++--- pkgs/athena-bccr/unwrapped.nix | 27 ++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/modules/athena-bccr/sys.nix b/modules/athena-bccr/sys.nix index ce63b01..425c23a 100644 --- a/modules/athena-bccr/sys.nix +++ b/modules/athena-bccr/sys.nix @@ -7,6 +7,9 @@ }: let athena = pkgs.${doctrine.prefix}.athena-bccr.${cfg.release}; inherit (athena) vendor; + + driver = athena.card-driver.lib; + scmiddleware = "${driver}/lib/SCMiddleware"; in { environment = { etc = @@ -16,11 +19,12 @@ in { ''; } // lib.optionalAttrs (vendor == "athena") { - "Athena".source = "${athena.card-driver.lib}/etc/Athena"; + "Athena".source = "${driver}/etc/Athena"; } // lib.optionalAttrs (vendor == "idopte") { - "idoss.conf".source = "${athena.card-driver.lib}/etc/idoss.conf"; - "idoss.lic".source = "${athena.card-driver.lib}/etc/idoss.lic"; + "idoss.conf".source = "${driver}/etc/idoss.conf"; + "idoss.lic".source = "${driver}/etc/idoss.lic"; + "SCMiddleware".source = scmiddleware; }; systemPackages = [athena.card-driver]; diff --git a/pkgs/athena-bccr/unwrapped.nix b/pkgs/athena-bccr/unwrapped.nix index c7781e4..3a70144 100644 --- a/pkgs/athena-bccr/unwrapped.nix +++ b/pkgs/athena-bccr/unwrapped.nix @@ -102,6 +102,7 @@ libnotify, openssl, pcsclite, + python3, stdenv, unzip, webkitgtk_4_1, @@ -124,6 +125,7 @@ nativeBuildInputs = [ autoPatchelfHook + python3 ]; outputs = ["out" "lib"]; @@ -132,15 +134,34 @@ runHook preInstall install -m755 -d $out/bin $lib/{etc,lib/SCMiddleware} - install -m755 usr/lib/SCMiddleware/{idocachesrv,SCManager} $out/bin - install -m755 usr/lib/SCMiddleware/*.so $lib/lib/SCMiddleware + install -m755 usr/lib/SCMiddleware/SCManager $out/bin + install -m755 usr/lib/SCMiddleware/{*.so,idocachesrv} $lib/lib/SCMiddleware cp -r etc/id* $lib/etc runHook postInstall ''; preFixup = '' - patchelf --set-rpath $lib/lib/SCMiddleware $lib/lib/SCMiddleware/* $out/bin/* + for elf in $lib/lib/SCMiddleware/* $out/bin/*; do + python3 /dev/fd/3 <$elf >$elf.patched 3<= len(b) + return s.replace(a, b + b'\0' * (len(a) - len(b))) + + contents = bin_replace(contents, b'/usr/lib/SCMiddleware', b'/etc/SCMiddleware') + contents = bin_replace(contents, b'/tmp/.idoss_socket', b'/run/idoss/socket') + + sys.stdout.buffer.write(contents) + EOF + + chmod --reference=$elf $elf.patched + mv $elf.patched $elf + + patchelf --set-rpath $lib/lib/SCMiddleware $elf + done ''; passthru.pkcs11-path = "lib/SCMiddleware/libidop11.so";