nix-packages/packages/bookwyrm/package.nix

187 lines
3.3 KiB
Nix

{
fetchFromGitHub ,
pkgs ,
stdenv ,
} :
with builtins ;
with pkgs ;
with pkgs . kernelmaft . python ;
with pkgs . python311Packages ;
with stdenv ;
let
simplePythonDependencies = [
aiohappyeyeballs
aiohttp
aiosignal
amqp
asgiref
attrs
billiard
bleach
boto3
botocore
bw-file-resubmit
celery
certifi
cffi
chardet
click
colorthief
cron-descriptor
cryptography
deprecated
django
django-appconf
django-celery-beat
django-csp
django-imagekit
django-model-utils
django-oauth-toolkit
django-pgtrigger
django-sass-processor
django-storages
django-timezone-field
environs
frozenlist
googleapis-common-protos
grpcio
idna
importlib-metadata
jmespath
jwcrypto
kombu
libsass
markdown
marshmallow
multidict
oauthlib
packaging
pilkit
pillow
protobuf
psycopg2
pycryptodome
pyotp
python-crontab
python-dateutil
python-dotenv
qrcode
redis
requests
s3-tar
s3transfer
six
sqlparse
typing-extensions
urllib3
vine
webencodings
wrapt
yarl
] ;
in
mkDerivation {
pname = "bookwyrm" ;
version = "2025-02-14-ba1f180" ;
src = fetchFromGitea {
domain = "kernelmaft.com/forgejo" ;
owner = "zedfrigg" ;
repo = "bookwyrm" ;
rev = "4b433e285dbacfab7dad21159d6844d971d9d80a" ;
hash = "sha256-9HsaJisTVPqTpNoD155WhawYBtBlKQvG4Z72IxuDOCA=" ;
} ;
dontPatch = true ;
dontConfigure = true ;
buildPhase = ''
runHook preBuild
mkdir -p /build/lib/python3.11/site-packages
# Python dependencies
for dependency in ${ concatStringsSep " " simplePythonDependencies } ; do
ln -sf $dependency/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
done
export PYTHONPATH=/build/lib/python3.11/site-packages
export DOMAIN=""
export EMAIL=""
export EMAIL_HOST=""
export EMAIL_HOST_USER=""
export EMAIL_HOST_PASSWORD=""
export SECRET_KEY=""
${python311}/bin/python manage.py compile_themes
${python311}/bin/python manage.py collectstatic --no-input
runHook postBuild
'' ;
installPhase = ''
runHook preInstall
mkdir -p $out/bin
mkdir -p $out/lib/python3.11/site-packages
mkdir -p $out/srv/http/bookwyrm
mkdir -p $out/var/lib/bookwyrm
# Python dependencies
for dependency in ${ concatStringsSep " " simplePythonDependencies } ; do
ln -sf $dependency/lib/python3.11/site-packages/* $out/lib/python3.11/site-packages/
done
# Python packages
cp -r /build/source/bookwyrm $out/lib/python3.11/site-packages/
cp -r /build/source/celerywyrm $out/lib/python3.11/site-packages/
# Python scripts
cp /build/source/manage.py $out/lib/python3.11/
# Static web files
cp -r /build/source/static/* $out/srv/http/
# Executables
cat <<- EOF > $out/bin/bookwyrm
#!${bash}/bin/sh
exec ${gunicorn}/bin/gunicorn bookwyrm.wsgi:application --bind=unix:/run/bookwyrm/http-socket
EOF
cat <<- EOF > $out/bin/bookwyrm-env
#!${bash}/bin/sh
PATH=${coreutils-full}/bin
if [ \$( id -un ) != "bookwyrm" -o \$( id -gn ) != "bookwyrm" ] ; then
echo "You are not running as the 'bookwyrm' user and group, quitting"
exit 1
fi
export PYTHONPATH=$out/lib/python3.11/site-packages
export DEBUG=false
exec \$@
EOF
chmod +x $out/bin/*
# Working directory contents
cp $src/VERSION $out/var/lib/bookwyrm/
runHook postInstall
'' ;
}