Printing: Difference between revisions
imported>Tobias.bora No edit summary |
imported>Tobias.bora No edit summary |
||
Line 34: | Line 34: | ||
<p>You may need to authenticate when you add the printer. Search the web for e.g. “cups add printer” for further information.</p></li></ol> | <p>You may need to authenticate when you add the printer. Search the web for e.g. “cups add printer” for further information.</p></li></ol> | ||
=== With a raw PPD === | |||
===== Provide the PPD imperatively ===== | |||
If no driver is found for your printer, even when <code>services.printing.drivers</code> is correctly populated (see above), | If no driver is found for your printer, even when <code>services.printing.drivers</code> is correctly populated (see above), | ||
you can try to give cups a PPD file. | you can try to give cups a PPD file. | ||
* Download the required PPD file, for example from [https://openprinting.org/printers openprinting.org] | * Download the required PPD file, for example from [https://openprinting.org/printers openprinting.org] | ||
* Open the PPD as a text file, and check that it does not mention FHS paths like <code>/usr/bin</code>. If it does, this method is unlikely to work, as the PPD file depends on executables not present on your system. | * Open the PPD as a text file, and check that it does not mention FHS paths like <code>/usr/bin</code>. If it does, this method is unlikely to work, as the PPD file depends on executables not present on your system. You can certainly install the binaries yourself and point to the new binary, but it is certainly easier to patch the executables in a derivation (see below) to avoid garbage collection of your binaries. | ||
* add the printer with <code>system-config-printer</code> (for example) and at the 'choose driver' screen choose 'provide PPD file' | * add the printer with <code>system-config-printer</code> (for example) and at the 'choose driver' screen choose 'provide PPD file' | ||
===== Provide the PPD declaratively ===== | |||
You can also declaratively add the PPD as a new driver by creating a simple derivation. You just need to create a derivation that puts the PPD file in <code>$out/share/cups/model/yourfile.ppd</code> (you can also put it in a subfolder like <code>$out/share/cups/model/HP/yourfile.ppd</code> to limit conflicts between ppd having the same name). Note that the name of the file does not change the way cups will list it as the model/manufacturer is written inside the (text) ppd. | |||
At in the imperative method, first check that your file does not contain any reference to binaries outside the store like <code>/bin/</code> or <code>/usr/</code>. If it does not contain any reference then you should be able to simply do this: | |||
<syntaxhighlight lang="nix"> | |||
{ | |||
... | |||
services.printing.enable = true; | |||
services.printing.drivers = [ | |||
(writeTextDir "share/cups/model/yourppd.ppd" (builtins.readFile ./yourppd.ppd)) | |||
]; | |||
... | |||
} | |||
</syntaxhighlight> | |||
If your ppd contains links to external binaries, you can instead path the file using for instance <code>substituteInPlace</code>. For that, create a file, say, <code>myPrinter.nix</code> containing something like: | |||
<syntaxhighlight lang="nix"> | |||
{ stdenv }: | |||
stdenv.mkDerivation rec { | |||
name = "myprinter-${version}"; | |||
version = "1.0"; | |||
src = ./.; | |||
installPhase = '' | |||
mkdir -p $out/share/cups/model/ | |||
cp myprinter.ppd $out/share/cups/model/ | |||
# If you need to patch the path to files outside the nix store, you can do it this way | |||
# (if the ppd also comes with executables you may need to also patch the executables) | |||
substituteInPlace $out/share/cups/model/myprinter.ppd \ | |||
--replace "/usr/yourProgram/" "${yourProgram}/bin/yourProgram" | |||
''; | |||
} | |||
</syntaxhighlight> | |||
Of course update the name of the files and adapt the substituteInPlace command to your needs. Then add your driver as: | |||
<syntaxhighlight lang="nix"> | |||
{ | |||
... | |||
services.printing.enable = true; | |||
services.printing.drivers = [ | |||
(pkgs.callPackage ./myPrinter.nix {}) | |||
]; | |||
... | |||
} | |||
</syntaxhighlight> | |||
Your PPD file should now appear next to the other PPD files installed on your system when you add a new printer. | |||
===== Networked printers ===== | ===== Networked printers ===== |