NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
16.48k stars 12.98k forks source link

USB scanner does not work because SANE tries to write to lock file in /nix/store #273280

Open nh2 opened 6 months ago

nh2 commented 6 months ago

My Canon CanoScan LiDE 20 does not work on NixOS.

I wrote a minimal SANE config dir to reproduce:

$ find $PWD/sane-config-simple
/home/niklas/tmp/sane-config-simple
/home/niklas/tmp/sane-config-simple/plustek.conf
/home/niklas/tmp/sane-config-simple/dll.conf
$ cat sane-config-simple/dll.conf
plustek
$ cat sane-config-simple/plustek.conf                 
[usb] 0x04A9 0x220D
device auto

Invocation:

SANE_DEBUG_DLL=128 SANE_USB_WORKAROUND=1 SANE_DEBUG_SANEI_USB=128  SANE_DEBUG_PLUSTEK=255 SANE_CONFIG_DIR=$PWD/sane-config-simple strace -fye open,openat scanimage -L

Reveals:

``` [06:50:41.520033] [sanei_usb] libusb_scan_devices: skipping device 0x1d6b/0x0002 at 001:001: cannot open: Access denied (insufficient permissions) [06:50:41.520094] [sanei_usb] sanei_usb_scan_devices: device 00 is libusb:001:015 [06:50:41.520153] [sanei_usb] sanei_usb_scan_devices: found 1 devices [06:50:41.520216] [plustek] Plustek backend V0.52-12, part of sane-backends 1.2.1 [06:50:41.520280] [plustek] Retrieving all supported and conntected devices [06:50:41.520356] [plustek] Checking for 0x07b3-0x0010 [06:50:41.520417] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0010 [06:50:41.520477] [plustek] Checking for 0x07b3-0x0011 [06:50:41.520537] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0011 [06:50:41.520596] [plustek] Checking for 0x07b3-0x0013 [06:50:41.520656] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0013 [06:50:41.520715] [plustek] Checking for 0x07b3-0x0017 [06:50:41.520774] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0017 [06:50:41.520834] [plustek] Checking for 0x07b3-0x0015 [06:50:41.520893] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0015 [06:50:41.520953] [plustek] Checking for 0x07b3-0x0015 [06:50:41.521012] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0015 [06:50:41.521071] [plustek] Checking for 0x07b3-0x0017 [06:50:41.521131] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0017 [06:50:41.521190] [plustek] Checking for 0x07b3-0x0013 [06:50:41.521250] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0013 [06:50:41.521309] [plustek] Checking for 0x07b3-0x0011 [06:50:41.521371] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0011 [06:50:41.521431] [plustek] Checking for 0x07b3-0x0010 [06:50:41.521491] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0010 [06:50:41.521551] [plustek] Checking for 0x07b3-0x0014 [06:50:41.521612] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0014 [06:50:41.521672] [plustek] Checking for 0x07b3-0x0014 [06:50:41.521731] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0014 [06:50:41.521791] [plustek] Checking for 0x07b3-0x0016 [06:50:41.521851] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0016 [06:50:41.521911] [plustek] Checking for 0x07b3-0x0017 [06:50:41.521971] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0017 [06:50:41.522031] [plustek] Checking for 0x07b3-0x0017 [06:50:41.522090] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0017 [06:50:41.522150] [plustek] Checking for 0x07b3-0x0007 [06:50:41.522210] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0007 [06:50:41.522270] [plustek] Checking for 0x07b3-0x000f [06:50:41.522329] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x000f [06:50:41.522392] [plustek] Checking for 0x07b3-0x000f [06:50:41.522455] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x000f [06:50:41.522514] [plustek] Checking for 0x07b3-0x0005 [06:50:41.522601] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0005 [06:50:41.522662] [plustek] Checking for 0x07b3-0x0014 [06:50:41.522721] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0014 [06:50:41.522780] [plustek] Checking for 0x07b3-0x0012 [06:50:41.522839] [sanei_usb] sanei_usb_find_devices: vendor=0x07b3, product=0x0012 [06:50:41.522903] [plustek] Checking for 0x0400-0x1000 [06:50:41.522964] [sanei_usb] sanei_usb_find_devices: vendor=0x0400, product=0x1000 [06:50:41.523028] [plustek] Checking for 0x0400-0x1001 [06:50:41.523091] [sanei_usb] sanei_usb_find_devices: vendor=0x0400, product=0x1001 [06:50:41.523162] [plustek] Checking for 0x0400-0x1001 [06:50:41.523233] [sanei_usb] sanei_usb_find_devices: vendor=0x0400, product=0x1001 [06:50:41.523345] [plustek] Checking for 0x0458-0x2007 [06:50:41.523423] [sanei_usb] sanei_usb_find_devices: vendor=0x0458, product=0x2007 [06:50:41.523498] [plustek] Checking for 0x0458-0x2008 [06:50:41.523571] [sanei_usb] sanei_usb_find_devices: vendor=0x0458, product=0x2008 [06:50:41.523642] [plustek] Checking for 0x0458-0x2009 [06:50:41.523718] [sanei_usb] sanei_usb_find_devices: vendor=0x0458, product=0x2009 [06:50:41.523795] [plustek] Checking for 0x0458-0x2013 [06:50:41.523869] [sanei_usb] sanei_usb_find_devices: vendor=0x0458, product=0x2013 [06:50:41.523945] [plustek] Checking for 0x0458-0x2015 [06:50:41.524021] [sanei_usb] sanei_usb_find_devices: vendor=0x0458, product=0x2015 [06:50:41.524096] [plustek] Checking for 0x0458-0x2016 [06:50:41.524169] [sanei_usb] sanei_usb_find_devices: vendor=0x0458, product=0x2016 [06:50:41.524326] [plustek] Checking for 0x03f0-0x0505 [06:50:41.524407] [sanei_usb] sanei_usb_find_devices: vendor=0x03f0, product=0x0505 [06:50:41.524479] [plustek] Checking for 0x03f0-0x0605 [06:50:41.524550] [sanei_usb] sanei_usb_find_devices: vendor=0x03f0, product=0x0605 [06:50:41.524619] [plustek] Checking for 0x04b8-0x010f [06:50:41.524688] [sanei_usb] sanei_usb_find_devices: vendor=0x04b8, product=0x010f [06:50:41.524761] [plustek] Checking for 0x04b8-0x011d [06:50:41.524832] [sanei_usb] sanei_usb_find_devices: vendor=0x04b8, product=0x011d [06:50:41.524906] [plustek] Checking for 0x1606-0x0050 [06:50:41.524977] [sanei_usb] sanei_usb_find_devices: vendor=0x1606, product=0x0050 [06:50:41.525049] [plustek] Checking for 0x1606-0x0060 [06:50:41.525118] [sanei_usb] sanei_usb_find_devices: vendor=0x1606, product=0x0060 [06:50:41.525187] [plustek] Checking for 0x1606-0x0160 [06:50:41.525258] [sanei_usb] sanei_usb_find_devices: vendor=0x1606, product=0x0160 [06:50:41.525330] [plustek] Checking for 0x049f-0x001a [06:50:41.525409] [sanei_usb] sanei_usb_find_devices: vendor=0x049f, product=0x001a [06:50:41.525479] [plustek] Checking for 0x04a9-0x2206 [06:50:41.525549] [sanei_usb] sanei_usb_find_devices: vendor=0x04a9, product=0x2206 [06:50:41.525644] [plustek] Checking for 0x04a9-0x2207 [06:50:41.525714] [sanei_usb] sanei_usb_find_devices: vendor=0x04a9, product=0x2207 [06:50:41.525780] [plustek] Checking for 0x04a9-0x2208 [06:50:41.525845] [sanei_usb] sanei_usb_find_devices: vendor=0x04a9, product=0x2208 [06:50:41.525912] [plustek] Checking for 0x04a9-0x220d [06:50:41.525977] [sanei_usb] sanei_usb_find_devices: vendor=0x04a9, product=0x220d [06:50:41.526045] [plustek] Checking for 0x04a9-0x220e [06:50:41.526111] [sanei_usb] sanei_usb_find_devices: vendor=0x04a9, product=0x220e [06:50:41.526177] [plustek] Checking for 0x04a9-0x2220 [06:50:41.526242] [sanei_usb] sanei_usb_find_devices: vendor=0x04a9, product=0x2220 [06:50:41.526306] [plustek] Checking for 0x0a82-0x4600 [06:50:41.526385] [sanei_usb] sanei_usb_find_devices: vendor=0x0a82, product=0x4600 [06:50:41.526451] [plustek] Checking for 0x0a82-0x6620 [06:50:41.526524] [sanei_usb] sanei_usb_find_devices: vendor=0x0a82, product=0x6620 [06:50:41.526590] [plustek] Checking for 0x04a7-0x0427 [06:50:41.526668] [sanei_usb] sanei_usb_find_devices: vendor=0x04a7, product=0x0427 [06:50:41.526727] [plustek] Checking for 0x0a53-0x1000 [06:50:41.526786] [sanei_usb] sanei_usb_find_devices: vendor=0x0a53, product=0x1000 [06:50:41.526845] [plustek] Checking for 0x0a53-0x2000 [06:50:41.526903] [sanei_usb] sanei_usb_find_devices: vendor=0x0a53, product=0x2000 [06:50:41.526962] [plustek] Available and supported devices: [06:50:41.527021] [plustek] Device: >libusb:001:015< - 0x04a9x0x220d [pid 63324] openat(AT_FDCWD, "/home/niklas/tmp/sane-config-simple/plustek.conf", O_RDONLY) = 7 [06:50:41.527266] [plustek] ># Plustek-SANE Backend configuration file< [06:50:41.527329] [plustek] ># For use with LM9831/2/3 based USB scanners< [06:50:41.527397] [plustek] >#< [06:50:41.527456] [plustek] >< [06:50:41.527515] [plustek] ># each device needs at least two lines:< [06:50:41.527573] [plustek] ># - [usb] vendor-ID and product-ID< [06:50:41.527632] [plustek] ># - device devicename< [06:50:41.527691] [plustek] ># i.e. for Plustek (0x07B3) UT12/16/24 (0x0017)< [06:50:41.527749] [plustek] ># [usb] 0x07B3 0x0017< [06:50:41.527808] [plustek] ># device /dev/usbscanner< [06:50:41.527867] [plustek] ># or< [06:50:41.527925] [plustek] ># device libusb:bbb:ddd< [06:50:41.527984] [plustek] ># where bbb is the busnumber and ddd the device number< [06:50:41.528043] [plustek] ># make sure that your user has access to /proc/bus/usb/bbb/ddd< [06:50:41.528101] [plustek] >#< [06:50:41.528160] [plustek] ># additionally you can specify some options< [06:50:41.528218] [plustek] ># warmup, lOffOnEnd, lampOff< [06:50:41.528277] [plustek] >#< [06:50:41.528339] [plustek] ># For autodetection use< [06:50:41.528398] [plustek] ># [usb]< [06:50:41.528457] [plustek] ># device /dev/usbscanner< [06:50:41.528515] [plustek] >#< [06:50:41.528574] [plustek] ># or simply< [06:50:41.528632] [plustek] ># [usb]< [06:50:41.528691] [plustek] >#< [06:50:41.528750] [plustek] ># or if you want a specific device but you have no idea about the< [06:50:41.528808] [plustek] ># device node or you use libusb, simply set vendor- and product-ID< [06:50:41.528867] [plustek] ># [usb] 0x07B3 0x0017< [06:50:41.528926] [plustek] ># device auto< [06:50:41.528985] [plustek] >#< [06:50:41.529044] [plustek] ># NOTE: autodetection is safe, as it uses the info it got< [06:50:41.529102] [plustek] ># from the USB subsystem. If you're not using the< [06:50:41.529161] [plustek] ># autodetection, you MUST have attached that device< [06:50:41.529220] [plustek] ># at your USB-port, that you have specified...< [06:50:41.529278] [plustek] >#< [06:50:41.529628] [plustek] >< [06:50:41.529713] [plustek] >[usb] 0x04A9 0x220D< [06:50:41.529775] [plustek] next device is a USB device (0x04A9-0x220D) [06:50:41.529834] [plustek] ... next device [06:50:41.529893] [plustek] >#device libusb:001:015< [06:50:41.529951] [plustek] >device auto< [06:50:41.530010] [plustek] Decoding device name >auto< [06:50:41.530097] [plustek] attach (auto, 0x7ffc5a863df0, (nil)) [06:50:41.530157] [plustek] Device configuration: [06:50:41.530215] [plustek] device name : >auto< [06:50:41.530274] [plustek] USB-ID : >0x04A9-0x220D< [06:50:41.530332] [plustek] model ovr. : 0 [06:50:41.530397] [plustek] warmup : -1s [06:50:41.530456] [plustek] lampOff : -1 [06:50:41.530514] [plustek] lampOffOnEnd : yes [06:50:41.530573] [plustek] cacheCalData : no [06:50:41.530631] [plustek] altCalibrate : no [06:50:41.530689] [plustek] skipCalibr. : no [06:50:41.530748] [plustek] skipFine : no [06:50:41.530806] [plustek] skipFineWhite: no [06:50:41.530865] [plustek] skipDarkStrip: no [06:50:41.530923] [plustek] incDarkTarget: yes [06:50:41.530982] [plustek] invertNegs. : no [06:50:41.531040] [plustek] dis.Speedup : no [06:50:41.531098] [plustek] pos_x : 0 [06:50:41.531157] [plustek] pos_y : 0 [06:50:41.531215] [plustek] pos_shading_y: -1 [06:50:41.531273] [plustek] neg_x : 0 [06:50:41.531332] [plustek] neg_y : 0 [06:50:41.531394] [plustek] neg_shading_y: -1 [06:50:41.531453] [plustek] tpa_x : 0 [06:50:41.531511] [plustek] tpa_y : 0 [06:50:41.531570] [plustek] tpa_shading_y: -1 [06:50:41.531628] [plustek] red gain : -1 [06:50:41.531686] [plustek] green gain : -1 [06:50:41.531745] [plustek] blue gain : -1 [06:50:41.531803] [plustek] red offset : -1 [06:50:41.531862] [plustek] green offset : -1 [06:50:41.531921] [plustek] blue offset : -1 [06:50:41.531979] [plustek] red lampoff : -1 [06:50:41.532038] [plustek] green lampoff: -1 [06:50:41.532096] [plustek] blue lampoff : -1 [06:50:41.532155] [plustek] red Gamma : 1.00 [06:50:41.532215] [plustek] green Gamma : 1.00 [06:50:41.532274] [plustek] blue Gamma : 1.00 [06:50:41.532338] [plustek] gray Gamma : 1.00 [06:50:41.532398] [plustek] --------------------- [06:50:41.532465] [plustek] usbDev_open(auto,0x04A9-0x220D) - 0x203f440 [pid 63324] openat(AT_FDCWD, "/nix/store/4wxksva2132pc1ddy4rk83mx2j8q9p82-sane-backends-1.2.1/var/lock/LCK..libusb:001:015", O_WRONLY|O_CREAT|O_EXCL, 0644) = -1 EROFS (Read-only file system) [06:50:41.532572] [plustek] sanei_access_lock failed: 11 [06:50:41.532633] [plustek] open failed: -1 [06:50:41.532691] [dll] init: backend `plustek' is version 1.0.0 [06:50:41.532750] [plustek] sane_get_devices (0x7ffc5a865f70, 0) [06:50:41.532808] [dll] sane_get_devices: found 0 devices No scanners were identified. If you were expecting something different, check that the scanner is plugged in, turned on and detected by the sane-find-scanner tool (if appropriate). Please read the documentation which came with this software (README, FAQ, manpages). [06:50:41.532953] [dll] sane_exit: exiting [06:50:41.533015] [dll] sane_exit: calling backend `plustek's exit function [06:50:41.533076] [plustek] sane_exit [06:50:41.533210] [dll] sane_exit: finished [pid 63325] +++ exited with 0 +++ +++ exited with 0 +++ ```

Important part:

[plustek] usbDev_open(auto,0x04A9-0x220D) - 0x203f440
openat(AT_FDCWD</home/niklas/tmp>, "/nix/store/4wxksva2132pc1ddy4rk83mx2j8q9p82-sane-backends-1.2.1/var/lock/LCK..libusb:001:015", O_WRONLY|O_CREAT|O_EXCL, 0644) = -1 EROFS (Read-only file system)
[plustek] sanei_access_lock failed: 11
[plustek] open failed: -1

It's failing because it's trying to write a lock file into /nix/store.

nh2 commented 6 months ago

I suspect the code involved is this:

https://github.com/miurahr/sane-backends/blob/9fc683d8837f176db761b0aaf2a9140feec8febf/sanei/sanei_access.c#L131-L136

static void
create_lock_filename( char *fn, const char *devname )
{
    char *p;

    strcpy( fn, STRINGIFY(PATH_SANE_LOCK_DIR)"/LCK.." );

https://github.com/miurahr/sane-backends/blob/9fc683d8837f176db761b0aaf2a9140feec8febf/include/sane/sanei_access.h#L67-L84

/** Set a lock.
 *
 * The function tries to open/create exclusively a lock file in 
 * $PATH_SANE_LOCK_DIR.
 * If the file could be created successfully, the function fills in the
 * process ID.
 * The complete filename of the lockfile is created as follows:
 * $PATH_SANE_LOCK_DIR/LCK..&lt;devicename&gt;
 * If the lock could not be set, the function tries it until the timeout
 * period has been elapsed.
 *
 * @param devicename - unique part of the lockfile name
 * @param timeout    - time in seconds to try to set a lock
 * @return  
 * - SANE_STATUS_GOOD          - if the lock has been successfully set
 * - SANE_STATUS_ACCESS_DENIED - the lock could not set
 */
extern SANE_Status sanei_access_lock( const char * devicename, SANE_Word timeout );
$ strings /nix/store/4wxksva2132pc1ddy4rk83mx2j8q9p82-sane-backends-1.2.1/lib/sane/libsane-plustek.so | grep /var/lock
/nix/store/4wxksva2132pc1ddy4rk83mx2j8q9p82-sane-backends-1.2.1/1/var/lock/LCK..

Looks like the packaging overrode the /var/lock/LCK.. string, putting the nix output store path prefix in front; that seems wrong.

nh2 commented 6 months ago

Grepping further:

https://github.com/miurahr/sane-backends/blob/9fc683d8837f176db761b0aaf2a9140feec8febf/configure.in#L570-L587

dnl Check for lock dir

AC_ARG_WITH(lockdir, AC_HELP_STRING([--with-lockdir=DIR],
                                    [set SANE lockdir @<:@localstatedir/lock/sane@:>@]),
                                    [locksanedir=$withval],[locksanedir=${localstatedir}/lock/sane])
AC_SUBST(locksanedir)

configdir="${sysconfdir}/sane.d"
AC_SUBST(configdir)

dnl ***********************************************************************
dnl enable/disable backends and features based on previous tests and user's
dnl choice
dnl ***********************************************************************

CPPFLAGS="${CPPFLAGS} -DPATH_SANE_CONFIG_DIR=\$(configdir) \
      -DPATH_SANE_DATA_DIR=\$(datadir) \
      -DPATH_SANE_LOCK_DIR=\$(locksanedir) \
      -DV_MAJOR=${V_MAJOR} -DV_MINOR=${V_MINOR}"

Indeed, the build logs show the wrong Lockfiles path:

% nix --extra-experimental-features nix-command log /nix/store/4wxksva2132pc1ddy4rk83mx2j8q9p82-sane-backends-1.2.1/ | grep -i lock

checking whether to enable device locking... yes
checking for struct flock in fcntl.h... yes
AM_CPPFLAGS=" -D_REENTRANT -DPATH_SANE_CONFIG_DIR=$(configdir) -DPATH_SANE_DATA_DIR=$(datadir) -DPATH_SANE_LOCK_DIR=$(locksanedir) -DV_MAJOR=1 -DV_MINOR=2"
Lockfiles:     /nix/store/4wxksva2132pc1ddy4rk83mx2j8q9p82-sane-backends-1.2.1/var/lock
nh2 commented 6 months ago

Probably the nix build sets localstatedir to a store path.

Fixing it via:

  configureFlags = [
    "--localstatedir=/var" # `sane-backends` puts e.g. lock files in here, must not be in /nix/store
  ]

Other nixpkgs packages also set "--localstatedir=/var".


Maybe nixpkgs should do this automatically for all autoconf packages?

https://www.gnu.org/prep/standards/html_node/Directory-Variables.html

localstatedir The directory for installing data files which the programs modify while they run $(localstatedir) should normally be /usr/local/var, but write it as $(prefix)/var.

Probably $(prefix)/var is what puts the nix store path in.


However, trying the workaround fails the build at step:

/nix/store/q1c2flcykgr4wwg5a6h450hxbk4ch589-bash-5.2-p15/bin/bash /build/sane-backends-1.2.1/install-sh -d -m 775 /var/lock
mkdir: cannot create directory '/var': Permission denied
mkdir: cannot create directory '/var': Permission denied
nh2 commented 6 months ago

In PR #273286 I made an option to set the sane-backends package without mass rebuilds.

With that, the following workarounds make the scanner work:

  hardware.sane.enable = true; # enables support for SANE scanners
  hardware.sane.backends-package = pkgs.sane-backends.overrideAttrs (old: {
    configureFlags = (old.configureFlags or []) ++ [
      # "--localstatedir=/var" # `sane-backends` puts e.g. lock files in here, must not be in /nix/store
      # "--with-lockdir=/var/lock/sane" # `sane-backends` puts e.g. lock files in here, must not be in /nix/store

      # Ugly workaround for https://github.com/NixOS/nixpkgs/issues/273280#issuecomment-1848873028
      # Really we should make `sane-backends` be able to provide a real lock dir (e.g. `/var/lock/sane`).
      "--disable-locking"
    ];
    # Alternative workaround for https://github.com/NixOS/nixpkgs/issues/273280#issuecomment-1848873028
    # We'd prefer to just set in `configureFlags`
    #     "--localstatedir=/var" # `sane-backends` puts e.g. lock files in here, must not be in /nix/store
    # but that does not work because the install step tries to create this directory,
    # which fails in the nix build sandbox.
    # So instead, we set the preprocessor variable directly, see:
    #     https://gitlab.com/sane-project/backends/-/blob/65779d6b595547d155a1954958bce5faaad45a5d/configure.ac#L635-652
    # A problem is that this lock dir also needs to exist and have write permissions.
    # Right now you have to do that manually with:
    #     sudo mkdir -p /var/lock/sane && sudo chown root:scanner /var/lock/sane && sudo chmod g+w /var/lock/sane
    # Maybe we should use the `scanner` group for that, and/or configure it with systemd `tmpfiles`.
    #NIX_CFLAGS_COMPILE = "-DPATH_SANE_LOCK_DIR=/var/lock/sane";
  });

Now I can scan.

nh2 commented 6 months ago

I'd be happy if somebody could pick up the task to pass a proper lock dir and ensure it exists in NixOS.

nagy commented 6 months ago

Another option is to disable locking entirely. Putting this in my nixos config is working for me:

{
  nixpkgs.overlays = [
    (final: prev: {
      # Fixes a problem that attempt to access /nix/store/.../var/lock .
      # Without this, the scanner is not detected.
      sane-backends = prev.sane-backends.overrideAttrs
        ({ configureFlags ? [ ], ... }: {
          configureFlags = configureFlags ++ [ "--disable-locking" ];
        });
    })
  ];
}
nh2 commented 6 months ago

Another option is to disable locking entirely. Putting this in my nixos config is working for me:

Yes, that's what's mentioned in the comment just above: https://github.com/NixOS/nixpkgs/issues/273280#issuecomment-1848875571

nh2 commented 6 months ago

It seems only scanners covered by SANE's plustek driver are affected by this, as only those use locks as per grep:

% grep -R /var/lock /nix/store/4wxksva2132pc1ddy4rk83mx2j8q9p82-sane-backends-1.2.1
grep: /nix/store/4wxksva2132pc1ddy4rk83mx2j8q9p82-sane-backends-1.2.1/lib/sane/libsane-plustek.so.1.2.1: binary file matches
grep: /nix/store/4wxksva2132pc1ddy4rk83mx2j8q9p82-sane-backends-1.2.1/lib/sane/libsane-plustek.so.1: binary file matches
grep: /nix/store/4wxksva2132pc1ddy4rk83mx2j8q9p82-sane-backends-1.2.1/lib/sane/libsane-plustek.so: binary file matches

http://www.sane-project.org/lists/sane-backends-cvs.html#S-PLUSTEK

Note this driver, even though called plustek, handles also many other vendors' scanners, including some Canon, Epson, HP, and others.

bjornfor commented 6 months ago

Other nixpkgs packages also set "--localstatedir=/var".

Maybe nixpkgs should do this automatically for all autoconf packages? [...] However, trying the workaround fails the build at step:

/nix/store/q1c2flcykgr4wwg5a6h450hxbk4ch589-bash-5.2-p15/bin/bash /build/sane-backends-1.2.1/install-sh -d -m 775 /var/lock mkdir: cannot create directory '/var': Permission denied

I think that's the reason it isn't being done by default, because upstream build systems try to create directories inside the runtime state directory at install time.

So we're trading build time successes for runtime failures.

A similar situation exists with /etc (sysconfdir), where I think the default should be /etc, but nixpkgs uses $prefix/etc because it has a higher success rate at build time.

onjen commented 5 days ago

With the workaround mentioned in https://github.com/NixOS/nixpkgs/issues/273280#issuecomment-1848875571 I'm able to scan on a CanonScan Lide 25 using the sane-plustek backend. Would be great to have this properly fixed.