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