12 , enableSystemd ? stdenv.isLinux
26 stdenv.mkDerivation rec {
29 # After 2.2.6, CUPS requires headers only available in macOS 10.12+
30 version = if stdenv.isDarwin then "2.2.6" else "2.4.2";
32 src = fetchurl (if stdenv.isDarwin then {
33 url = "https://github.com/apple/cups/releases/download/v${version}/cups-${version}-source.tar.gz";
34 sha256 = "16qn41b84xz6khrr2pa2wdwlqxr29rrrkjfi618gbgdkq9w5ff20";
36 url = "https://github.com/OpenPrinting/cups/releases/download/v${version}/cups-${version}-source.tar.gz";
37 sha256 = "sha256-8DzLQLCH0eMJQKQOAUHcu6Jj85l0wg658lIQZsnGyQg=";
40 outputs = [ "out" "lib" "dev" "man" ];
42 patches = lib.optionals (version == "2.2.6") [
43 ./0001-TargetConditionals.patch
45 name = "CVE-2022-26691.patch";
46 url = "https://github.com/OpenPrinting/cups/commit/de4f8c196106033e4c372dce3e91b9d42b0b9444.patch";
47 sha256 = "sha256-IKOtV7bCS6PstwK6YqnYRYTeH562jWwkley86p+6Of8=";
48 excludes = [ "CHANGES.md" ];
51 name = "CVE-2022-26691-fix-comment.patch";
52 url = "https://github.com/OpenPrinting/cups/commit/411b6136f450a583ee08c3880fa09dbe837eb3f1.patch";
53 sha256 = "sha256-dVopmr34c9N5H2ZZz52rXVnHQBuDTNo8M40x9455+jQ=";
58 substituteInPlace cups/testfile.c \
59 --replace 'cupsFileFind("cat", "/bin' 'cupsFileFind("cat", "${coreutils}/bin'
62 nativeBuildInputs = [ pkg-config removeReferencesTo ];
64 buildInputs = [ zlib libjpeg libpng libtiff libusb1 gnutls libpaper ]
65 ++ optionals stdenv.isLinux [ avahi pam dbus acl ]
66 ++ optional enableSystemd systemd
67 ++ optionals stdenv.isDarwin (with darwin; [
68 configd apple_sdk.frameworks.ApplicationServices
71 propagatedBuildInputs = [ gmp ];
73 configurePlatforms = lib.optionals stdenv.isLinux [ "build" "host" ];
75 "--localstatedir=/var"
77 "--enable-raw-printing"
79 ] ++ optionals stdenv.isLinux [
82 "--with-dbusdir=${placeholder "out"}/share/dbus-1"
83 ] ++ optional (libusb1 != null) "--enable-libusb"
84 ++ optional (gnutls != null) "--enable-ssl"
85 ++ optional (avahi != null) "--enable-avahi"
86 ++ optional (libpaper != null) "--enable-libpaper"
87 ++ optional stdenv.isDarwin "--disable-launchd";
89 # AR has to be an absolute path
91 export AR="${getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ar"
92 configureFlagsArray+=(
93 # Put just lib/* and locale into $lib; this didn't work directly.
94 # lib/cups is moved back to $out in postInstall.
95 # Beware: some parts of cups probably don't fully respect these.
97 "--datadir=$out/share"
98 "--localedir=$lib/share/locale"
100 "--with-systemd=$out/lib/systemd/system"
102 ${optionalString stdenv.isDarwin ''
103 "--with-bundledir=$out"
109 [ # Don't try to write in /var at build time.
110 "CACHEDIR=$(TMPDIR)/dummy"
111 "LOGDIR=$(TMPDIR)/dummy"
112 "REQUESTS=$(TMPDIR)/dummy"
113 "STATEDIR=$(TMPDIR)/dummy"
115 "PAMDIR=$(out)/etc/pam.d"
116 "XINETD=$(out)/etc/xinetd.d"
117 "SERVERROOT=$(out)/etc/cups"
119 "MENUDIR=$(out)/share/applications"
120 "ICONDIR=$(out)/share/icons"
121 # Work around a Makefile bug.
122 "CUPS_PRIMARY_SYSTEM_GROUP=root"
125 enableParallelBuilding = true;
128 libexec=${if stdenv.isDarwin then "libexec/cups" else "lib/cups"}
129 moveToOutput $libexec "$out"
131 # $lib contains references to $out/share/cups.
132 # CUPS is working without them, so they are not vital.
133 find "$lib" -type f -exec grep -q "$out" {} \; \
134 -printf "removing references from %p\n" \
135 -exec remove-references-to -t "$out" {} +
137 # Delete obsolete stuff that conflicts with cups-filters.
138 rm -rf $out/share/cups/banners $out/share/cups/data/testprint
140 moveToOutput bin/cups-config "$dev"
141 sed -e "/^cups_serverbin=/s|$lib|$out|" \
142 -i "$dev/bin/cups-config"
144 for f in "$out"/lib/systemd/system/*; do
145 substituteInPlace "$f" --replace "$lib/$libexec" "$out/$libexec"
147 '' + optionalString stdenv.isLinux ''
148 # Use xdg-open when on Linux
149 substituteInPlace "$out"/share/applications/cups.desktop \
150 --replace "Exec=htmlview" "Exec=xdg-open"
153 passthru.tests.nixos = nixosTests.printing;
156 homepage = "https://openprinting.github.io/cups/";
157 description = "A standards-based printing system for UNIX";
158 license = licenses.asl20;
159 maintainers = with maintainers; [ matthewbauer ];
160 platforms = platforms.unix;