Introduce bookwyrm-env in Bookwyrm

This commit is contained in:
Reinout Meliesie 2025-03-09 12:55:12 +01:00
parent db2fc844df
commit e38a4f7bf0
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6
2 changed files with 19 additions and 4 deletions

View file

@ -15,7 +15,7 @@ with pkgs . kernelmaft ;
[Service]
ExecStartPre=${coreutils-full}/bin/ln -sf ${bookwyrm}/var/lib/bookwyrm/VERSION /var/lib/bookwyrm/
ExecStart=${bookwyrm}/bin/bookwyrm
ExecStart=${bookwyrm}/bin/bookwyrm-env ${bookwyrm}/bin/bookwyrm
WorkingDirectory=/var/lib/bookwyrm

View file

@ -111,6 +111,7 @@ mkDerivation {
# 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 &
@ -137,20 +138,34 @@ mkDerivation {
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
if [ $( id -un ) != "bookwyrm" || $( id -gn ) != "bookwyrm" ] ; do
echo "You are not running as the 'bookwyrm' user and group, quitting"
exit 1
done
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=""
export SECRET_KEY="\$( ${coreutils-full}/bin/cat /etc/nixos/assets/bookwyrm-secret-key )" # The escape here is required in order to retrieve the key file contents at runtime
exec ${gunicorn}/bin/gunicorn bookwyrm.wsgi:application --bind=unix:/run/bookwyrm/http-socket
# The escape here is required in order to retrieve the key file contents at runtime
export SECRET_KEY="\$( ${coreutils-full}/bin/cat /etc/nixos/assets/bookwyrm-secret-key )"
exec $@
EOF
chmod +x $out/bin/bookwyrm
chmod +x $out/bin/*
# Working directory contents