Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions checks/pdfkiln.nix
Original file line number Diff line number Diff line change
@@ -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 '<p>pdfkiln check</p>' > page.html
wkhtmltopdf page.html page.pdf
test "$(head -c 4 page.pdf)" = %PDF
''}
''
10 changes: 8 additions & 2 deletions docs/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name>.nix` (or `lib/<name>/default.nix`) is `lib.<name>`, with a kebab-case file name as a camelCase attribute (`lib/db-nocow.nix` is `lib.dbNocow`), and `checks/<name>.nix` is `checks.<system>.<name>`. `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/<name>.nix` (or `lib/<name>/default.nix`) is `lib.<name>`, with a kebab-case file name as a camelCase attribute (`lib/db-nocow.nix` is `lib.dbNocow`), `packages/<name>.nix` is `packages.<system>.<name>`, and `checks/<name>.nix` is `checks.<system>.<name>`. `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.

Expand Down Expand Up @@ -106,6 +106,12 @@ Conventions: [Production](conventions.md#production), [Logging](conventions.md#l

Conventions: [Images](conventions.md#images).

## Packages

| Export | What it does |
| --- | --- |
| `packages.<system>.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 |
Expand Down
4 changes: 4 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
perSystem =
{ pkgs, ... }:
{
# packages/<name>.nix is `{ pkgs, … }: derivation`, called with callPackage,
# and becomes packages.<system>.<name>.
packages = lib.mapAttrs (_: path: pkgs.callPackage path { }) (entries ./packages);

# checks/<name>.nix is `{ pkgs, self }: derivation` and becomes
# checks.<system>.<name>. CI builds every one of them.
checks = lib.mapAttrs (_: path: import path { inherit pkgs self; }) (entries ./checks);
Expand Down
62 changes: 62 additions & 0 deletions packages/pdfkiln.nix
Original file line number Diff line number Diff line change
@@ -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";
};
}