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