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.
This commit is contained in:
@@ -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 <release> 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 <bin>/../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 ];
|
||||
};
|
||||
})
|
||||
Reference in New Issue
Block a user