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"; + }; +}