diff options
| author | Mira Ressel | 2025-06-10 20:17:29 +0200 | 
|---|---|---|
| committer | Mira Ressel | 2025-06-12 11:08:41 +0200 | 
| commit | 010a2bb354b309c48092014904d4944b6d6eb9ca (patch) | |
| tree | 2aae4e055a3efc7e0eaf5b5f43b6e2ce78bcd92c /pkgs | |
| parent | d58c1897c33e8ce9dc3375fcca72d3c294fdd443 (diff) | |
bookwyrm: split into two packages
Seems nice to separate the compilation from the config injection.
Diffstat (limited to '')
| -rw-r--r-- | pkgs/bookwyrm.nix | 142 | ||||
| -rw-r--r-- | pkgs/bookwyrm/default.nix | 91 | ||||
| -rw-r--r-- | pkgs/bookwyrm/unwrapped.nix | 80 | ||||
| -rw-r--r-- | pkgs/overlay.nix | 3 | 
4 files changed, 173 insertions, 143 deletions
| diff --git a/pkgs/bookwyrm.nix b/pkgs/bookwyrm.nix deleted file mode 100644 index 92764ce..0000000 --- a/pkgs/bookwyrm.nix +++ /dev/null @@ -1,142 +0,0 @@ -{ lib -, fetchFromGitHub -, python -, writeShellScriptBin -, writeText -, 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)); - -  bookwyrm = python.pkgs.buildPythonApplication rec { -    pname = "bookwyrm"; -    version = "0.7.5"; - -    format = "other"; - -    src = fetchFromGitHub { -      owner = "bookwyrm-social"; -      repo = "bookwyrm"; -      rev = "refs/tags/v${version}"; -      hash = "sha256-/oak9dEB2rR2z8b9oXVQ6+F2H7s0F5hVxmAlPdpaA0w="; -    }; - -    propagatedBuildInputs = with python.pkgs; [ -      aiohttp -      bleach -      celery -      colorthief -      django -      django-celery-beat -      bw-file-resubmit -      django-compressor -      django-imagekit -      django-model-utils -      django-sass-processor -      django-csp -      django-oauth-toolkit -      django-storages -      django-pgtrigger -      s3-tar -      environs -      flower -      gunicorn -      libsass -      markdown -      packaging -      pillow -      psycopg2 -      pycryptodome -      dateutil -      redis -      requests -      responses -      pytz -      boto3 -      django-storages -      django-redis -      opentelemetry-api -      opentelemetry-exporter-otlp-proto-grpc -      # opentelemetry-instrumentation-celery -      opentelemetry-instrumentation-django -      # opentelemetry-instrumentation-pyscopg2 -      opentelemetry-sdk -      protobuf -      pyotp -      qrcode -      grpcio -    ]; - -    postBuild = '' -      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 - -      substituteInPlace contrib/systemd/* \ -        --replace /opt/bookwyrm/venv/bin/gunicorn ${lib.getExe python.pkgs.gunicorn} \ -        --replace /opt/bookwyrm/venv/bin/celery ${lib.getExe' python.pkgs.celery "celery"} \ -        --replace /opt/bookwyrm $out - -      sed -i /BindPath/d contrib/systemd/* - -      python manage.py compile_themes -      python manage.py collectstatic --no-input -    ''; - -    postInstall = '' -      mkdir -p $out/lib/systemd/system -      cp -r * .env $out -      cp -r contrib/systemd/* $out/lib/systemd/system -    ''; - -    passthru = { -      pythonPath = python.pkgs.makePythonPath propagatedBuildInputs; -      gunicorn = python.pkgs.gunicorn; -      celery = python.pkgs.celery; -      manage = environmentFile: writeShellScriptBin "bookwyrm-manage.py" '' -        set -a -        ${if environmentFile != null -          then "source ${environmentFile}" -          else ""} -        export PYTHONPATH=${passthru.pythonPath} -        cd ${bookwyrm.outPath} -        exec ${bookwyrm.outPath}/manage.py "$@" -      ''; -    }; - -    # hacky hacky hack -    shellHook = '' -      export PYTHONPATH=${passthru.pythonPath} -    ''; -  }; -in bookwyrm 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 "$@" +    ''; +  }; +}) diff --git a/pkgs/bookwyrm/unwrapped.nix b/pkgs/bookwyrm/unwrapped.nix new file mode 100644 index 0000000..151a9b5 --- /dev/null +++ b/pkgs/bookwyrm/unwrapped.nix @@ -0,0 +1,80 @@ +{ lib +, fetchFromGitHub +, python +}: + +python.pkgs.buildPythonApplication rec { +  pname = "bookwyrm-unwrapped"; +  version = "0.7.5"; + +  format = "other"; + +  src = fetchFromGitHub { +    owner = "bookwyrm-social"; +    repo = "bookwyrm"; +    rev = "refs/tags/v${version}"; +    hash = "sha256-/oak9dEB2rR2z8b9oXVQ6+F2H7s0F5hVxmAlPdpaA0w="; +  }; + +  propagatedBuildInputs = with python.pkgs; [ +    aiohttp +    bleach +    celery +    colorthief +    django +    django-celery-beat +    bw-file-resubmit +    django-compressor +    django-imagekit +    django-model-utils +    django-sass-processor +    django-csp +    django-oauth-toolkit +    django-storages +    django-pgtrigger +    s3-tar +    environs +    flower +    gunicorn +    libsass +    markdown +    packaging +    pillow +    psycopg2 +    pycryptodome +    dateutil +    redis +    requests +    responses +    pytz +    boto3 +    django-storages +    django-redis +    opentelemetry-api +    opentelemetry-exporter-otlp-proto-grpc +    # opentelemetry-instrumentation-celery +    opentelemetry-instrumentation-django +    # opentelemetry-instrumentation-pyscopg2 +    opentelemetry-sdk +    protobuf +    pyotp +    qrcode +    grpcio +  ]; + +  postInstall = '' +    mkdir $out +    cp -r * $out +  ''; + +  passthru = { +    pythonPath = python.pkgs.makePythonPath propagatedBuildInputs; +    gunicorn = python.pkgs.gunicorn; +    celery = python.pkgs.celery; +  }; + +  # hacky hacky hack +  shellHook = '' +    export PYTHONPATH=${passthru.pythonPath} +  ''; +} diff --git a/pkgs/overlay.nix b/pkgs/overlay.nix index e981f8f..687d5cf 100644 --- a/pkgs/overlay.nix +++ b/pkgs/overlay.nix @@ -281,7 +281,8 @@ in    #### packaged mostly as shitpost / to play around with #### -  bookwyrm = (self.callPackage ./bookwyrm.nix { +  bookwyrm = self.callPackage ./bookwyrm {}; +  bookwyrm-unwrapped = (self.callPackage ./bookwyrm/unwrapped.nix {      python = super.python312.override ({        packageOverrides = self: super: {          django-sass-processor = self.callPackage ./python/django-sass-processor.nix {}; | 
