From 43199e5b8ba98116134faa491e2dbc3d6bf720ed Mon Sep 17 00:00:00 2001 From: Alexander Miroshnichenko Date: Tue, 3 Nov 2026 13:48:55 +0300 Subject: [PATCH] feat(pdfcraft): add PdfCraft 0.18.0 built from source Packages the storytold/pdfcraft Cargo workspace at tag v0.18.0: the pdfcraft desktop app and pdfcraft-cli, with the desktop entry, AppStream metadata, icons, licences and the two CC-BY-SA OCR models the app reads from share/pdfcraft/models. No upstream binaries are downloaded. Two deviations from upstream's build instructions: - The three [patch.crates-io] entries upstream's own Cargo.lock records as [[patch.unused]] (egui_demo_lib, egui_inspection, egui_system_font_provider) have no package in nixpkgs' partial vendor tree to resolve against, so cargo aborts. postPatch drops them; they are unused, and cargo drops the matching lock entries itself, so the build runs without --locked. - nixos-unstable's rustc 1.98.1 and 1.99.0 reject every AVX-VNNI intrinsic ("intrinsic signature mismatch for llvm.x86.avx512.vpdpbusd/vpwssd"), and rten-gemm, pic-scale and zlib-rs all use one. The package therefore builds against a new nixpkgs-rust195 input (nixos-26.05, rustc 1.95.0), the same pattern as nixpkgs-torch211. Follow-up: nix-overlay-g4w. Also adds a Home Manager module (programs.pdfcraft) to homeManagerModules.default, and documents both in the README. --- .beads/issues.jsonl | 2 + README.md | 25 +++++ flake.lock | 17 ++++ flake.nix | 11 ++- modules/pdfcraft-hm.nix | 33 +++++++ packages/pdfcraft/default.nix | 9 ++ packages/pdfcraft/package.nix | 171 ++++++++++++++++++++++++++++++++++ 7 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 modules/pdfcraft-hm.nix create mode 100644 packages/pdfcraft/default.nix create mode 100644 packages/pdfcraft/package.nix diff --git a/.beads/issues.jsonl b/.beads/issues.jsonl index 8779ba1..4b482c2 100644 --- a/.beads/issues.jsonl +++ b/.beads/issues.jsonl @@ -2,6 +2,7 @@ {"_type":"issue","id":"nix-overlay-1ah","title":"omniroute: bump 3.8.50 -\u003e 3.8.51 once npmDepsHash is recomputed","description":"Upstream v3.8.51 changes both package.json and package-lock.json, so the version bump needs a new npmDepsHash (and the src + npmTarball hashes, which are already computed: src sha256-ZYRjwynEw3cziFp8tM483QN96mDH0ZuHCFuhcJDwelA=, npm tgz sha256-QhaZ/do0vYW88DUlfojjWe3AM8AbhdVLakkhwc2k0u8=). Left at 3.8.50 because computing the hash requires running the npm-deps prefetch (build) and the host was low on disk (24G free, 95% used) and swap. Run: nix-update --flake --version=3.8.51 omniroute, which will recompute all three hashes in one pass.","status":"open","priority":3,"issue_type":"task","owner":"alex@millerson.name","created_at":"2026-10-06T13:46:38Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-10-06T13:46:38Z","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"nix-overlay-2fk","title":"marmel: bump d6627d7 (1.0.0) -\u003e 3f238ff (main)","description":"Update packages/marmel to the latest upstream main commit 3f238ff217ee2e1033c937c840bd2d33ec57abc4 (feat: add per-role reasoning_effort configuration, #12). Verify src/hash, cargoHash, and whether the Landlock ro_paths fix landed (see nix-overlay-5ml) so the cargoTestFlags skips can be dropped or kept.","status":"closed","priority":2,"issue_type":"task","assignee":"Alexander Miroshnichenko","owner":"alex@millerson.name","created_at":"2026-10-16T09:30:54Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-10-16T10:25:09Z","started_at":"2026-10-16T09:30:59Z","closed_at":"2026-10-16T10:25:09Z","close_reason":"Closed","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"nix-overlay-2gf","title":"Update all packages to latest versions","description":"## Why\\nUser request: update every package in the overlay to its latest upstream version.\\n\\n## What\\nBump version + src hash (and cargoHash for Rust) in each packages/\u003cname\u003e/package.nix, update README table if needed, verify builds.\\n\\n## Acceptance\\n- Every package builds with nix build .#\u003cname\u003e\\n- README reflects new versions\\n- Changes committed and pushed","notes":"All packages updated and built successfully. Commit 1f3f0f468bdd on local main. PUSH BLOCKED: git.millerson.name:22002 and DoltHub unreachable from this network (SSH connect timeout). Re-run git push + bd dolt push when network is back, then close.","status":"closed","priority":2,"issue_type":"task","assignee":"Alexander Miroshnichenko","owner":"alex@millerson.name","created_at":"2026-08-07T07:22:50Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-08-07T13:17:34Z","started_at":"2026-08-07T07:22:55Z","closed_at":"2026-08-07T13:17:34Z","close_reason":"All packages updated to latest versions, verified building, pushed to origin","dependency_count":0,"dependent_count":0,"comment_count":0} +{"id":"nix-overlay-3sa","title":"pdfcraft: add PdfCraft 0.18.0 (build from source)","description":"Add packages/pdfcraft building the storytold/pdfcraft Rust workspace from source (no pre-compiled binaries): desktop app + pdfcraft-cli, desktop entry, icons, metainfo, OCR models. Plus a Home Manager module.","status":"closed","priority":2,"issue_type":"feature","assignee":"minder","created_at":"2026-11-03T08:31:41.141131190Z","created_by":"minder","updated_at":"2026-11-03T10:48:31.465220459Z","closed_at":"2026-11-03T10:48:31.464736388Z","close_reason":"nix build .#packages.x86_64-linux.pdfcraft succeeds; pdfcraft/pdfcraft-cli 0.18.0 run, pdfcraft-cli render+info+extract work on a test PDF, mcp initialize answers, ocr_status reports available:true, desktop-file-validate clean, home-manager eval picks the package up from programs.pdfcraft.enable","source_repo":"nix-overlay","compaction_level":0,"original_size":0} {"_type":"issue","id":"nix-overlay-51o","title":"marmel: bump 3f238ff -\u003e 981b35b (main)","description":"Update packages/marmel to latest upstream main commit 981b35b0d356e56de429ab4198e427ccfbe7d85f. Verify src hash, cargoHash, whether patches (landlock-nix-store.patch #14, session-boot-trust-store.patch) still apply / whether follow-ups nix-overlay-pnb / nix-overlay-nn2 can close, and whether the sandbox test skip is still needed.","status":"closed","priority":2,"issue_type":"task","assignee":"Alexander Miroshnichenko","owner":"alex@millerson.name","created_at":"2026-10-18T11:25:08Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-10-18T11:53:11Z","started_at":"2026-10-18T11:25:13Z","closed_at":"2026-10-18T11:53:11Z","close_reason":"Bumped packages/marmel to 981b35b (main), hash regenerated, full build+tests green (1030+ tests).","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"nix-overlay-570","title":"radar: ensure package builds without error","description":"Verify nix build .#radar succeeds; fix any build failures.","status":"closed","priority":2,"issue_type":"task","assignee":"Alexander Miroshnichenko","owner":"alex@millerson.name","created_at":"2026-10-06T16:51:35Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-10-06T17:02:59Z","started_at":"2026-10-06T16:51:40Z","closed_at":"2026-10-06T17:02:59Z","close_reason":"Closed","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"nix-overlay-5gg","title":"freetoken: optional accel extras and kernel-cache wheel","description":"Follow-ups for the freetoken package: (1) package flashinfer[cu12] and sglang-kernel 0.4.5 (accel extra) so the native fast path is available instead of the Triton fallback; (2) package the freetoken-kernel-cache companion wheel (prebuilt TVM FFI kernels, built via scripts/build-release-wheels.sh) so TVM JIT kernel compilation (nvcc at runtime) can be avoided. Both blocked on suitable PyPI/CUDA packaging work in nixpkgs (flashinfer exists in nixpkgs but needs cu12 variant). Priority: backlog.","status":"open","priority":3,"issue_type":"task","owner":"alex@millerson.name","created_at":"2026-08-30T17:58:57Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-08-30T17:58:57Z","dependency_count":0,"dependent_count":0,"comment_count":0} @@ -21,6 +22,7 @@ {"id":"nix-overlay-e2b","title":"awgen: bump 0.2 -> 0.3","description":"Upstream tag v0.3 exists at git.millerson.name/alex/awgen (commit 3d10c5f). Bump version + src/cargo hashes in packages/awgen/package.nix and verify nix build .#awgen.","status":"closed","priority":2,"issue_type":"task","assignee":"pi","created_at":"2026-10-25T13:58:22.504514222Z","created_by":"minder","updated_at":"2026-10-25T14:06:10.968003613Z","closed_at":"2026-10-25T14:06:10.966719541Z","close_reason":"Completed: awgen pinned to v0.3 (src sha256-86YT...), cargoHash unchanged (Cargo.lock deps identical). nix build .#awgen green, cargo checkPhase 29 passed/0 failed; result/bin/awgen runs.","source_repo":"nix-overlay","compaction_level":0,"original_size":0} {"_type":"issue","id":"nix-overlay-ez7","title":"marmel: Landlock sandbox-exec tests fail in the Nix build sandbox","description":"Both harness::sandbox::tests::test_internal_sandbox_* tests re-exec sh through marmel --internal-sandbox-exec. Upstream apply_landlock_linux() allow-lists FHS paths only (/usr /bin /lib /opt /etc /var ...), never /nix/store, and PathFd() silently skips paths missing in the sandbox. Inside the Nix sandbox PATH points at /nix/store/-bash/bin and /nix/store/-coreutils/bin, so exec is denied: 'Failed to exec shell in sandbox: Permission denied (os error 13)'. Not a code defect: on a real NixOS host sh resolves through /bin -\u003e system path which the /bin rule covers.","status":"closed","priority":2,"issue_type":"task","assignee":"Alexander Miroshnichenko","owner":"alex@millerson.name","created_at":"2026-10-06T18:58:44Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-10-06T19:31:56Z","started_at":"2026-10-06T18:59:02Z","closed_at":"2026-10-06T19:31:56Z","close_reason":"Skipped both sandbox-exec tests in packages/marmel; nix build .#marmel green (342/344 run). Runtime defect split out to nix-overlay-5ml.","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"nix-overlay-f8c","title":"Add nftablesbuilder package","description":"Package NftablesBuilder (github.com/AiseBouma/NftablesBuilder) web interface to manage nftables. Upstream source is incomplete (missing settings crate, no GUI build tooling, no Cargo.lock) so: patch in authored settings crate (schema from release artifacts), build Rust workspace from pinned commit, reuse built GUI assets from hash-pinned release tarball.","status":"closed","priority":2,"issue_type":"task","assignee":"Alexander Miroshnichenko","owner":"alex@millerson.name","created_at":"2026-08-07T04:58:22Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-08-07T05:38:40Z","started_at":"2026-08-07T04:58:25Z","closed_at":"2026-08-07T05:38:40Z","close_reason":"Package added, builds green, committed","dependency_count":0,"dependent_count":0,"comment_count":0} +{"id":"nix-overlay-g4w","title":"pdfcraft: drop nixpkgs-rust195 pin once nixos-unstable rustc assembles AVX-VNNI again","description":"nixos-unstable's rustc 1.98.1/1.99.0 (LLVM 21.1.8) rejects every AVX-VNNI intrinsic with 'intrinsic signature mismatch for llvm.x86.avx512.vpdpbusd/vpwssd', which breaks rten-gemm, pic-scale and zlib-rs. pdfcraft therefore builds against inputs.nixpkgs-rust195 (nixos-26.05, rustc 1.95.0) in packages/pdfcraft/default.nix. Re-test with: rustc -O on a snippet calling _mm512_dpbusd_epi32; when nixos-unstable's rustc compiles it, delete the input and revert default.nix to pkgs.callPackage.","status":"open","priority":3,"issue_type":"task","created_at":"2026-11-03T10:48:09.706576343Z","created_by":"minder","updated_at":"2026-11-03T10:48:09.706576343Z","source_repo":"nix-overlay","compaction_level":0,"original_size":0} {"_type":"issue","id":"nix-overlay-hcf","title":"Update all overlay packages to latest upstream versions","description":"Bump every package in packages/ to its latest upstream release/commit using nix-update, then verify each builds. Working tree already carries uncommitted bumps for 15 packages (awg-tool, ds4, freebuff, freetoken, g3, graphify, hipengine, kubernetes-mcp-server, llama-cpp, marmel, omniroute, open-code-review, radar, skillsmcp, traycer); remaining packages (aionui, container-use, desloppify, haivemind, loop, mcp-gateway, nftables-analyzer, nftablesbuilder, relay-free-llm, shardr, stakpak) still need checking.","status":"closed","priority":2,"issue_type":"task","assignee":"Alexander Miroshnichenko","owner":"alex@millerson.name","created_at":"2026-10-06T12:54:12Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-10-06T13:46:41Z","started_at":"2026-10-06T12:54:20Z","closed_at":"2026-10-06T13:46:41Z","close_reason":"All 26 packages checked: 16 committed in 6013b17aadbc; aionui/container-use/desloppify/loop/mcp-gateway/nftables-analyzer/nftablesbuilder/relay-free-llm/stakpak already current; 3 evaluation/version-string errors from nix-update repaired by hand. omniroute deferred to its own issue (stale npmDepsHash).","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"nix-overlay-ikz","title":"Add g3 package (dhanji/g3)","description":"Package g3 AI coding agent from https://github.com/dhanji/g3 as rustPlatform.buildRustPackage. Pin commit (no tags), ship g3 + g3-studio binaries, category AI Coding Agents.","status":"closed","priority":2,"issue_type":"feature","assignee":"Alexander Miroshnichenko","owner":"alex@millerson.name","created_at":"2026-09-23T10:59:57Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-09-23T11:54:07Z","started_at":"2026-09-23T11:00:30Z","closed_at":"2026-09-23T11:54:07Z","close_reason":"Closed","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"nix-overlay-m5y","title":"Add CodeAF package (Agent-Field/CodeAF)","description":"Add https://github.com/Agent-Field/CodeAF as a new package under packages/codeaf with default.nix + package.nix, staged for blueprint discovery, README table updated, nix build verified.","status":"closed","priority":2,"issue_type":"feature","assignee":"Alexander Miroshnichenko","owner":"alex@millerson.name","created_at":"2026-10-06T18:07:38Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-10-06T18:46:34Z","started_at":"2026-10-06T18:08:19Z","closed_at":"2026-10-06T18:46:34Z","close_reason":"Closed","dependency_count":0,"dependent_count":0,"comment_count":0} diff --git a/README.md b/README.md index 002b23d..e9ff6db 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ A custom Nix overlay and flake providing additional packages not found in upstre | `omniroute` | Unified AI router with 160+ providers, auto fallback, MCP/A2A, OpenAI-compatible APIs | AI LLM Gateway | | `open-code-review` | AI-powered code review CLI combining deterministic pipelines with an LLM agent for line-level review comments | AI Coding Agents | | `pilotdeck` | Task-oriented AI Agent productivity platform (source-built Electron desktop app, plus a headless server command) with WorkSpace isolation, white-box memory, and smart routing | AI Agents | +| `pdfcraft` | PDF reader and editor written from scratch in Rust — comments, forms, page organizing, redaction — plus a headless `pdfcraft-cli` with an opt-in MCP server | PDF Tools | | `relay-free-llm` | RESTful API to route user prompts to various AI model providers with automatic failover and intent-based routing | AI LLM Gateway | | `stakpak` | DevOps AI agent that generates infrastructure code, debugs Kubernetes, configures CI/CD, and automates deployments | AI Agents | | `traycer` | Open-source AI orchestration app for agentic coding | AI Coding Agents | @@ -181,6 +182,29 @@ Note: the `node_modules` symlink is shared across everything in the plugins directory; other manually-installed plugins with conflicting npm dependencies cannot coexist with it. +### PdfCraft (Home Manager) + +`pdfcraft` is built from source (no upstream binaries are downloaded). A Home +Manager module installs both programs it ships: + +```nix +# in your home-manager configuration +imports = [ millerson-nix-overlay.homeManagerModules.default ]; + +programs.pdfcraft.enable = true; +``` + +That puts `pdfcraft` (the desktop app) and `pdfcraft-cli` (headless tool +runner and the opt-in MCP server, `pdfcraft-cli mcp`) on PATH. The module adds +`programs.pdfcraft.package` to `home.packages`; the default is +`pkgs.millerson-nix-overlay.pdfcraft`, so `nixpkgs.overlays` must carry this +flake's overlay, or set `package` yourself. + +The package ships the two OCR models under `share/pdfcraft/models`, where the +app looks beside its own `bin/` — `pdfcraft-cli run ocr_status` reports +`"available": true`. The optional `craft-fonts` build input is not used, so +Japanese interface text falls back to an installed system font. + ## Development ### Prerequisites @@ -233,6 +257,7 @@ nix-overlay/ │ ├── omniroute/ # Unified AI router with 160+ providers │ ├── open-code-review/ # AI code review CLI (deterministic + LLM agent) │ ├── pilotdeck/ # Task-oriented AI Agent platform (source-built Electron desktop app) +│ ├── pdfcraft/ # PDF reader and editor in Rust, with pdfcraft-cli │ ├── radar/ # Kubernetes UI (topology, timeline, Helm, GitOps) │ ├── relay-free-llm/ # AI model provider routing gateway │ ├── skillsmcp/ # MCP server for Agent Skills diff --git a/flake.lock b/flake.lock index 075aab9..9842298 100644 --- a/flake.lock +++ b/flake.lock @@ -105,6 +105,22 @@ "type": "github" } }, + "nixpkgs-rust195": { + "locked": { + "lastModified": 1793633738, + "narHash": "sha256-tItrb9M8eYA6WhFgmT9tpGKueri3+wRuVA952o/2xSU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7dcdd87373d72e7a2173e4db02e20d3d7f495cfd", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-26.05", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs-torch211": { "locked": { "lastModified": 1777954456, @@ -128,6 +144,7 @@ "flake-parts": "flake-parts", "nixpkgs": "nixpkgs", "nixpkgs-latest": "nixpkgs-latest", + "nixpkgs-rust195": "nixpkgs-rust195", "nixpkgs-torch211": "nixpkgs-torch211", "systems": "systems", "treefmt-nix": "treefmt-nix" diff --git a/flake.nix b/flake.nix index 1882e1e..51dd652 100644 --- a/flake.nix +++ b/flake.nix @@ -11,6 +11,12 @@ # nixpkgs revision for freetoken so its CUDA 12.9 / torch 2.11 stack is # unchanged. nixpkgs-torch211.url = "github:NixOS/nixpkgs/549bd84d6279f9852cae6225e372cc67fb91a4c1"; + # nixos-unstable's Rust 1.98/1.99 cannot assemble AVX-VNNI intrinsics: every call to + # _mm512_dpbusd_epi32 / _mm512_dpwssd_epi32 / _mm*_dpwssd_avx_epi32 fails with + # "intrinsic signature mismatch for llvm.x86.avx512.vpdp*" against its LLVM 21.1.8. pdfcraft + # needs rustc >= 1.95 and pulls that instruction in through rten-gemm, pic-scale and zlib-rs, so + # it builds against stable's 1.95.0, which assembles them fine. + nixpkgs-rust195.url = "github:NixOS/nixpkgs/nixos-26.05"; systems.url = "github:nix-systems/default"; blueprint = { url = "github:numtide/blueprint"; @@ -59,7 +65,10 @@ }; homeManagerModules.default = { - imports = [ ./modules/open-code-review-hm.nix ]; + imports = [ + ./modules/open-code-review-hm.nix + ./modules/pdfcraft-hm.nix + ]; }; }; } diff --git a/modules/pdfcraft-hm.nix b/modules/pdfcraft-hm.nix new file mode 100644 index 0000000..6aabd8d --- /dev/null +++ b/modules/pdfcraft-hm.nix @@ -0,0 +1,33 @@ +# Home Manager module: installs PdfCraft and its command-line tool. +# +# The package puts both `pdfcraft` (the desktop app) and `pdfcraft-cli` (headless runner and +# opt-in MCP server) on PATH, and its icons, desktop entry and AppStream metadata in +# $out/share, which a NixOS system profile or an XDG_DATA_DIRS that covers ~/.nix-profile/share +# shows in the application launcher. +{ + config, + lib, + pkgs, + ... +}: + +let + cfg = config.programs.pdfcraft; +in +{ + options.programs.pdfcraft = { + enable = lib.mkEnableOption "PdfCraft PDF workbench and its pdfcraft-cli tool"; + + package = lib.mkOption { + type = lib.types.package; + # The flake's overlay keeps its packages under the `millerson-nix-overlay` namespace. + default = pkgs.millerson-nix-overlay.pdfcraft or pkgs.pdfcraft; + defaultText = lib.literalExpression "pkgs.millerson-nix-overlay.pdfcraft or pkgs.pdfcraft"; + description = "The pdfcraft package to use."; + }; + }; + + config = lib.mkIf cfg.enable { + home.packages = [ cfg.package ]; + }; +} diff --git a/packages/pdfcraft/default.nix b/packages/pdfcraft/default.nix new file mode 100644 index 0000000..36d795f --- /dev/null +++ b/packages/pdfcraft/default.nix @@ -0,0 +1,9 @@ +{ + pkgs, + inputs, + ... +}: +# Built against nixpkgs-rust195 (see flake.nix): its rustc 1.95.0 assembles the AVX-VNNI +# instructions rten-gemm, pic-scale and zlib-rs use, which nixos-unstable's rustc 1.98/1.99 rejects. +inputs.nixpkgs-rust195.legacyPackages.${pkgs.stdenv.hostPlatform.system}.callPackage ./package.nix + { } diff --git a/packages/pdfcraft/package.nix b/packages/pdfcraft/package.nix new file mode 100644 index 0000000..d00f15f --- /dev/null +++ b/packages/pdfcraft/package.nix @@ -0,0 +1,171 @@ +{ + lib, + stdenv, + fetchFromGitHub, + fetchurl, + rustPlatform, + makeWrapper, + pkg-config, + # winit, wgpu, egui_glow and rfd load these by SONAME at runtime; the binaries themselves link + # only glibc and libgcc_s (upstream's packaging/linux/nfpm.yaml says the same), so they merely + # have to be reachable by the dynamic loader. + libGL, + libx11, + libxcursor, + libxi, + libxrandr, + libxxf86vm, + libxkbcommon, + libxcb, + vulkan-loader, + wayland, +}: +let + appId = "ai.storyteller.pdfcraft"; + + # Upstream substitutes the build date into the AppStream entry. The Nix build date is + # SOURCE_DATE_EPOCH (1980-01-01), so the tagged release date is used instead. + releaseDate = "2026-11-02"; + + runtimeLibs = [ + libGL + libx11 + libxcursor + libxi + libxrandr + libxxf86vm + libxkbcommon + libxcb + vulkan-loader + wayland + ]; + + # The "Scan & OCR" models, from ATTRIBUTION.toml ([[fetched]] kind = "model"). The app looks for + # them in /../share/pdfcraft/models, which is also where upstream's deb/rpm/tarball put + # them; without them the feature is silently unavailable. + ocrModels = map (m: m // { src = fetchurl { inherit (m) url hash; }; }) [ + { + file = "text-detection.onnx"; + title = "Ocrs text detection model"; + url = "https://ocrs-models.s3-accelerate.amazonaws.com/text-detection.onnx"; + hash = "sha256-qReyPb2VJLRl336SJkGz/ymBYj303tWgI0AE7y/ufP4="; + } + { + file = "text-recognition.onnx"; + title = "Ocrs text recognition model"; + url = "https://ocrs-models.s3-accelerate.amazonaws.com/text-recognition.onnx"; + hash = "sha256-hsFFwu25bIyu1bHruPRNcGQIkiIRRRwwnGJRV91gYcU="; + } + ]; + + ocrModelLicenceUrl = "https://creativecommons.org/licenses/by-sa/4.0/legalcode.txt"; + + ocrModelLicence = fetchurl { + url = ocrModelLicenceUrl; + hash = "sha256-KKlSnH0LtNxR9L9cEWo9Fu8kegUvdZFGZ2jd9WP9HPU="; + }; + + # CC-BY-SA-4.0 requires attribution; upstream ships this file next to the models. + ocrModelAttribution = builtins.toFile "ATTRIBUTION.txt" ( + '' + PdfCraft's text recognition (Scan & OCR) uses these models, unmodified. + '' + + lib.concatMapStrings (m: '' + + ${m.file} + ${m.title} + by Robert Knight (ocrs-models; trained on HierText, CC-BY-SA-4.0) + from ${m.url} + licence: CC-BY-SA-4.0 (${ocrModelLicenceUrl}; full text in ${m.file}.LICENCE.txt) + '') ocrModels + ); +in +rustPlatform.buildRustPackage (finalAttrs: { + pname = "pdfcraft"; + version = "0.18.0"; + + src = fetchFromGitHub { + owner = "storytold"; + repo = "pdfcraft"; + rev = "v${finalAttrs.version}"; + hash = "sha256-agLr61nG0/s786ZYj2AS2uw8hhH7a20TcCEjedHyygk="; + }; + + cargoHash = "sha256-fE6KX6KMyc22kdiJiqJLnCnVXTxHNWlhtEf/0vqCf88="; + + # The nixpkgs cargo vendor tree mirrors only the packages the dependency graph resolves to, so + # the three `[patch.crates-io]` entries that upstream's own Cargo.lock records as + # `[[patch.unused]]` have no package to resolve against and cargo stops with "patch location ... + # does not contain packages matching ...". Dropping them leaves the graph untouched, which is + # what `[[patch.unused]]` says they are, and cargo then drops the stale lock entries itself. + # Cargo.lock itself must stay untouched here: buildRustPackage rejects a patched lock, because + # its vendor tree was fetched against the original one. + postPatch = '' + sed -i '/^\(egui_demo_lib\|egui_inspection\|egui_system_font_provider\) = { git = "https:\/\/github.com\/storytold\/egui\.git"/d' Cargo.toml + ''; + + # Only the two binaries upstream's Linux packages ship; the workspace default-members would also + # build xtask and the WebAssembly app. No --locked: the patch above makes cargo drop the lock + # entries it no longer has patches for. Resolution stays offline against the vendor tree, so the + # versions cannot drift. + cargoBuildFlags = [ + "-p" + "pdfcraft" + "-p" + "pdfcraft-cli" + ]; + + nativeBuildInputs = [ + makeWrapper + pkg-config + ]; + + buildInputs = lib.optionals stdenv.hostPlatform.isLinux runtimeLibs; + + # The suite is 400+ unit, property and UI-snapshot tests, and the corpus sweeps need the + # pdf.js corpus plus assets/models, which upstream fetches in its own CI. + doCheck = false; + + postInstall = '' + install -Dm644 packaging/linux/${appId}.desktop \ + $out/share/applications/${appId}.desktop + install -Dm644 packaging/linux/${appId}.metainfo.xml.in \ + $out/share/metainfo/${appId}.metainfo.xml + substituteInPlace $out/share/metainfo/${appId}.metainfo.xml \ + --replace-fail '@VERSION@' '${finalAttrs.version}' \ + --replace-fail '@DATE@' '${releaseDate}' + mkdir -p $out/share/icons + cp -r assets/app-icon/hicolor $out/share/icons/ + install -Dm644 LICENSE-MIT -t $out/share/doc/pdfcraft + install -Dm644 LICENSE-APACHE -t $out/share/doc/pdfcraft + install -Dm644 NOTICE -t $out/share/doc/pdfcraft + install -Dm644 ATTRIBUTION.md -t $out/share/doc/pdfcraft + install -Dm644 ${ocrModelAttribution} $out/share/pdfcraft/models/ATTRIBUTION.txt + '' + + lib.concatMapStrings (m: '' + install -Dm644 ${m.src} $out/share/pdfcraft/models/${m.file} + install -Dm644 ${ocrModelLicence} $out/share/pdfcraft/models/${m.file}.LICENCE.txt + '') ocrModels; + + postFixup = lib.optionalString stdenv.hostPlatform.isLinux '' + wrapProgram $out/bin/pdfcraft \ + --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath runtimeLibs}" + ''; + + passthru.category = "PDF Tools"; + + meta = { + description = "PDF reader and editor written from scratch in Rust, with a headless CLI and MCP server"; + homepage = "https://getartcraft.com/apps/pdfcraft"; + changelog = "https://github.com/storytold/pdfcraft/releases/tag/v${finalAttrs.version}"; + license = with lib.licenses; [ + mit + asl20 + ]; + mainProgram = "pdfcraft"; + # macOS and Windows are supported upstream, but this derivation only handles the Linux + # runtime libraries, desktop entry and windowing libs. + platforms = lib.platforms.linux; + sourceProvenance = [ lib.sourceTypes.fromSource ]; + }; +})