Change:
<del> { stdenv, lib, fetchurl, fetchpatch, runtimeShell, buildPackages , gettext, pkg-config, python3 , avahi, libgphoto2, libieee1284, libjpeg, libpng, libtiff, libusb1, libv4l, net-snmp , curl, systemd, libxml2, poppler, gawk , sane-drivers , nixosTests </del> <ins> { stdenv, lib, fetchFromGitLab, runtimeShell, buildPackages, gettext, pkg-config, python3, avahi, libgphoto2, libieee1284, libjpeg, libpng, libtiff, libusb1, libv4l, net-snmp, curl, systemd, libxml2, poppler, gawk, sane-drivers, nixosTests, autoconf, automake, libtool, autoconf-archive, </ins> # List of { src name backend } attibute sets - see installFirmware below: <del> , extraFirmware ? [] </del> <ins> extraFirmware ? [], </ins> # For backwards compatibility with older setups; use extraFirmware instead: <del> , gt68xxFirmware ? null, snapscanFirmware ? null </del> <ins> gt68xxFirmware ? null, snapscanFirmware ? null, </ins> # Not included by default, scan snap drivers require fetching of unfree binaries. <del> , scanSnapDriversUnfree ? false, scanSnapDriversPackage ? sane-drivers.epjitsu </del> <ins> scanSnapDriversUnfree ? false, scanSnapDriversPackage ? sane-drivers.epjitsu, </ins> }: <del> stdenv.mkDerivation { </del> <ins> stdenv.mkDerivation rec { </ins> pname = "sane-backends"; <del> version = "1.2.1"; </del> <ins> version = "1.3.1"; </ins> <del> src = fetchurl { # raw checkouts of the repo do not work because, the configure script is # only functional in manually uploaded release tarballs. # https://gitlab.com/sane-project/backends/-/issues/440 # unfortunately this make the url unpredictable on update, to find the link # go to https://gitlab.com/sane-project/backends/-/releases and choose # the link under the heading "Other". url = "https://gitlab.com/sane-project/backends/uploads/110fc43336d0fb5e514f1fdc7360dd87/sane-backends-1.2.1.tar.gz"; sha256 = "f832395efcb90bb5ea8acd367a820c393dda7e0dd578b16f48928b8f5bdd0524"; </del> <ins> src = fetchFromGitLab { owner = "sane-project"; repo = "backends"; rev = "refs/tags/${version}"; hash = "sha256-4mwPGeRsyzngDxBQ8/48mK+VR9LYV6082xr8lTrUZrk="; </ins> }; <del> patches = [ # sane-desc will be used in postInstall so compile it for build # https://github.com/void-linux/void-packages/blob/master/srcpkgs/sane/patches/sane-desc-cross.patch (fetchpatch { name = "compile-sane-desc-for-build.patch"; url = "https://raw.githubusercontent.com/void-linux/void-packages/4b97cd2fb4ec38712544438c2491b6d7d5ab334a/srcpkgs/sane/patches/sane-desc-cross.patch"; sha256 = "sha256-y6BOXnOJBSTqvRp6LwAucqaqv+OLLyhCS/tXfLpnAPI="; }) ]; </del> postPatch = '' <ins> # Do not create lock dir in install phase sed -i '/^install-lockpath:/!b;n;c       # pass' backend/Makefile.am ''; preConfigure = '' # create version files, so that autotools macros can use them: # https://gitlab.com/sane-project/backends/-/issues/440 printf "%sn" "$version" > .tarball-version printf "%sn" "$version" > .version autoreconf -fiv # Fixes for cross compilation # https://github.com/NixOS/nixpkgs/issues/308283 </ins> # related to the compile-sane-desc-for-build substituteInPlace tools/Makefile.in  --replace 'cc -I' '$(CC_FOR_BUILD) -I' <ins> # sane-desc will be used in postInstall so compile it for build # https://github.com/void-linux/void-packages/blob/master/srcpkgs/sane/patches/sane-desc-cross.patch patch -p1 -i ${./sane-desc-cross.patch} </ins> ''; outputs = [ "out" "doc" "man" ];

Discussion:
My Canon CanoScan LiDE 20 does not work on NixOS. I wrote a minimal SANE config dir to reproduce: Invocation: ` Reveals: <details</detailsImportant part: It's failing because it's trying to write a lock file into .
I suspect the code involved is this: Looks like the packaging overrode the string, putting the nix output store path prefix in front; that seems wrong.
Grepping further: Indeed, the build logs show the wrong path:
Probably the nix build sets to a store path. Fixing it via: Other nixpkgs packages also set . Maybe nixpkgs should do this automatically for all packages? Probably is what puts the nix store path in. However, trying the workaround fails the build at step:
In PR I made an option to set the package without mass rebuilds. With that, the following workarounds make the scanner work: Now I can scan.
I'd be happy if somebody could pick up the task to pass a proper lock dir and ensure it exists in NixOS.
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:
It seems only scanners covered by SANE's driver are affected by this, as only those use locks as per : Note this driver, even though called , handles also many other vendors' scanners, including some Canon, Epson, HP, and others.
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.
With the workaround mentioned in I'm able to scan on a CanonScan Lide 25 using the sane-plustek backend. Would be great to have this properly fixed.
Using a Canon N670U (also covered by ) I ran into the same issue and resolved it with workaround Proper fix would be highly appreciated though.
Please give a try, it should fix the issue