1{ lib, stdenv
2, fetchurl
3, pkg-config
4, removeReferencesTo
5, zlib
6, libjpeg
7, libpng
8, libtiff
9, pam
10, dbus
11, enableSystemd ? stdenv.isLinux
12, systemd
13, acl
14, gmp
15, darwin
16, libusb1 ? null
17, gnutls ? null
18, avahi ? null
19, libpaper ? null
20, coreutils
21}:
22
23### IMPORTANT: before updating cups, make sure the nixos/tests/printing.nix test
24### works at least for your platform.
25
26with lib;
27stdenv.mkDerivation rec {
28 pname = "cups";
29
30 # After 2.2.6, CUPS requires headers only available in macOS 10.12+
31 version = if stdenv.isDarwin then "2.2.6" else "2.3.3op2";
32
33 src = fetchurl (if stdenv.isDarwin then {
34 url = "https://github.com/apple/cups/releases/download/v${version}/cups-${version}-source.tar.gz";
35 sha256 = "16qn41b84xz6khrr2pa2wdwlqxr29rrrkjfi618gbgdkq9w5ff20";
36 } else {
37 url = "https://github.com/OpenPrinting/cups/releases/download/v${version}/cups-${version}-source.tar.gz";
38 sha256 = "1pwndz4gwkm7311wkhhzlw2diy7wbck7yy026jbaxh3rprdmgcyy";
39 });
40
41 outputs = [ "out" "lib" "dev" "man" ];
42
43 postPatch = ''
44 substituteInPlace cups/testfile.c \
45 --replace 'cupsFileFind("cat", "/bin' 'cupsFileFind("cat", "${coreutils}/bin'
46 '';
47
48 nativeBuildInputs = [ pkg-config removeReferencesTo ];
49
50 buildInputs = [ zlib libjpeg libpng libtiff libusb1 gnutls libpaper ]
51 ++ optionals stdenv.isLinux [ avahi pam dbus acl ]
52 ++ optional enableSystemd systemd
53 ++ optionals stdenv.isDarwin (with darwin; [
54 configd apple_sdk.frameworks.ApplicationServices
55 ]);
56
57 propagatedBuildInputs = [ gmp ];
58
59 configureFlags = [
60 "--localstatedir=/var"
61 "--sysconfdir=/etc"
62 "--enable-raw-printing"
63 "--enable-threads"
64 ] ++ optionals stdenv.isLinux [
65 "--enable-dbus"
66 "--enable-pam"
67 "--with-dbusdir=${placeholder "out"}/share/dbus-1"
68 ] ++ optional (libusb1 != null) "--enable-libusb"
69 ++ optional (gnutls != null) "--enable-ssl"
70 ++ optional (avahi != null) "--enable-avahi"
71 ++ optional (libpaper != null) "--enable-libpaper"
72 ++ optional stdenv.isDarwin "--disable-launchd";
73
74 # AR has to be an absolute path
75 preConfigure = ''
76 export AR="${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 ${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 "LOGDIR=$(TMPDIR)/dummy"
97 "REQUESTS=$(TMPDIR)/dummy"
98 "STATEDIR=$(TMPDIR)/dummy"
99 # Idem for /etc.
100 "PAMDIR=$(out)/etc/pam.d"
101 "XINETD=$(out)/etc/xinetd.d"
102 "SERVERROOT=$(out)/etc/cups"
103 # Idem for /usr.
104 "MENUDIR=$(out)/share/applications"
105 "ICONDIR=$(out)/share/icons"
106 # Work around a Makefile bug.
107 "CUPS_PRIMARY_SYSTEM_GROUP=root"
108 ];
109
110 enableParallelBuilding = true;
111
112 postInstall = ''
113 libexec=${if stdenv.isDarwin then "libexec/cups" else "lib/cups"}
114 moveToOutput $libexec "$out"
115
116 # $lib contains references to $out/share/cups.
117 # CUPS is working without them, so they are not vital.
118 find "$lib" -type f -exec grep -q "$out" {} \; \
119 -printf "removing references from %p\n" \
120 -exec remove-references-to -t "$out" {} +
121
122 # Delete obsolete stuff that conflicts with cups-filters.
123 rm -rf $out/share/cups/banners $out/share/cups/data/testprint
124
125 moveToOutput bin/cups-config "$dev"
126 sed -e "/^cups_serverbin=/s|$lib|$out|" \
127 -i "$dev/bin/cups-config"
128
129 for f in "$out"/lib/systemd/system/*; do
130 substituteInPlace "$f" --replace "$lib/$libexec" "$out/$libexec"
131 done
132 '' + optionalString stdenv.isLinux ''
133 # Use xdg-open when on Linux
134 substituteInPlace "$out"/share/applications/cups.desktop \
135 --replace "Exec=htmlview" "Exec=xdg-open"
136 '';
137
138 meta = {
139 homepage = "https://openprinting.github.io/cups/";
140 description = "A standards-based printing system for UNIX";
141 license = licenses.asl20;
142 maintainers = with maintainers; [ matthewbauer ];
143 platforms = platforms.unix;
144 };
145}