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, ... }: 2 3 with lib; 4 ··· 14 (mkRenamedOptionModule [ "networking" "enableRT73Firmware" ] [ "networking" "enableRalinkFirmware" ]) 15 16 (mkRenamedOptionModule [ "services" "cadvisor" "host" ] [ "services" "cadvisor" "listenAddress" ]) 17 (mkRenamedOptionModule [ "services" "elasticsearch" "host" ] [ "services" "elasticsearch" "listenAddress" ]) 18 (mkRenamedOptionModule [ "services" "graphite" "api" "host" ] [ "services" "graphite" "api" "listenAddress" ]) 19 (mkRenamedOptionModule [ "services" "graphite" "web" "host" ] [ "services" "graphite" "web" "listenAddress" ])
··· 1 + { lib, pkgs, ... }: 2 3 with lib; 4 ··· 14 (mkRenamedOptionModule [ "networking" "enableRT73Firmware" ] [ "networking" "enableRalinkFirmware" ]) 15 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 [ ])) 21 (mkRenamedOptionModule [ "services" "elasticsearch" "host" ] [ "services" "elasticsearch" "listenAddress" ]) 22 (mkRenamedOptionModule [ "services" "graphite" "api" "host" ] [ "services" "graphite" "api" "listenAddress" ]) 23 (mkRenamedOptionModule [ "services" "graphite" "web" "host" ] [ "services" "graphite" "web" "listenAddress" ])
+14 -18
nixos/modules/services/printing/cupsd.nix
··· 4 5 let 6 7 - inherit (pkgs) cups cups-pk-helper cups-filters gutenprint; 8 9 cfg = config.services.printing; 10 ··· 35 name = "cups-progs"; 36 paths = 37 [ cups.out additionalBackends cups-filters pkgs.ghostscript ] 38 - ++ optional cfg.gutenprint gutenprint 39 ++ cfg.drivers; 40 pathsToLink = [ "/lib" "/share/cups" "/bin" ]; 41 postBuild = cfg.bindirCmds; ··· 97 (writeConf "client.conf" cfg.clientConf) 98 (writeConf "snmp.conf" cfg.snmpConf) 99 ] ++ optional avahiEnabled browsedFile 100 - ++ optional cfg.gutenprint gutenprint 101 ++ cfg.drivers; 102 pathsToLink = [ "/etc/cups" ]; 103 ignoreCollisions = true; 104 }; 105 106 in 107 ··· 224 ''; 225 }; 226 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 drivers = mkOption { 237 type = types.listOf types.path; 238 default = []; 239 - example = literalExample "[ pkgs.splix ]"; 240 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>. 244 ''; 245 }; 246 ··· 318 [ ! -e /var/lib/cups/path ] && \ 319 ln -s ${bindir} /var/lib/cups/path 320 321 - ${optionalString cfg.gutenprint '' 322 if [ -d /var/lib/cups/ppd ]; then 323 - ${gutenprint}/bin/cups-genppdupdate -p /var/lib/cups/ppd 324 fi 325 ''} 326 '';
··· 4 5 let 6 7 + inherit (pkgs) cups cups-pk-helper cups-filters; 8 9 cfg = config.services.printing; 10 ··· 35 name = "cups-progs"; 36 paths = 37 [ cups.out additionalBackends cups-filters pkgs.ghostscript ] 38 ++ cfg.drivers; 39 pathsToLink = [ "/lib" "/share/cups" "/bin" ]; 40 postBuild = cfg.bindirCmds; ··· 96 (writeConf "client.conf" cfg.clientConf) 97 (writeConf "snmp.conf" cfg.snmpConf) 98 ] ++ optional avahiEnabled browsedFile 99 ++ cfg.drivers; 100 pathsToLink = [ "/etc/cups" ]; 101 ignoreCollisions = true; 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); 107 108 in 109 ··· 226 ''; 227 }; 228 229 drivers = mkOption { 230 type = types.listOf types.path; 231 default = []; 232 + example = literalExample "[ pkgs.gutenprint pkgs.hplip pkgs.splix ]"; 233 description = '' 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. 240 ''; 241 }; 242 ··· 314 [ ! -e /var/lib/cups/path ] && \ 315 ln -s ${bindir} /var/lib/cups/path 316 317 + ${optionalString (containsGutenprint cfg.drivers) '' 318 if [ -d /var/lib/cups/ppd ]; then 319 + ${getGutenprint cfg.drivers}/bin/cups-genppdupdate -p /var/lib/cups/ppd 320 fi 321 ''} 322 '';
+1
pkgs/misc/drivers/gutenprint/default.nix
··· 47 homepage = https://sourceforge.net/projects/gimp-print/; 48 license = licenses.gpl2; 49 platforms = platforms.linux; 50 }; 51 }
··· 47 homepage = https://sourceforge.net/projects/gimp-print/; 48 license = licenses.gpl2; 49 platforms = platforms.linux; 50 + isGutenprint = true; 51 }; 52 }