nix-packages/packages/bookwyrm/package.nix

220 lines
4.6 KiB
Nix
Raw Normal View History

2025-03-03 21:03:41 +01:00
{
fetchFromGitHub ,
pkgs ,
stdenv ,
} :
with builtins ;
with pkgs ;
2025-03-03 21:03:41 +01:00
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
] ;
overlappingPythonDependencies = [
{ package = opentelemetry-api ; subDirectory = "opentelemetry" ; }
{ package = opentelemetry-exporter-otlp-proto-common ; subDirectory = "opentelemetry/exporter/otlp/proto" ; }
{ package = opentelemetry-exporter-otlp-proto-grpc ; subDirectory = "opentelemetry/exporter/otlp/proto" ; }
{ package = opentelemetry-proto ; subDirectory = "opentelemetry" ; }
{ package = opentelemetry-sdk ; subDirectory = "opentelemetry" ; }
{ package = opentelemetry-semantic-conventions ; subDirectory = "opentelemetry" ; }
] ;
in
2025-03-03 21:03:41 +01:00
mkDerivation {
pname = "bookwyrm" ;
version = "2025-02-14-ba1f180" ;
2025-03-10 18:00:59 +01:00
src = fetchFromGitea {
2025-03-10 17:58:28 +01:00
domain = "kernelmaft.com/forgejo" ;
owner = "zedfrigg" ;
2025-03-03 21:03:41 +01:00
repo = "bookwyrm" ;
rev = "ba1f180c834e1b84d33e565abc3d95f772e2cdd8" ;
2025-03-10 17:58:28 +01:00
hash = "" ;
2025-03-03 21:03:41 +01:00
} ;
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
${ concatStringsSep "\n" ( map ( dependency : ''
mkdir -p /build/lib/python3.11/site-packages/${ dependency . subDirectory }
ln -s ${ dependency . package }/lib/python3.11/site-packages/${ dependency . subDirectory }/* \
/build/lib/python3.11/site-packages/${ dependency . subDirectory }/
'' ) overlappingPythonDependencies ) }
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=""
# Compile SASS
${python311}/bin/python manage.py compile_themes || true
runHook postBuild
'' ;
2025-03-03 21:03:41 +01:00
installPhase = ''
2025-03-03 21:03:41 +01:00
runHook preInstall
mkdir -p $out/bin
2025-03-03 21:03:41 +01:00
mkdir -p $out/lib/python3.11/site-packages
mkdir -p $out/var/lib/bookwyrm
2025-03-03 21:03:41 +01:00
# Python dependencies
for dependency in ${ concatStringsSep " " simplePythonDependencies } ; do
ln -sf $dependency/lib/python3.11/site-packages/* $out/lib/python3.11/site-packages/
done
2025-03-03 21:03:41 +01:00
${ concatStringsSep "\n" ( map ( dependency : ''
mkdir -p $out/lib/python3.11/site-packages/${ dependency . subDirectory }
ln -s ${ dependency . package }/lib/python3.11/site-packages/${ dependency . subDirectory }/* \
$out/lib/python3.11/site-packages/${ dependency . subDirectory }/
'' ) overlappingPythonDependencies ) }
# Python packages
2025-03-03 21:03:41 +01:00
cp -r $src/bookwyrm $out/lib/python3.11/site-packages/
cp -r $src/celerywyrm $out/lib/python3.11/site-packages/
2025-03-09 14:43:48 +01:00
# Python scripts
cp $src/manage.py $out/lib/python3.11/
# Executables
cat <<- EOF > $out/bin/bookwyrm
#!${bash}/bin/sh
2025-03-03 21:03:41 +01:00
2025-03-09 12:55:12 +01:00
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
2025-03-09 12:55:12 +01:00
echo "You are not running as the 'bookwyrm' user and group, quitting"
exit 1
fi
2025-03-09 12:55:12 +01:00
2025-03-03 21:03:41 +01:00
export PYTHONPATH="$out/lib/python3.11/site-packages"
export DEBUG="false"
2025-03-09 12:55:12 +01:00
2025-03-03 21:03:41 +01:00
export DOMAIN=""
export EMAIL=""
export EMAIL_HOST=""
export EMAIL_HOST_USER=""
export EMAIL_HOST_PASSWORD=""
2025-03-09 12:55:12 +01:00
# 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 )"
2025-03-09 12:55:12 +01:00
exec \$@
2025-03-03 21:03:41 +01:00
EOF
2025-03-09 12:55:12 +01:00
chmod +x $out/bin/*
2025-03-03 21:03:41 +01:00
# Working directory contents
cp $src/VERSION $out/var/lib/bookwyrm/
2025-03-03 21:03:41 +01:00
runHook postInstall
'' ;
}