nix-packages/packages/bookwyrm/package.nix

234 lines
6.7 KiB
Nix

{
fetchFromGitHub ,
pkgs ,
stdenv ,
} :
with builtins ;
with pkgs ;
with pkgs . kernelmaft . python ;
with pkgs . python311Packages ;
with stdenv ;
mkDerivation {
pname = "bookwyrm" ;
version = "2025-02-14-ba1f180" ;
src = fetchFromGitHub {
owner = "bookwyrm-social" ;
repo = "bookwyrm" ;
rev = "ba1f180c834e1b84d33e565abc3d95f772e2cdd8" ;
hash = "sha256-8e1+pfURTvzsWumRpeBZGDyD8UW1C98Vv9/1GqECLD4=" ;
} ;
dontPatch = true ;
dontConfigure = true ;
buildPhase = ''
runHook preBuild
mkdir -p /build/lib/python3.11/site-packages
ln -sf ${aiohttp}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${asgiref}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${attrs}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${bw-file-resubmit}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${celery}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${certifi}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${cffi}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${cryptography}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${django}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${django-celery-beat}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${django-imagekit}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${django-model-utils}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${django-oauth-toolkit}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${django-pgtrigger}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${django-sass-processor}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${django-storages}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${environs}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${idna}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${jwcrypto}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${libsass}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${marshmallow}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${multidict}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${oauthlib}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${packaging}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${pillow}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${psycopg2}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${python-dotenv}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${requests}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${sqlparse}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${typing-extensions}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${urllib3}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
ln -sf ${yarl}/lib/python3.11/site-packages/* /build/lib/python3.11/site-packages/
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
runHook postBuild
'' ;
installPhase = let
pythonDependencies = [
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
opentelemetry-api
opentelemetry-exporter-otlp-proto-common
opentelemetry-exporter-otlp-proto-grpc
opentelemetry-proto
opentelemetry-sdk
opentelemetry-semantic-conventions
packaging
pilkit
pillow
protobuf
psycopg2
pycryptodome
pyotp
python-crontab
python-dateutil
python-dotenv
qrcode # I.e. python311Packages . qrcode
redis # I.e. python311Packages . redis
requests
s3-tar
s3transfer
six
sqlparse
typing-extensions
urllib3
vine
webencodings
wrapt
yarl
] ;
in ''
runHook preInstall
mkdir -p $out/bin
mkdir -p $out/lib/python3.11/site-packages
mkdir -p $out/var/lib/bookwyrm
# Python dependencies
pythonDependencies="${ concatStringsSep " " pythonDependencies }"
for package in $pythonDependencies ; do
for directory in $( cd $package/lib/python3.11/site-packages ; find -mindepth 1 -type d -not -name __pycache__ ) ; do
mkdir -p $out/lib/python3.11/site-packages/$directory &
done
done
wait
for package in $pythonDependencies ; do
for file in $( cd $package/lib/python3.11/site-packages ; find -type f -not -path \*__pycache__\* ) ; do
ln -s $package/lib/python3.11/site-packages/$file $out/lib/python3.11/site-packages/$file &
done
done
wait
# Python packages
cp -r $src/bookwyrm $out/lib/python3.11/site-packages/
cp -r $src/celerywyrm $out/lib/python3.11/site-packages/
# Python scripts
cp $src/manage.py $out/lib/python3.11/
# 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"
export DOMAIN=""
export EMAIL=""
export EMAIL_HOST=""
export EMAIL_HOST_USER=""
export EMAIL_HOST_PASSWORD=""
# The escape here is required in order to retrieve the key file contents at runtime
export SECRET_KEY="\$( cat /etc/nixos/assets/bookwyrm-secret-key )"
exec \$@
EOF
chmod +x $out/bin/*
# Working directory contents
cp $src/VERSION $out/var/lib/bookwyrm/
runHook postInstall
'' ;
}