at 23.11-beta 153 lines 4.7 kB view raw
1{ lib, stdenv 2, fetchurl 3, pkg-config 4, removeReferencesTo 5, zlib 6, libjpeg 7, libpng 8, libtiff 9, pam 10, dbus 11, enableSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd 12, systemd 13, acl 14, gmp 15, darwin 16, libusb1 ? null 17, gnutls ? null 18, avahi ? null 19, libpaper ? null 20, coreutils 21, nixosTests 22}: 23 24stdenv.mkDerivation rec { 25 pname = "cups"; 26 version = "2.4.7"; 27 28 src = fetchurl { 29 url = "https://github.com/OpenPrinting/cups/releases/download/v${version}/cups-${version}-source.tar.gz"; 30 sha256 = "sha256-3VQijdkDUmQozn43lhr67SMK0xB4gUHadc66oINiz2w="; 31 }; 32 33 outputs = [ "out" "lib" "dev" "man" ]; 34 35 postPatch = '' 36 substituteInPlace cups/testfile.c \ 37 --replace 'cupsFileFind("cat", "/bin' 'cupsFileFind("cat", "${coreutils}/bin' 38 39 # The cups.socket unit shouldn't be part of cups.service: stopping the 40 # service would stop the socket and break subsequent socket activations. 41 # See https://github.com/apple/cups/issues/6005 42 sed -i '/PartOf=cups.service/d' scheduler/cups.socket.in 43 '' + lib.optionalString (stdenv.hostPlatform.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinSdkVersion "12") '' 44 substituteInPlace backend/usb-darwin.c \ 45 --replace "kIOMainPortDefault" "kIOMasterPortDefault" 46 ''; 47 48 nativeBuildInputs = [ pkg-config removeReferencesTo ]; 49 50 buildInputs = [ zlib libjpeg libpng libtiff libusb1 gnutls libpaper ] 51 ++ lib.optionals stdenv.isLinux [ avahi pam dbus acl ] 52 ++ lib.optional enableSystemd systemd 53 ++ lib.optionals stdenv.isDarwin (with darwin; [ 54 configd apple_sdk.frameworks.ApplicationServices 55 ]); 56 57 propagatedBuildInputs = [ gmp ]; 58 59 configurePlatforms = lib.optionals stdenv.isLinux [ "build" "host" ]; 60 configureFlags = [ 61 "--localstatedir=/var" 62 "--sysconfdir=/etc" 63 "--enable-raw-printing" 64 "--enable-threads" 65 ] ++ lib.optionals stdenv.isLinux [ 66 "--enable-dbus" 67 "--enable-pam" 68 "--with-dbusdir=${placeholder "out"}/share/dbus-1" 69 ] ++ lib.optional (libusb1 != null) "--enable-libusb" 70 ++ lib.optional (gnutls != null) "--enable-ssl" 71 ++ lib.optional (avahi != null) "--enable-avahi" 72 ++ lib.optional (libpaper != null) "--enable-libpaper"; 73 74 # AR has to be an absolute path 75 preConfigure = '' 76 export AR="${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ar" 77 configureFlagsArray+=( 78 # Put just lib/* and locale into $lib; this didn't work directly. 79 # lib/cups is moved back to $out in postInstall. 80 # Beware: some parts of cups probably don't fully respect these. 81 "--prefix=$lib" 82 "--datadir=$out/share" 83 "--localedir=$lib/share/locale" 84 85 "--with-systemd=$out/lib/systemd/system" 86 87 ${lib.optionalString stdenv.isDarwin '' 88 "--with-bundledir=$out" 89 ''} 90 ) 91 ''; 92 93 installFlags = 94 [ # Don't try to write in /var at build time. 95 "CACHEDIR=$(TMPDIR)/dummy" 96 "LAUNCHD_DIR=$(TMPDIR)/dummy" 97 "LOGDIR=$(TMPDIR)/dummy" 98 "REQUESTS=$(TMPDIR)/dummy" 99 "STATEDIR=$(TMPDIR)/dummy" 100 # Idem for /etc. 101 "PAMDIR=$(out)/etc/pam.d" 102 "XINETD=$(out)/etc/xinetd.d" 103 "SERVERROOT=$(out)/etc/cups" 104 # Idem for /usr. 105 "MENUDIR=$(out)/share/applications" 106 "ICONDIR=$(out)/share/icons" 107 # Work around a Makefile bug. 108 "CUPS_PRIMARY_SYSTEM_GROUP=root" 109 ]; 110 111 enableParallelBuilding = true; 112 113 postInstall = '' 114 libexec=${if stdenv.isDarwin then "libexec/cups" else "lib/cups"} 115 moveToOutput $libexec "$out" 116 117 # $lib contains references to $out/share/cups. 118 # CUPS is working without them, so they are not vital. 119 find "$lib" -type f -exec grep -q "$out" {} \; \ 120 -printf "removing references from %p\n" \ 121 -exec remove-references-to -t "$out" {} + 122 123 # Delete obsolete stuff that conflicts with cups-filters. 124 rm -rf $out/share/cups/banners $out/share/cups/data/testprint 125 126 moveToOutput bin/cups-config "$dev" 127 sed -e "/^cups_serverbin=/s|$lib|$out|" \ 128 -i "$dev/bin/cups-config" 129 130 for f in "$out"/lib/systemd/system/*; do 131 substituteInPlace "$f" --replace "$lib/$libexec" "$out/$libexec" 132 done 133 '' + lib.optionalString stdenv.isLinux '' 134 # Use xdg-open when on Linux 135 substituteInPlace "$out"/share/applications/cups.desktop \ 136 --replace "Exec=htmlview" "Exec=xdg-open" 137 ''; 138 139 passthru.tests = { 140 inherit (nixosTests) 141 printing-service 142 printing-socket 143 ; 144 }; 145 146 meta = with lib; { 147 homepage = "https://openprinting.github.io/cups/"; 148 description = "A standards-based printing system for UNIX"; 149 license = licenses.asl20; 150 maintainers = with maintainers; [ matthewbauer ]; 151 platforms = platforms.unix; 152 }; 153}