summaryrefslogtreecommitdiff
path: root/pkgs/bookwyrm/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/bookwyrm/default.nix')
-rw-r--r--pkgs/bookwyrm/default.nix91
1 files changed, 91 insertions, 0 deletions
diff --git a/pkgs/bookwyrm/default.nix b/pkgs/bookwyrm/default.nix
new file mode 100644
index 0000000..c043bdf
--- /dev/null
+++ b/pkgs/bookwyrm/default.nix
@@ -0,0 +1,91 @@
+{ lib
+, stdenvNoCC
+, writeShellScriptBin
+, writeText
+, bookwyrm-unwrapped
+, settings ? { }
+}:
+
+let
+ # set some dummy values to make the package build
+ settingsWithDefaults = {
+ DOMAIN = "localhost";
+ DEBUG = false;
+ USE_HTTPS = false;
+ EMAIL = "your@email.here";
+ PGPORT = 5432;
+ POSTGRES_USER = "bookwyrm";
+ POSTGRES_DB = "bookwyrm";
+ POSTGRES_HOST = "localhost";
+ REDIS_ACTIVITY_HOST = "localhost";
+ REDIS_ACTIVITY_PORT = 6379;
+ REDIS_BROKER_HOST = "localhost";
+ REDIS_BROKER_PORT = 6379;
+ EMAIL_HOST = "smtp.example.com";
+ EMAIL_PORT = 587;
+ EMAIL_HOST_USER = "mail@example.org";
+ EMAIL_HOST_PASSWORD = "blub";
+ MEDIA_ROOT = "/var/lib/bookwyrm/images";
+ } // settings;
+
+ # toShellVar produces "" for false, which bookwyrm rejects
+ toDjangoVar = name: value: lib.toShellVar name
+ (if value == false then "false" else
+ (if value == true then "true" else value));
+
+ envfile = writeText "bookwyrm.env"
+ (lib.strings.concatLines
+ (lib.mapAttrsToList toDjangoVar settingsWithDefaults));
+
+in stdenvNoCC.mkDerivation (finalAttrs: {
+ pname = "bookwyrm";
+ inherit (bookwyrm-unwrapped) version;
+ src = bookwyrm-unwrapped;
+
+ dontConfigure = true;
+
+ buildPhase = ''
+ runHook preBuild
+
+ ln -s ${envfile} .env
+ # needed for the python settings.py file to not fail, but not
+ # used during the commands executed below, so this is safe
+ export SECRET_KEY=fnord
+
+ export PYTHONPATH=${bookwyrm-unwrapped.pythonPath}
+ ./manage.py compile_themes
+ ./manage.py collectstatic --no-input
+
+ substituteInPlace contrib/systemd/* \
+ --replace /opt/bookwyrm/venv/bin/gunicorn ${lib.getExe bookwyrm-unwrapped.gunicorn} \
+ --replace /opt/bookwyrm/venv/bin/celery ${lib.getExe' bookwyrm-unwrapped.celery "celery"} \
+ --replace /opt/bookwyrm $out
+
+ sed -i /BindPath/d contrib/systemd/*
+
+ runHook postBuild
+ '';
+
+ installPhase = ''
+ runHook preInstall
+
+ mkdir -p $out/lib/systemd/system
+ cp -r * .env $out
+ cp -r contrib/systemd/* $out/lib/systemd/system
+
+ runHook postInstall
+ '';
+
+ passthru = rec {
+ inherit (bookwyrm-unwrapped) celery gunicorn pythonPath;
+ manage = environmentFile: writeShellScriptBin "bookwyrm-manage.py" ''
+ set -a
+ ${if environmentFile != null
+ then "source ${environmentFile}"
+ else ""}
+ export PYTHONPATH=${pythonPath}
+ cd ${finalAttrs.finalPackage.outPath}
+ exec ${finalAttrs.finalPackage.outPath}/manage.py "$@"
+ '';
+ };
+})