diff options
author | Bruno BELANYI <bruno@belanyi.fr> | 2021-11-26 18:00:14 +0100 |
---|---|---|
committer | Bruno BELANYI <bruno@belanyi.fr> | 2022-10-03 09:48:54 +0200 |
commit | 6a1359e4a236ef32d5f9fcdf6e533d269a659bf1 (patch) | |
tree | fed34d0d6d5e0e961354e222b8e16fd7eee60720 /pkgs/applications/misc/tandoor-recipes | |
parent | 284e89493f5507c4fa03decaeabf9bd68b980239 (diff) |
tandoor-recipes: init at 1.4.1
Diffstat (limited to 'pkgs/applications/misc/tandoor-recipes')
-rw-r--r-- | pkgs/applications/misc/tandoor-recipes/common.nix | 19 | ||||
-rw-r--r-- | pkgs/applications/misc/tandoor-recipes/default.nix | 135 | ||||
-rw-r--r-- | pkgs/applications/misc/tandoor-recipes/frontend.nix | 57 | ||||
-rw-r--r-- | pkgs/applications/misc/tandoor-recipes/media-root.patch | 17 | ||||
-rwxr-xr-x | pkgs/applications/misc/tandoor-recipes/update.sh | 42 |
5 files changed, 270 insertions, 0 deletions
diff --git a/pkgs/applications/misc/tandoor-recipes/common.nix b/pkgs/applications/misc/tandoor-recipes/common.nix new file mode 100644 index 0000000000000..77f1c3f9aef52 --- /dev/null +++ b/pkgs/applications/misc/tandoor-recipes/common.nix @@ -0,0 +1,19 @@ +{ lib, fetchFromGitHub }: +rec { + version = "1.4.1"; + + src = fetchFromGitHub { + owner = "TandoorRecipes"; + repo = "recipes"; + rev = version; + sha256 = "sha256-Q/IwjSByCUXVYxhk3U7oWvlMxrJxyajhpsRyq67PVHY="; + }; + + yarnSha256 = "sha256-gH0q3pJ2BC5pAU9KSo3C9DDRUnpypoyLOEqKSrkxYrk="; + + meta = with lib; { + homepage = "https://tandoor.dev/"; + license = licenses.agpl3Only; + maintainers = with maintainers; [ ambroisie ]; + }; +} diff --git a/pkgs/applications/misc/tandoor-recipes/default.nix b/pkgs/applications/misc/tandoor-recipes/default.nix new file mode 100644 index 0000000000000..eb0a8fde447c2 --- /dev/null +++ b/pkgs/applications/misc/tandoor-recipes/default.nix @@ -0,0 +1,135 @@ +{ callPackage +, python3 +}: +let + python = python3.override { + packageOverrides = self: super: { + django = super.django_4; + + # Tests are incompatible with Django 4 + django-js-reverse = super.django-js-reverse.overridePythonAttrs (_: { + doCheck = false; + }); + }; + }; + + common = callPackage ./common.nix { }; + + frontend = callPackage ./frontend.nix { }; +in +python.pkgs.pythonPackages.buildPythonPackage rec { + pname = "tandoor-recipes"; + + inherit (common) version src; + + format = "other"; + + patches = [ + # Allow setting MEDIA_ROOT through environment variable + ./media-root.patch + ]; + + propagatedBuildInputs = with python.pkgs; [ + beautifulsoup4 + bleach + bleach-allowlist + boto3 + cryptography + django + django-allauth + django-annoying + django-auth-ldap + django-autocomplete-light + django-cleanup + django-cors-headers + django-crispy-forms + django-hcaptcha + django-js-reverse + django-oauth-toolkit + django-prometheus + django-scopes + django-storages + django-tables2 + django-webpack-loader + django_treebeard + djangorestframework + drf-writable-nested + gunicorn + icalendar + jinja2 + lxml + markdown + microdata + pillow + psycopg2 + pyppeteer + python-dotenv + pytube + pyyaml + recipe-scrapers + requests + six + uritemplate + validators + webdavclient3 + whitenoise + ]; + + configurePhase = '' + runHook preConfigure + + ln -sf ${frontend}/ cookbook/static/vue + cp ${frontend}/webpack-stats.json vue/ + + runHook postConfigure + ''; + + buildPhase = '' + runHook preBuild + + # Avoid dependency on django debug toolbar + export DEBUG=0 + + # See https://github.com/TandoorRecipes/recipes/issues/2043 + mkdir cookbook/static/themes/maps/ + touch cookbook/static/themes/maps/style.min.css.map + touch cookbook/static/themes/bootstrap.min.css.map + touch cookbook/static/css/bootstrap-vue.min.css.map + + ${python.pythonForBuild.interpreter} manage.py collectstatic_js_reverse + ${python.pythonForBuild.interpreter} manage.py collectstatic + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + mkdir -p $out/lib + cp -r . $out/lib/tandoor-recipes + chmod +x $out/lib/tandoor-recipes/manage.py + makeWrapper $out/lib/tandoor-recipes/manage.py $out/bin/tandoor-recipes \ + --prefix PYTHONPATH : "$PYTHONPATH" + + runHook postInstall + ''; + + checkInputs = with python.pkgs; [ + pytestCheckHook + pytest-django + pytest-factoryboy + ]; + + passthru = { + inherit frontend python; + + updateScript = ./update.sh; + }; + + meta = common.meta // { + description = '' + Application for managing recipes, planning meals, building shopping lists + and much much more! + ''; + }; +} diff --git a/pkgs/applications/misc/tandoor-recipes/frontend.nix b/pkgs/applications/misc/tandoor-recipes/frontend.nix new file mode 100644 index 0000000000000..47dcde5aca517 --- /dev/null +++ b/pkgs/applications/misc/tandoor-recipes/frontend.nix @@ -0,0 +1,57 @@ +{ stdenv, fetchYarnDeps, fixup_yarn_lock, callPackage, nodejs-16_x }: +let + common = callPackage ./common.nix { }; +in +stdenv.mkDerivation { + pname = "tandoor-recipes-frontend"; + inherit (common) version; + + src = "${common.src}/vue"; + + yarnOfflineCache = fetchYarnDeps { + yarnLock = "${common.src}/vue/yarn.lock"; + sha256 = common.yarnSha256; + }; + + nativeBuildInputs = [ + fixup_yarn_lock + # Use Node JS 16 because of @achrinza/node-ipc@9.2.2 + nodejs-16_x + nodejs-16_x.pkgs.yarn + ]; + + configurePhase = '' + runHook preConfigure + + export HOME=$(mktemp -d) + yarn config --offline set yarn-offline-mirror "$yarnOfflineCache" + fixup_yarn_lock yarn.lock + command -v yarn + yarn install --frozen-lockfile --offline --no-progress --non-interactive + patchShebangs node_modules/ + + runHook postConfigure + ''; + + buildPhase = '' + runHook preBuild + + yarn --offline run build + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + cp -R ../cookbook/static/vue/ $out + cp webpack-stats.json $out + echo "${common.version}" > "$out/version" + + runHook postInstall + ''; + + meta = common.meta // { + description = "Tandoor Recipes frontend"; + }; +} diff --git a/pkgs/applications/misc/tandoor-recipes/media-root.patch b/pkgs/applications/misc/tandoor-recipes/media-root.patch new file mode 100644 index 0000000000000..8114ca8aaeb37 --- /dev/null +++ b/pkgs/applications/misc/tandoor-recipes/media-root.patch @@ -0,0 +1,17 @@ +diff --git a/recipes/settings.py b/recipes/settings.py +index 5676fe0a..6c6f1747 100644 +--- a/recipes/settings.py ++++ b/recipes/settings.py +@@ -426,10 +426,10 @@ if os.getenv('S3_ACCESS_KEY', ''): + AWS_S3_CUSTOM_DOMAIN = os.getenv('S3_CUSTOM_DOMAIN', '') + + MEDIA_URL = os.getenv('MEDIA_URL', '/media/') +- MEDIA_ROOT = os.path.join(BASE_DIR, "mediafiles") ++ MEDIA_ROOT = os.getenv('MEDIA_ROOT', os.path.join(BASE_DIR, "mediafiles")) + else: + MEDIA_URL = os.getenv('MEDIA_URL', '/media/') +- MEDIA_ROOT = os.path.join(BASE_DIR, "mediafiles") ++ MEDIA_ROOT = os.getenv('MEDIA_ROOT', os.path.join(BASE_DIR, "mediafiles")) + + # Serve static files with gzip + STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' diff --git a/pkgs/applications/misc/tandoor-recipes/update.sh b/pkgs/applications/misc/tandoor-recipes/update.sh new file mode 100755 index 0000000000000..49b6d5f98ae95 --- /dev/null +++ b/pkgs/applications/misc/tandoor-recipes/update.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env nix-shell +#!nix-shell -I nixpkgs=../../../../ -i bash -p nix wget prefetch-yarn-deps nix-prefetch-github jq + +# shellcheck shell=bash + +if [ -n "$GITHUB_TOKEN" ]; then + TOKEN_ARGS=(--header "Authorization: token $GITHUB_TOKEN") +fi + +if [ "$#" -gt 1 ] || [[ "$1" == -* ]]; then + echo "Regenerates packaging data for the tandoor-recipes package." + echo "Usage: $0 [git release tag]" + exit 1 +fi + +version="$1" + +set -euo pipefail + +if [ -z "$version" ]; then + version="$(wget -O- "${TOKEN_ARGS[@]}" "https://api.github.com/repos/TandoorRecipes/recipes/releases?per_page=1" | jq -r '.[0].tag_name')" +fi + +package_src="https://raw.githubusercontent.com/TandoorRecipes/recipes/$version" + +src_hash=$(nix-prefetch-github TandoorRecipes recipes --rev "${version}" | jq -r .sha256) + +tmpdir=$(mktemp -d) +trap 'rm -rf "$tmpdir"' EXIT + +pushd "$tmpdir" +wget "${TOKEN_ARGS[@]}" "$package_src/vue/yarn.lock" +yarn_hash=$(prefetch-yarn-deps yarn.lock) +popd + +# Use friendlier hashes +src_hash=$(nix hash to-sri --type sha256 "$src_hash") +yarn_hash=$(nix hash to-sri --type sha256 "$yarn_hash") + +sed -i -E -e "s#version = \".*\"#version = \"$version\"#" common.nix +sed -i -E -e "s#sha256 = \".*\"#sha256 = \"$src_hash\"#" common.nix +sed -i -E -e "s#yarnSha256 = \".*\"#yarnSha256 = \"$yarn_hash\"#" common.nix |