about summary refs log tree commit diff
path: root/pkgs/build-support/setup-hooks/patch-ppd-files
AgeCommit message (Collapse)AuthorFilesLines
2023-04-11patch-ppd-files: use `meta` and `passthru` directlyYarny01-19/+12
When I authored the nix file in 335a9083b02d2a7034dd98c8641f019e85e50426, `makeSetupHook` didn't know about `passthru` or `meta`. So I foisted these attributes on the derivation with `.overrideAttrs`. Commits ba895a7da8f86c6f924fc96026d8f1cb1ea2af1e and 48034046bf6271d44f7dea4c1ba97196b3b105a7 enabled `makeSetupHook` to receive these attributes directly. It seems advisable to use that instead of `.overrideAttrs`.
2022-12-08stdenv: support opt-in __structuredAttrsArtturin1-1/+1
Co-authored-by: Robin Gloster <mail@glob.in> stdenv: print message if structuredAttrs is enabled stdenv: add _append reduces the chance of a user doing it wrong fix nix develop issue output hooks don't work yet in nix develop though making $outputs be the same on non-structuredAttrs and structuredAttrs is too much trouble. lets instead make a function that gets the output names reading environment file '/nix/store/2x7m69a2sm2kh0r6v0q5s9z1dh41m4xf-xz-5.2.5-env-bin' nix: src/nix/develop.cc:299: std::string Common::makeRcScript(nix::ref<nix::Store>, const BuildEnvironment&, const Path&): Assertion `outputs != buildEnvironment.vars.end()' failed. use a function to get all output names instead of using $outputs copy env functionality from https://github.com/NixOS/nixpkgs/pull/76732/commits
2022-11-06patchPpdFilesHook: new setup hook for absolute executable pathsYarny05-0/+320
PostScript Printer Description (ppd) files describe printer features and capabilities. They are usually evaluated by CUPS to convert print jobs into a format suitable for a printer. The conversion is often accomplished by commands or even short shell scripts inside the ppd files. ppd files are included in many printer driver packages. Their scripts sometimes refer to other executables; some of them are more common (like `perl`), others are more exotic (like `rastertohp`). If an executable is called with its name alone, the effects of the ppd file depend on whether the executable is in the PATH of CUPS, and on the executable's version. If an executable is called with an absolut path (like `/usr/bin/perl`), it won't work at all in NixOS. The commit at hand adds a setup hook that uses the `fixupPhase` to substitute certain executable's invocations in pdd files with absolute paths. To use it, add the hook to `nativeBuildInputs` and provide a list of executable names in `ppdFileCommands`. Each executable must be available in the package that is being built, or in `buildInputs`. The setup hook's script then looks for ppd files in `share/cups/model` and `share/ppds` in each output, and replaces executable names with their absolute paths. If ppd files need to be patched in unorthodox locations or the setup hook needs to be invoked manually for other reasons, one may leave the list `ppdFileCommands` empty to avoid automatic processing of ppd files, then call the shell function `patchPpdFileCommands` directly. Details are described in the file `patch-ppd-hook.sh`. Notes on the motivation for this setup hook: Most packages in nixpkgs that provide ppd files do not patch those ppd files at all. This is not fatal when the executables are just called with their names since the user can add packages with the executables to `services.printing.drivers`. E.g. if the user adds `pkgs.perl`, then all ppd files that invoke `perl` will work as expected. Nevertheless, to make these ppd files independent of their execution environment, command invocations should be substituted with absolut paths into the nix store. This is similar to patching shebang lines so scripts can be called independently of having the interpreter in the PATH. The hook script in this commit is meant to support new packages `foomatic-db*` which will generate several thousands of ppd files referencing a plethora of different executables. During development of these packages, I realized that it's quite hard to patch ppd files in a robust way. While binary names like `rastertokpsl` seem to be sufficiently unique to be patched with `sed`, names like `date` or `gs` are hard to patch without producing "false positives", i.e., coincidental occurences of the executable's name that do *not* refer to the executable and should not be patched at all. As this problem also affects other packages, it seems reasonable to put a robust implementation in its own setup hook so that other packages can use it without much effort. Notes on the implementation: The ppd file format is far from trivial. The basic structure are key-value pairs; keys may occur multiple times. Only a small subset of keys may contain executable names or shell scripts in their values. Some values may span multiple lines; a linebreak might even occur in the middle of a token. Some executable names also occur in other keys by accident where they must not be substituted (e.g. `gs` or `date`). It is necessary to provide the list of command names that will be patched for two reasons: ppd files often contain "tokens" that might look like commands (e.g. "file" or "host") but aren't; these would erroneously get patched. Also, looking for everything that might be a command would slow down the patching process considerably. The implementation uses `awk` to detect keys that might contain executable names; only their values are treated for substitution. This avoids most cases of "overzealous" substitutions. Since values may span multiple lines, `sed` alone (while faster than `awk`) cannot focus its substitution capabilities on relevant keys. An elaborate set of regular expressions further helps to minimize the probability of "false positives". Several tricks are employed to speed up `awk`. Notably, relevant files are identified with `grep` before `awk` is applied to those files only. Note that the script probably cannot handle fancy command names (like spaces or backslashes as part of the name). Also, there are still edge cases that the script would mistakenly skip, e.g. if a shell script contains a line break in the middle of an executable's name; although ppd files permit such constellations, I have yet to see one. ppd files may be gzipped. The setup hook accepts gzipped ppd files: It decompresses them, substitutes paths, then recompresses them. However, Nix cannot detect substituted paths as runtime dependencies in compressed ppd files. To ensure substituted paths are propagated as runtime dependencies, the script adds each substituted path to the variable `propagatedBuildInputs`. Since this might not be enough for multi-output packages, those paths are also written directly to `nix-support/propagated-build-inputs`. See the comment in `patch-ppd-hook.sh` for details. Finally, the setup hook comes with a small test that probes some edge cases with an artificial ppd file. References: * https://www.cups.org/doc/spec-ppd.html * general ppd file specification * lists some keys that may contain executable names or shell scripts * https://refspecs.linuxfoundation.org/LSB_4.0.0/LSB-Printing/LSB-Printing/ppdext.html * lists some keys that may contain executable names or shell scripts * https://en.wikipedia.org/wiki/PostScript_Printer_Description#CUPS * lists the usual locations of ppd files