Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 201 lines 5.5 kB view raw
1{ 2 stdenv, 3 lib, 4 fetchFromGitLab, 5 runtimeShell, 6 buildPackages, 7 gettext, 8 pkg-config, 9 python3, 10 avahi, 11 libgphoto2, 12 libieee1284, 13 libjpeg, 14 libpng, 15 libtiff, 16 libusb1, 17 libv4l, 18 net-snmp, 19 curl, 20 systemd, 21 withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd, 22 libxml2, 23 poppler, 24 gawk, 25 sane-drivers, 26 nixosTests, 27 autoconf, 28 automake, 29 libtool, 30 autoconf-archive, 31 32 # List of { src name backend } attribute sets - see installFirmware below: 33 extraFirmware ? [ ], 34 35 # For backwards compatibility with older setups; use extraFirmware instead: 36 gt68xxFirmware ? null, 37 snapscanFirmware ? null, 38 39 # Not included by default, scan snap drivers require fetching of unfree binaries. 40 scanSnapDriversUnfree ? false, 41 scanSnapDriversPackage ? sane-drivers.epjitsu, 42}: 43 44stdenv.mkDerivation rec { 45 pname = "sane-backends"; 46 version = "1.4.0"; 47 48 src = fetchFromGitLab { 49 owner = "sane-project"; 50 repo = "backends"; 51 rev = "refs/tags/${version}"; 52 hash = "sha256-e7Wjda+CobYatblvVCGkMAO2aWrdSCp7q+qIEGnGDCY="; 53 }; 54 55 postPatch = '' 56 # Do not create lock dir in install phase 57 sed -i '/^install-lockpath:/!b;n;c\ # pass' backend/Makefile.am 58 ''; 59 60 preConfigure = '' 61 # create version files, so that autotools macros can use them: 62 # https://gitlab.com/sane-project/backends/-/issues/440 63 printf "%s\n" "$version" > .tarball-version 64 printf "%s\n" "$version" > .version 65 66 autoreconf -fiv 67 68 # Fixes for cross compilation 69 # https://github.com/NixOS/nixpkgs/issues/308283 70 71 # related to the compile-sane-desc-for-build 72 substituteInPlace tools/Makefile.in \ 73 --replace 'cc -I' '$(CC_FOR_BUILD) -I' 74 75 # sane-desc will be used in postInstall so compile it for build 76 # https://github.com/void-linux/void-packages/blob/master/srcpkgs/sane/patches/sane-desc-cross.patch 77 patch -p1 -i ${./sane-desc-cross.patch} 78 ''; 79 80 outputs = [ 81 "out" 82 "doc" 83 "man" 84 ]; 85 86 depsBuildBuild = [ buildPackages.stdenv.cc ]; 87 88 nativeBuildInputs = [ 89 autoconf 90 autoconf-archive 91 automake 92 gettext 93 libtool 94 pkg-config 95 python3 96 ]; 97 98 buildInputs = [ 99 avahi 100 libgphoto2 101 libjpeg 102 libpng 103 libtiff 104 libusb1 105 curl 106 libxml2 107 poppler 108 gawk 109 ] 110 ++ lib.optionals stdenv.hostPlatform.isLinux [ 111 libieee1284 112 libv4l 113 net-snmp 114 ] 115 ++ lib.optionals withSystemd [ 116 systemd 117 ]; 118 119 enableParallelBuilding = true; 120 121 configureFlags = [ 122 "--with-lockdir=/var/lock/sane" 123 ] 124 ++ lib.optional (avahi != null) "--with-avahi" 125 ++ lib.optional (libusb1 != null) "--with-usb"; 126 127 # autoconf check for HAVE_MMAP is never set on cross compilation. 128 # The pieusb backend fails compilation if HAVE_MMAP is not set. 129 buildFlags = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ 130 "CFLAGS=-DHAVE_MMAP=${if stdenv.hostPlatform.isLinux then "1" else "0"}" 131 ]; 132 133 postInstall = 134 let 135 136 compatFirmware = 137 extraFirmware 138 ++ lib.optional (gt68xxFirmware != null) { 139 src = gt68xxFirmware.fw; 140 inherit (gt68xxFirmware) name; 141 backend = "gt68xx"; 142 } 143 ++ lib.optional (snapscanFirmware != null) { 144 src = snapscanFirmware; 145 name = "your-firmwarefile.bin"; 146 backend = "snapscan"; 147 }; 148 149 installFirmware = f: '' 150 mkdir -p $out/share/sane/${f.backend} 151 ln -sv ${f.src} $out/share/sane/${f.backend}/${f.name} 152 ''; 153 154 in 155 '' 156 mkdir -p $out/etc/udev/rules.d/ $out/etc/udev/hwdb.d 157 ./tools/sane-desc -m udev+hwdb -s doc/descriptions:doc/descriptions-external > $out/etc/udev/rules.d/49-libsane.rules 158 ./tools/sane-desc -m udev+hwdb -s doc/descriptions:doc/descriptions-external -m hwdb > $out/etc/udev/hwdb.d/20-sane.hwdb 159 # the created 49-libsane references /bin/sh 160 substituteInPlace $out/etc/udev/rules.d/49-libsane.rules \ 161 --replace "RUN+=\"/bin/sh" "RUN+=\"${runtimeShell}" 162 163 substituteInPlace $out/lib/libsane.la \ 164 --replace "-ljpeg" "-L${lib.getLib libjpeg}/lib -ljpeg" 165 166 # net.conf conflicts with the file generated by the nixos module 167 rm $out/etc/sane.d/net.conf 168 169 '' 170 + lib.optionalString scanSnapDriversUnfree '' 171 # the ScanSnap drivers live under the epjitsu subdirectory, which was already created by the build but is empty. 172 rmdir $out/share/sane/epjitsu 173 ln -svT ${scanSnapDriversPackage} $out/share/sane/epjitsu 174 '' 175 + lib.concatStrings (builtins.map installFirmware compatFirmware); 176 177 # parallel install creates a bad symlink at $out/lib/sane/libsane.so.1 which prevents finding plugins 178 # https://github.com/NixOS/nixpkgs/issues/224569 179 enableParallelInstalling = false; 180 181 doInstallCheck = true; 182 183 passthru.tests = { 184 inherit (nixosTests) sane; 185 }; 186 187 meta = { 188 description = "SANE (Scanner Access Now Easy) backends"; 189 longDescription = '' 190 Collection of open-source SANE backends (device drivers). 191 SANE is a universal scanner interface providing standardized access to 192 any raster image scanner hardware: flatbed scanners, hand-held scanners, 193 video- and still-cameras, frame-grabbers, etc. For a list of supported 194 scanners, see http://www.sane-project.org/sane-backends.html. 195 ''; 196 homepage = "http://www.sane-project.org/"; 197 license = lib.licenses.gpl2Plus; 198 platforms = lib.platforms.linux ++ lib.platforms.darwin; 199 maintainers = [ lib.maintainers.symphorien ]; 200 }; 201}