python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / pkgs / misc / cups / default.nix
blobc844dbffee404399e260c6145f079c16552ef03c
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 ? stdenv.isLinux
13 , systemd
14 , acl
15 , gmp
16 , darwin
17 , libusb1 ? null
18 , gnutls ? null
19 , avahi ? null
20 , libpaper ? null
21 , coreutils
22 , nixosTests
25 with lib;
26 stdenv.mkDerivation rec {
27   pname = "cups";
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";
35   } else {
36     url = "https://github.com/OpenPrinting/cups/releases/download/v${version}/cups-${version}-source.tar.gz";
37     sha256 = "sha256-8DzLQLCH0eMJQKQOAUHcu6Jj85l0wg658lIQZsnGyQg=";
38   });
40   outputs = [ "out" "lib" "dev" "man" ];
42   patches = lib.optionals (version == "2.2.6") [
43     ./0001-TargetConditionals.patch
44     (fetchpatch {
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" ];
49     })
50     (fetchpatch {
51       name = "CVE-2022-26691-fix-comment.patch";
52       url = "https://github.com/OpenPrinting/cups/commit/411b6136f450a583ee08c3880fa09dbe837eb3f1.patch";
53       sha256 = "sha256-dVopmr34c9N5H2ZZz52rXVnHQBuDTNo8M40x9455+jQ=";
54     })
55   ];
57   postPatch = ''
58     substituteInPlace cups/testfile.c \
59       --replace 'cupsFileFind("cat", "/bin' 'cupsFileFind("cat", "${coreutils}/bin'
60   '';
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
69     ]);
71   propagatedBuildInputs = [ gmp ];
73   configurePlatforms = lib.optionals stdenv.isLinux [ "build" "host" ];
74   configureFlags = [
75     "--localstatedir=/var"
76     "--sysconfdir=/etc"
77     "--enable-raw-printing"
78     "--enable-threads"
79   ] ++ optionals stdenv.isLinux [
80     "--enable-dbus"
81     "--enable-pam"
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
90   preConfigure = ''
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.
96       "--prefix=$lib"
97       "--datadir=$out/share"
98       "--localedir=$lib/share/locale"
100       "--with-systemd=$out/lib/systemd/system"
102       ${optionalString stdenv.isDarwin ''
103         "--with-bundledir=$out"
104       ''}
105     )
106   '';
108   installFlags =
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"
114       # Idem for /etc.
115       "PAMDIR=$(out)/etc/pam.d"
116       "XINETD=$(out)/etc/xinetd.d"
117       "SERVERROOT=$(out)/etc/cups"
118       # Idem for /usr.
119       "MENUDIR=$(out)/share/applications"
120       "ICONDIR=$(out)/share/icons"
121       # Work around a Makefile bug.
122       "CUPS_PRIMARY_SYSTEM_GROUP=root"
123     ];
125   enableParallelBuilding = true;
127   postInstall = ''
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"
146       done
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"
151     '';
153   passthru.tests.nixos = nixosTests.printing;
155   meta = {
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;
161   };