From fb9710fb774e93645d9601c6d127c1457989178c Mon Sep 17 00:00:00 2001 From: Kevin Shenk Date: Mon, 23 Nov 2026 09:29:55 -0500 Subject: [PATCH] feat(standards): add the pdfkiln wkhtmltopdf replacement Add packages/pdfkiln.nix: @pdfkiln/pdfkiln 1.3.0 from the npm registry, pinned by its sha512 and unpacked as published, with its three commands (wkhtmltopdf, wkhtmltoimage and pdfkiln) wrapped on nixpkgs' Node.js 24. Each wrapper sets PDFKILN_CHROMIUM, which selects the browser pdfkiln drives, so pdfkiln never downloads one: - Linux: nixpkgs chromium (chromium/bin/chromium) - darwin: nixpkgs google-chrome (google-chrome/bin/google-chrome-stable) flake.nix exposes it as packages..pdfkiln, from the entries helper that checks use. checks/pdfkiln.nix builds it and requires wkhtmltopdf --version to report "with patched qt". On Linux it also requires the wrapper to set PDFKILN_CHROMIUM, and renders a PDF inside the build sandbox with pdfkiln's own settings. docs/library.md documents it. Validation on x86_64-linux: the package and the check build. A check with a broken grep fails the build. A page rendered outside the sandbox starts with %PDF and shows the 1/1 footer. nix fmt, prek, statix, deadnix, nix-lint, check-names, ci-pins, dependabot and shared-config pass, and nix flake check --no-build evaluates the flake. Not verified: aarch64-darwin. google-chrome is unfree and this flake's nixpkgs does not allow unfree packages, so packages.aarch64-darwin.pdfkiln does not evaluate by default. aarch64-linux built here only under binfmt emulation, not on native hardware, and its check was not built. Co-Authored-By: Claude Haiku 5.5 Claude-Session: https://claude.ai/code/session_01AAw4Sw2knFZL7NYgFroq1Y --- checks/pdfkiln.nix | 26 +++++++++++++++++++ docs/library.md | 10 +++++-- flake.nix | 4 +++ packages/pdfkiln.nix | 62 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 checks/pdfkiln.nix create mode 100644 packages/pdfkiln.nix diff --git a/checks/pdfkiln.nix b/checks/pdfkiln.nix new file mode 100644 index 0000000..6ede78d --- /dev/null +++ b/checks/pdfkiln.nix @@ -0,0 +1,26 @@ +# packages/pdfkiln.nix, built and run: wkhtmltopdf reports the patched Qt it is +# built with, and on Linux its wrapper points PDFKILN_CHROMIUM at nixpkgs' +# chromium, the browser the package is built against. +{ pkgs, self }: +let + inherit (pkgs) lib; + checks = self.lib.checks.mk { + inherit pkgs; + product = "python-devops-nix"; + }; + pdfkiln = self.packages.${pkgs.stdenv.hostPlatform.system}.pdfkiln; +in +checks.script "pdfkiln" { tools = [ pdfkiln ]; } '' + wkhtmltopdf --version > version + cat version + grep -F 'with patched qt' version + + ${lib.optionalString pkgs.stdenv.hostPlatform.isLinux '' + grep -F 'PDFKILN_CHROMIUM' ${pdfkiln}/bin/wkhtmltopdf + grep -F '${pkgs.chromium}/bin/chromium' ${pdfkiln}/bin/wkhtmltopdf + + printf '

pdfkiln check

' > page.html + wkhtmltopdf page.html page.pdf + test "$(head -c 4 page.pdf)" = %PDF + ''} +'' diff --git a/docs/library.md b/docs/library.md index f8b7406..d7a5ef9 100644 --- a/docs/library.md +++ b/docs/library.md @@ -4,12 +4,12 @@ description: What python-devops-nix exports, from the secrets toolkit to the Nix nav_title: Library order: 2 tags: [reference, nix, lib] -updated: 2026-11-21 +updated: 2026-11-23 --- # Library reference -The flake has nixpkgs and flake-parts as its only inputs. Each output is read from one directory: `lib/.nix` (or `lib//default.nix`) is `lib.`, with a kebab-case file name as a camelCase attribute (`lib/db-nocow.nix` is `lib.dbNocow`), and `checks/.nix` is `checks..`. `flakeModules` is read from `modules/`, which is empty today. Python sits in `python/`, standards-core (a Python distribution of its own) in `standards/`, and the stub products and fixtures the checks run against sit in `tests/` (standards-core's in `standards/tests/`). +The flake has nixpkgs and flake-parts as its only inputs. Each output is read from one directory: `lib/.nix` (or `lib//default.nix`) is `lib.`, with a kebab-case file name as a camelCase attribute (`lib/db-nocow.nix` is `lib.dbNocow`), `packages/.nix` is `packages..`, and `checks/.nix` is `checks..`. `flakeModules` is read from `modules/`, which is empty today. Python sits in `python/`, standards-core (a Python distribution of its own) in `standards/`, and the stub products and fixtures the checks run against sit in `tests/` (standards-core's in `standards/tests/`). Every function takes `pkgs` and the product's names (label, prefix, option path) as arguments, and none names a product. The `check` functions are the base's own tests, which a product can also build against its interpreters. Each takes `{ pkgs, product ? …, name ? …, interpreters ? … }` and runs on every interpreter a preset names. @@ -106,6 +106,12 @@ Conventions: [Production](conventions.md#production), [Logging](conventions.md#l Conventions: [Images](conventions.md#images). +## Packages + +| Export | What it does | +| --- | --- | +| `packages..pdfkiln` | `@pdfkiln/pdfkiln` 1.3.0 from the npm registry, pinned by its hash and unpacked as published (`packages/pdfkiln.nix`): a drop-in replacement for wkhtmltopdf that renders with Chromium. Its commands are `wkhtmltopdf`, `wkhtmltoimage` and `pdfkiln`, each a wrapper that sets `PDFKILN_CHROMIUM`, which selects the browser, so pdfkiln never downloads one. The browser is nixpkgs' `chromium` on Linux and nixpkgs' `google-chrome` on darwin, through its `google-chrome-stable` wrapper. `google-chrome` is unfree and this flake's nixpkgs does not allow unfree packages, so the darwin output does not evaluate yet. | + ## Repository | Export | What it does | diff --git a/flake.nix b/flake.nix index 5b1cd6f..68fa32e 100644 --- a/flake.nix +++ b/flake.nix @@ -70,6 +70,10 @@ perSystem = { pkgs, ... }: { + # packages/.nix is `{ pkgs, … }: derivation`, called with callPackage, + # and becomes packages... + packages = lib.mapAttrs (_: path: pkgs.callPackage path { }) (entries ./packages); + # checks/.nix is `{ pkgs, self }: derivation` and becomes # checks... CI builds every one of them. checks = lib.mapAttrs (_: path: import path { inherit pkgs self; }) (entries ./checks); diff --git a/packages/pdfkiln.nix b/packages/pdfkiln.nix new file mode 100644 index 0000000..fcff026 --- /dev/null +++ b/packages/pdfkiln.nix @@ -0,0 +1,62 @@ +# @pdfkiln/pdfkiln 1.3.0 from the npm registry, unpacked as published: a drop-in +# replacement for wkhtmltopdf that renders with Chromium. Its three bundled CLIs +# (pdfkiln, wkhtmltopdf, wkhtmltoimage) run on the nixpkgs Node.js. Each wrapper +# sets PDFKILN_CHROMIUM, the browser pdfkiln drives, so pdfkiln never downloads +# one: nixpkgs' chromium on Linux, and nixpkgs' google-chrome on darwin, whose +# google-chrome-stable wrapper runs "Google Chrome.app". +{ + lib, + stdenvNoCC, + fetchurl, + makeWrapper, + nodejs_24, + chromium, + google-chrome, +}: + +let + nodejs = nodejs_24; + + # Each browser is referenced only on its own platform, so a platform evaluates + # only its own. + browserArgs = + lib.optionalString stdenvNoCC.hostPlatform.isLinux "--set PDFKILN_CHROMIUM ${chromium}/bin/chromium" + + lib.optionalString stdenvNoCC.hostPlatform.isDarwin "--set PDFKILN_CHROMIUM ${google-chrome}/bin/google-chrome-stable"; +in +stdenvNoCC.mkDerivation { + pname = "pdfkiln"; + version = "1.3.0"; + + src = fetchurl { + url = "https://registry.npmjs.org/@pdfkiln/pdfkiln/-/pdfkiln-1.3.0.tgz"; + hash = "sha512-QJiOuBJbnMhJpGN7b0eRX1egD/9FSMvw54eLIaxCaPImd+SFMiDRY9BfVfV70Kp3OdFO7V2vXfuxYiNcN8V+ig=="; + }; + + sourceRoot = "package"; + + nativeBuildInputs = [ makeWrapper ]; + + dontBuild = true; + + installPhase = '' + runHook preInstall + + mkdir -p $out/lib/pdfkiln $out/bin + cp -R . $out/lib/pdfkiln/ + + for name in pdfkiln wkhtmltopdf wkhtmltoimage; do + makeWrapper ${nodejs}/bin/node $out/bin/$name \ + --add-flags $out/lib/pdfkiln/dist/bundle/$name.cjs \ + ${browserArgs} + done + + runHook postInstall + ''; + + meta = { + description = "Drop-in replacement for wkhtmltopdf, powered by Chromium"; + license = lib.licenses.mit; + platforms = lib.platforms.linux ++ lib.platforms.darwin; + mainProgram = "wkhtmltopdf"; + }; +}