Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

cups service: Automatically detect Gutenprint in drivers

Additional CUPS drivers can be added via "services.printing.drivers" but
Gutenprint was an exception. It was possible to add a Gutenprint
derivation to that list and it would work at first but unlike the other
drivers Gutenprint requires a script to be run after each update or any
attempt to print something would simply fail and an error would show up
in the jobs queue (http://localhost:631/jobs/):
"The PPD version (5.2.11) is not compatible with Gutenprint 5.2.13.
Please run
`/nix/store/7762kpyhfkcgmr3q81v1bbyy0bjhym80-gutenprint-5.2.13/sbin/cups-genppdupdate'
as administrator."
This is due to state in "/var/lib/cups/ppd" and one would need to run
"/nix/store/.../bin/cups-genppdupdate -p /var/lib/cups/ppd" manually.
The alternative was to enable the following option:
"services.printing.gutenprint" but this had two disadvantages:
1) It is an exception that one could be unaware of or that could
potentially cause some confusion.
2) One couldn't use a customized Gutenprint derivation in
"services.printing.drivers" but would instead have to overwrite
"pkgs.gutenprint".

This new approach simply detects a Gutenprint derivation in
"services.printing.gutenprint" by checking if the meta set of a
derivation contains "isGutenprint = true". Therefore no special
exception for Gutenprint would be required and it could easily be
applied to other drivers if they would require such a script to be run.

authored by

Michael Weiss and committed by
Nikolay Amiantov
ea23f8bb ecea06ab

+20 -19
+5 -1
nixos/modules/rename.nix
··· 1 - { lib, ... }: 1 + { lib, pkgs, ... }: 2 2 3 3 with lib; 4 4 ··· 14 14 (mkRenamedOptionModule [ "networking" "enableRT73Firmware" ] [ "networking" "enableRalinkFirmware" ]) 15 15 16 16 (mkRenamedOptionModule [ "services" "cadvisor" "host" ] [ "services" "cadvisor" "listenAddress" ]) 17 + (mkChangedOptionModule [ "services" "printing" "gutenprint" ] [ "services" "printing" "drivers" ] 18 + (config: 19 + let enabled = getAttrFromPath [ "services" "printing" "gutenprint" ] config; 20 + in if enabled then [ pkgs.gutenprint ] else [ ])) 17 21 (mkRenamedOptionModule [ "services" "elasticsearch" "host" ] [ "services" "elasticsearch" "listenAddress" ]) 18 22 (mkRenamedOptionModule [ "services" "graphite" "api" "host" ] [ "services" "graphite" "api" "listenAddress" ]) 19 23 (mkRenamedOptionModule [ "services" "graphite" "web" "host" ] [ "services" "graphite" "web" "listenAddress" ])
+14 -18
nixos/modules/services/printing/cupsd.nix
··· 4 4 5 5 let 6 6 7 - inherit (pkgs) cups cups-pk-helper cups-filters gutenprint; 7 + inherit (pkgs) cups cups-pk-helper cups-filters; 8 8 9 9 cfg = config.services.printing; 10 10 ··· 35 35 name = "cups-progs"; 36 36 paths = 37 37 [ cups.out additionalBackends cups-filters pkgs.ghostscript ] 38 - ++ optional cfg.gutenprint gutenprint 39 38 ++ cfg.drivers; 40 39 pathsToLink = [ "/lib" "/share/cups" "/bin" ]; 41 40 postBuild = cfg.bindirCmds; ··· 97 96 (writeConf "client.conf" cfg.clientConf) 98 97 (writeConf "snmp.conf" cfg.snmpConf) 99 98 ] ++ optional avahiEnabled browsedFile 100 - ++ optional cfg.gutenprint gutenprint 101 99 ++ cfg.drivers; 102 100 pathsToLink = [ "/etc/cups" ]; 103 101 ignoreCollisions = true; 104 102 }; 103 + 104 + filterGutenprint = pkgs: filter (pkg: pkg.meta.isGutenprint or false == true) pkgs; 105 + containsGutenprint = pkgs: length (filterGutenprint pkgs) > 0; 106 + getGutenprint = pkgs: head (filterGutenprint pkgs); 105 107 106 108 in 107 109 ··· 224 226 ''; 225 227 }; 226 228 227 - gutenprint = mkOption { 228 - type = types.bool; 229 - default = false; 230 - description = '' 231 - Whether to enable Gutenprint drivers for CUPS. This includes auto-updating 232 - Gutenprint PPD files. 233 - ''; 234 - }; 235 - 236 229 drivers = mkOption { 237 230 type = types.listOf types.path; 238 231 default = []; 239 - example = literalExample "[ pkgs.splix ]"; 232 + example = literalExample "[ pkgs.gutenprint pkgs.hplip pkgs.splix ]"; 240 233 description = '' 241 - CUPS drivers to use. Drivers provided by CUPS, cups-filters, Ghostscript 242 - and Samba are added unconditionally. For adding Gutenprint, see 243 - <literal>gutenprint</literal>. 234 + CUPS drivers to use. Drivers provided by CUPS, cups-filters, 235 + Ghostscript and Samba are added unconditionally. If this list contains 236 + Gutenprint (i.e. a derivation with 237 + <literal>meta.isGutenprint = true</literal>) the PPD files in 238 + <filename>/var/lib/cups/ppd</filename> will be updated automatically 239 + to avoid errors due to incompatible versions. 244 240 ''; 245 241 }; 246 242 ··· 318 314 [ ! -e /var/lib/cups/path ] && \ 319 315 ln -s ${bindir} /var/lib/cups/path 320 316 321 - ${optionalString cfg.gutenprint '' 317 + ${optionalString (containsGutenprint cfg.drivers) '' 322 318 if [ -d /var/lib/cups/ppd ]; then 323 - ${gutenprint}/bin/cups-genppdupdate -p /var/lib/cups/ppd 319 + ${getGutenprint cfg.drivers}/bin/cups-genppdupdate -p /var/lib/cups/ppd 324 320 fi 325 321 ''} 326 322 '';
+1
pkgs/misc/drivers/gutenprint/default.nix
··· 47 47 homepage = https://sourceforge.net/projects/gimp-print/; 48 48 license = licenses.gpl2; 49 49 platforms = platforms.linux; 50 + isGutenprint = true; 50 51 }; 51 52 }