Files
nixpkgs/pkgs/by-name/pd/pdfding/package.nix
2026-09-18 18:40:14 +02:00

201 lines
4.8 KiB
Nix

{
lib,
callPackage,
fetchFromCodeberg,
makeWrapper,
nixosTests,
python3,
}:
let
python = python3;
in
python.pkgs.buildPythonPackage (finalAttrs: {
pname = "pdfding";
version = "1.14.0";
src = fetchFromCodeberg {
owner = "mrmn";
repo = "PdfDing";
rev = "v${finalAttrs.version}";
hash = "sha256-yxDN6aFYRdrpDV7AdKeam1ZUcs5GTXU1fLaOHB7Mx8c=";
};
pyproject = true;
__structuredAttrs = true;
# remove supervisor from dependencies, we use systemd
postPatch = ''
sed -i 's/supervisor.*$//' pyproject.toml
'';
dependencies =
with python.pkgs;
[
django
django-allauth
django-cleanup
django-htmx
gunicorn
huey
markdown
minio
nh3
oauthlib
pillow
psycopg2-binary
pypdf
pypdfium2
python-magic
qrcode
rapidfuzz
ruamel-yaml
whitenoise
# dependencies required for django collectstatic
cryptography
pyjwt
requests
]
++ qrcode.optional-dependencies.pil
++ django-allauth.optional-dependencies.mfa
++ django-allauth.optional-dependencies.socialaccount;
build-system = with python.pkgs; [ poetry-core ];
nativeBuildInputs = [
makeWrapper
python.pkgs.pyprojectVersionPatchHook
];
optional-dependencies = {
e2e = with python.pkgs; [
pytest
pytest-django
pytest-playwright
pytest-rerunfailures # required to retry some flaky e2e tests
];
};
preBuild = ''
# remove originals, copy from frontend
rm -rf pdfding/static
ln -s ${finalAttrs.passthru.frontend}/pdfding/static pdfding/static
# staticfiles step requires prod configuration, remove dev.py
mv pdfding/core/settings/dev.py dev.py.bak
${python.pythonOnBuildForHost.interpreter} pdfding/manage.py collectstatic
# not needed, now we have staticfiles directory
rm -rf pdfding/static
# the following is from upstream's Dockerfile
# remove django md5 hash from filenames of pdfjs as it will mess up the relative imports because of the whitenoise setup
export PDFJS_PATH="pdfding/staticfiles/pdfjs"
for file_name in $(find $PDFJS_PATH -type f -not -path "$PDFJS_PATH/web/images/*")
do
if [[ $file_name =~ "LICENSE" ]]; then
new=$(echo "$file_name" | sed -E "s/LICENSE\.[a-zA-Z0-9]{12}/LICENSE/");
else
new=$(echo "$file_name" | sed -E "s/\.[a-zA-Z0-9]{12}\./\./");
fi;
mv -- "$file_name" "$new";
done \
&& echo 'Successfully removed hash from pdfjs files'
echo "VERSION = '${finalAttrs.version}'" > pdfding/core/settings/version.py;
'';
env.PDFDING_OUT_DIR = "${placeholder "out"}/${python.sitePackages}/pdfding";
makeWrapperArgs = [
"--set-default"
"DATA_DIR"
"/var/lib/pdfding"
# allow for gunicorn processes to have access to Python packages
"--prefix"
"PYTHONPATH"
":"
"${python.pkgs.makePythonPath finalAttrs.passthru.dependencies}:${finalAttrs.env.PDFDING_OUT_DIR}"
];
postInstall = ''
mkdir -p $out/bin
makeWrapper "$PDFDING_OUT_DIR/manage.py" $out/bin/pdfding-manage \
"''${makeWrapperArgs[@]}"
makeWrapper ${lib.getExe python.pkgs.gunicorn} $out/bin/pdfding-start \
--add-flags '--bind ''${HOST_IP:-127.0.0.1}:''${HOST_PORT:-8080} core.wsgi:application' \
"''${makeWrapperArgs[@]}"
'';
# NOTE: don't undo relaxing of any of these, they are bound to break again
pythonRelaxDeps = [
"django"
"django-allauth"
"gunicorn"
"huey"
"markdown"
"nh3"
"psycopg2-binary"
"pypdf"
"pypdfium2"
];
checkInputs = with python.pkgs; [
fido2
pytest-django
];
nativeCheckInputs = with python.pkgs; [
pytestCheckHook
];
# from .github/workflows/tests.yaml
pytestFlags = [ "--ignore=e2e" ];
preCheck = ''
# dev.py is required for tests, restore it
mv dev.py.bak $PDFDING_OUT_DIR/core/settings/dev.py
export DATA_DIR=$PWD/pdfding
# tests should run in pdfding directory
pushd pdfding
'';
postCheck = ''
# come out of the pdfding directory
popd
unset DATA_DIR
# remove dev.py
rm $PDFDING_OUT_DIR/core/settings/dev.py
'';
pythonImportsCheck = [
"pdfding"
];
passthru = {
inherit python;
tests = nixosTests.pdfding;
frontend = callPackage ./frontend.nix { };
updateScript = ./update.sh;
};
meta = {
changelog = "https://codeberg.org/mrmn/PdfDing/src/commit/${finalAttrs.src.rev}/CHANGELOG.md";
description = "Selfhosted PDF manager, viewer and editor offering a seamless user experience on multiple devices";
downloadPage = "https://codeberg.org/mrmn/PdfDing";
homepage = "https://pdfding.com";
license = lib.licenses.agpl3Only;
mainProgram = "pdfding-manage";
platforms = lib.platforms.unix;
teams = with lib.teams; [ ngi ];
};
})