nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 python3Packages,
4 fetchzip,
5 writeScript,
6}:
7
8python3Packages.buildPythonApplication rec {
9 pname = "pdf-parser";
10 version = "0.7.10";
11 pyproject = false;
12
13 src = fetchzip {
14 url = "https://didierstevens.com/files/software/pdf-parser_V${
15 lib.replaceStrings [ "." ] [ "_" ] version
16 }.zip";
17 hash = "sha256-RhgEGue3RcALjLXKOnnXyx/0subXHNuXfDg8hbO3VDg=";
18 };
19
20 postPatch = ''
21 # quote regular expressions correctly
22 substituteInPlace pdf-parser.py \
23 --replace-fail \
24 "re.sub('" \
25 "re.sub(r'" \
26 --replace-fail \
27 "re.match('" \
28 "re.match(r'"
29 '';
30
31 installPhase = ''
32 install -Dm555 pdf-parser.py $out/bin/pdf-parser.py
33 '';
34
35 preFixup = ''
36 substituteInPlace $out/bin/pdf-parser.py \
37 --replace-fail '/usr/bin/python' '${python3Packages.python}/bin/python'
38 '';
39
40 passthru.updateScript = writeScript "update-pdf-parser" ''
41 #!/usr/bin/env nix-shell
42 #!nix-shell -i bash -p common-updater-scripts curl pcre2
43
44 set -eu -o pipefail
45
46 version="$(curl -s https://blog.didierstevens.com/programs/pdf-tools/ |
47 pcre2grep -O '$1.$2.$3' '\bpdf-parser_V(\d+)_(\d+)_(\d+)\.zip\b.*')"
48
49 update-source-version "$UPDATE_NIX_ATTR_PATH" "$version"
50 '';
51
52 meta = {
53 description = "Parse a PDF document";
54 longDescription = ''
55 This tool will parse a PDF document to identify the fundamental elements used in the analyzed file.
56 It will not render a PDF document.
57 '';
58 homepage = "https://blog.didierstevens.com/programs/pdf-tools/";
59 license = lib.licenses.publicDomain;
60 maintainers = [ lib.maintainers.lightdiscord ];
61 platforms = lib.platforms.all;
62 mainProgram = "pdf-parser.py";
63 };
64}