<commit_before>{ stdenv, fetchurl, glibc, cups, libusb, ghostscript }:

let

    arch = if stdenv.system == "x86_64-linux"
      then "x86_64"
      else "i386";

in stdenv.mkDerivation rec {
  name = "samsung-unified-linux-driver-${version}";
  version = "1.00.37";

  src = fetchurl {
    sha256 = "0r66l9zp0p1qgakh4j08hynwsr4lsgq5yrpxyr0x4ldvl0z2b1bb";
    url = "http://www.bchemnet.com/suldr/driver/UnifiedLinuxDriver-${version}.tar.gz";
  };

  buildInputs = [
    cups
    libusb
  ];

  phases = [ "unpackPhase" "installPhase" "fixupPhase" ];

  installPhase = ''

    mkdir -p $out/bin
    cp -R ${arch}/{gettext,pstosecps,rastertospl,smfpnetdiscovery,usbresetter} $out/bin

    mkdir -p $out/etc/sane.d/dll.d/
    install -m644 noarch/etc/smfp.conf $out/etc/sane.d
    echo smfp >> $out/etc/sane.d/dll.d/smfp-scanner.conf

    mkdir -p $out/lib
    install -m755 ${arch}/libscmssc.so* $out/lib

    mkdir -p $out/lib/cups/backend
    ln -s $out/bin/smfpnetdiscovery $out/lib/cups/backend

    mkdir -p $out/lib/cups/filter
    ln -s $out/bin/{pstosecps,rastertospl} $out/lib/cups/filter
    ln -s $ghostscript/bin/gs $out/lib/cups/filter

    mkdir -p $out/lib/sane
    install -m755 ${arch}/libsane-smfp.so* $out/lib/sane
    ln -s libsane-smfp.so.1.0.1 $out/lib/sane/libsane-smfp.so.1
    ln -s libsane-smfp.so.1     $out/lib/sane/libsane-smfp.so

    mkdir -p $out/lib/udev/rules.d
    (
      OEM_FILE=noarch/oem.conf
      INSTALL_LOG_FILE=/dev/null
      . noarch/scripting_utils
      . noarch/package_utils
      . noarch/scanner-script.pkg
      fill_full_template noarch/etc/smfp.rules.in $out/lib/udev/rules.d/60_smfp_samsung.rules
      chmod -x $out/lib/udev/rules.d/60_smfp_samsung.rules
    )

    mkdir -p $out/share
    cp -R noarch/share/* $out/share
    gzip -9 $out/share/ppd/*.ppd
    rm -r $out/share/locale/*/*/install.mo

    mkdir -p $out/share/cups
    cd $out/share/cups
    ln -s ../ppd .
    ln -s ppd model
  '';

  preFixup = ''

  for bin in $out/bin/*; do
    patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" "$bin"
    patchelf --set-rpath "$out/lib:${stdenv.lib.getLib cups}/lib" "$bin"
  done

  patchelf --set-rpath "$out/lib:${stdenv.lib.getLib cups}/lib" "$out/lib/libscmssc.so"

  ln -s ${stdenv.cc.cc.lib}/lib/libstdc++.so.6 $out/lib/

  '';

  # all binaries are already stripped
  dontStrip = true;

  # we did this in prefixup already
  dontPatchELF = true;

  meta = with stdenv.lib; {
    description = "Unified Linux Driver for Samsung printers and scanners";
    homepage = http://www.bchemnet.com/suldr;
    downloadPage = http://www.bchemnet.com/suldr/driver/;
    license = licenses.unfree;

    # Tested on linux-x86_64. Might work on linux-i386.
    # Probably won't work on anything else.
    platforms = platforms.linux;<commit_msg>samsung-unified-linux-drive: Fix sane driver by patching rpaths<commit_after>{ stdenv, fetchurl, glibc, cups, libusb, libxml2, ghostscript }:

let

    arch = if stdenv.system == "x86_64-linux"
      then "x86_64"
      else "i386";

in stdenv.mkDerivation rec {
  name = "samsung-unified-linux-driver-${version}";
  version = "1.00.37";

  src = fetchurl {
    sha256 = "0r66l9zp0p1qgakh4j08hynwsr4lsgq5yrpxyr0x4ldvl0z2b1bb";
    url = "http://www.bchemnet.com/suldr/driver/UnifiedLinuxDriver-${version}.tar.gz";
  };

  buildInputs = [
    cups
    libusb
    libxml2
  ];

  installPhase = ''

    mkdir -p $out/bin
    cp -R ${arch}/{gettext,pstosecps,rastertospl,smfpnetdiscovery,usbresetter} $out/bin

    mkdir -p $out/etc/sane.d/dll.d/
    install -m644 noarch/etc/smfp.conf $out/etc/sane.d
    echo smfp >> $out/etc/sane.d/dll.d/smfp-scanner.conf

    mkdir -p $out/lib
    install -m755 ${arch}/libscmssc.so* $out/lib

    mkdir -p $out/lib/cups/backend
    ln -s $out/bin/smfpnetdiscovery $out/lib/cups/backend

    mkdir -p $out/lib/cups/filter
    ln -s $out/bin/{pstosecps,rastertospl} $out/lib/cups/filter
    ln -s $ghostscript/bin/gs $out/lib/cups/filter

    mkdir -p $out/lib/sane
    install -m755 ${arch}/libsane-smfp.so* $out/lib/sane
    ln -s libsane-smfp.so.1.0.1 $out/lib/sane/libsane-smfp.so.1
    ln -s libsane-smfp.so.1     $out/lib/sane/libsane-smfp.so

    mkdir -p $out/lib/udev/rules.d
    (
      OEM_FILE=noarch/oem.conf
      INSTALL_LOG_FILE=/dev/null
      . noarch/scripting_utils
      . noarch/package_utils
      . noarch/scanner-script.pkg
      fill_full_template noarch/etc/smfp.rules.in $out/lib/udev/rules.d/60_smfp_samsung.rules
      chmod -x $out/lib/udev/rules.d/60_smfp_samsung.rules
    )

    mkdir -p $out/share
    cp -R noarch/share/* $out/share
    gzip -9 $out/share/ppd/*.ppd
    rm -r $out/share/locale/*/*/install.mo

    mkdir -p $out/share/cups
    cd $out/share/cups
    ln -s ../ppd .
    ln -s ppd model
  '';

  preFixup = ''
    for bin in "$out/bin/"*; do
      patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" "$bin"
      patchelf --set-rpath "$out/lib:${stdenv.lib.getLib cups}/lib" "$bin"
    done

    patchelf --set-rpath "$out/lib:${stdenv.lib.getLib cups}/lib" "$out/lib/libscmssc.so"
    patchelf --set-rpath "$out/lib:${libxml2.out}/lib:${libusb.out}/lib" "$out/lib/sane/libsane-smfp.so.1.0.1"

    ln -s ${stdenv.cc.cc.lib}/lib/libstdc++.so.6 $out/lib/
  '';

  # all binaries are already stripped
  dontStrip = true;

  # we did this in prefixup already
  dontPatchELF = true;

  meta = with stdenv.lib; {
    description = "Unified Linux Driver for Samsung printers and scanners";
    homepage = http://www.bchemnet.com/suldr;
    downloadPage = http://www.bchemnet.com/suldr/driver/;
    license = licenses.unfree;

    # Tested on linux-x86_64. Might work on linux-i386.
    # Probably won't work on anything else.
    platforms = platforms.linux;
{'fraction_non_alphanumeric': 0.15156764247358392, 'fraction_numerical': 0.0225186211675039, 'mean_word_length': 2.687100893997446, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2482390', 'n_tokens_mistral': 2521, 'n_tokens_neox': 2375, 'n_words': 421}