From ea23f8bb079ef11c2d11859994d804c4e4940be5 Mon Sep 17 00:00:00 2001 From: Michael Weiss Date: Sun, 20 Aug 2017 13:20:45 +0200 Subject: 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. --- nixos/modules/services/printing/cupsd.nix | 32 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'nixos/modules/services/printing/cupsd.nix') diff --git a/nixos/modules/services/printing/cupsd.nix b/nixos/modules/services/printing/cupsd.nix index 855c8930384..4c7f58d1d8b 100644 --- a/nixos/modules/services/printing/cupsd.nix +++ b/nixos/modules/services/printing/cupsd.nix @@ -4,7 +4,7 @@ with lib; let - inherit (pkgs) cups cups-pk-helper cups-filters gutenprint; + inherit (pkgs) cups cups-pk-helper cups-filters; cfg = config.services.printing; @@ -35,7 +35,6 @@ let name = "cups-progs"; paths = [ cups.out additionalBackends cups-filters pkgs.ghostscript ] - ++ optional cfg.gutenprint gutenprint ++ cfg.drivers; pathsToLink = [ "/lib" "/share/cups" "/bin" ]; postBuild = cfg.bindirCmds; @@ -97,12 +96,15 @@ let (writeConf "client.conf" cfg.clientConf) (writeConf "snmp.conf" cfg.snmpConf) ] ++ optional avahiEnabled browsedFile - ++ optional cfg.gutenprint gutenprint ++ cfg.drivers; pathsToLink = [ "/etc/cups" ]; ignoreCollisions = true; }; + filterGutenprint = pkgs: filter (pkg: pkg.meta.isGutenprint or false == true) pkgs; + containsGutenprint = pkgs: length (filterGutenprint pkgs) > 0; + getGutenprint = pkgs: head (filterGutenprint pkgs); + in { @@ -224,23 +226,17 @@ in ''; }; - gutenprint = mkOption { - type = types.bool; - default = false; - description = '' - Whether to enable Gutenprint drivers for CUPS. This includes auto-updating - Gutenprint PPD files. - ''; - }; - drivers = mkOption { type = types.listOf types.path; default = []; - example = literalExample "[ pkgs.splix ]"; + example = literalExample "[ pkgs.gutenprint pkgs.hplip pkgs.splix ]"; description = '' - CUPS drivers to use. Drivers provided by CUPS, cups-filters, Ghostscript - and Samba are added unconditionally. For adding Gutenprint, see - gutenprint. + CUPS drivers to use. Drivers provided by CUPS, cups-filters, + Ghostscript and Samba are added unconditionally. If this list contains + Gutenprint (i.e. a derivation with + meta.isGutenprint = true) the PPD files in + /var/lib/cups/ppd will be updated automatically + to avoid errors due to incompatible versions. ''; }; @@ -318,9 +314,9 @@ in [ ! -e /var/lib/cups/path ] && \ ln -s ${bindir} /var/lib/cups/path - ${optionalString cfg.gutenprint '' + ${optionalString (containsGutenprint cfg.drivers) '' if [ -d /var/lib/cups/ppd ]; then - ${gutenprint}/bin/cups-genppdupdate -p /var/lib/cups/ppd + ${getGutenprint cfg.drivers}/bin/cups-genppdupdate -p /var/lib/cups/ppd fi ''} ''; -- cgit 1.4.1