{
  stdenvNoCC,
  python3,
  fetchFromGitHub,
  fetchYarnDeps,
  yarnConfigHook,
  nodejs,
}:
let
  version = "1.1.0";

  src = fetchFromGitHub {
    owner = "inventree";
    repo = "InvenTree";
    tag = "${version}";
    hash = "sha256-GAATo5zkkNCes9fCQsYUsZ9auhgYEUnevN4obWj3ZRA=";
  };

  frontend = stdenvNoCC.mkDerivation {
    name = "inventree-frontend";
    inherit version src;

    yarnOfflineCache = fetchYarnDeps {
      yarnLock = "${src}/src/frontend/yarn.lock";
      hash = "sha256-Ijbkx+INZgsvMhkzo8h/FUY75W3UHnKAdUjQRD8kJZw=";
    };

    nativeBuildInputs = [
      yarnConfigHook
      nodejs
    ];

    patchPhase = ''
      runHook prePatch
      cd src/frontend
      runHook postPatch
    '';

    buildPhase = ''
      echo "Running lingui"
      ./node_modules/.bin/lingui compile --typescript
      echo building lib
      ./node_modules/.bin/tsc --p ./tsconfig.lib.json
      ./node_modules/.bin/vite --config vite.lib.config.ts build
      echo "Running tsc"
      ./node_modules/.bin/tsc
      echo "Running vite"
      ./node_modules/.bin/vite build --emptyOutDir --outDir $out
    '';
  };

in
python3.pkgs.buildPythonApplication rec {
  pname = "InvenTree";
  inherit version src;

  format = "other";

  dependencies =
    with python3.pkgs;
    [
      coreapi
      cryptography
      distutils
      dj-rest-auth
      django
      django-allauth
      django-allauth.optional-dependencies.openid
      django-allauth.optional-dependencies.mfa
      django-allauth.optional-dependencies.socialaccount
      django-cleanup
      django-cors-headers
      django-dbbackup
      django-error-report-2
      django-filter
      django-flags
      django-formtools
      django-ical
      django-js-asset
      django-maintenance-mode
      django-markdownify
      django-money
      django-mptt
      django-mailbox
      django-anymail
      django-redis
      django-oauth-toolkit
      django-otp
      django-q-sentry
      django-q2
      django-redis
      django-sesame
      django-sql-utils
      django-structlog
      django-stdimage
      django-taggit
      django-user-sessions
      django-weasyprint
      djangorestframework
      djangorestframework-simplejwt
      djangorestframework-simplejwt.optional-dependencies.crypto
      django-xforwardedfor-middleware
      django-storages
      drf-spectacular
      dulwich
      feedparser
      gunicorn
      pdf2image
      pillow
      pint
      pip-licenses
      pypdf
      python-barcode
      python-barcode.optional-dependencies.images
      python-dotenv
      pyyaml
      qrcode
      qrcode.optional-dependencies.pil
      rapidfuzz
      sentry-sdk
      tablib
      tablib.optional-dependencies.xls
      tablib.optional-dependencies.xlsx
      tablib.optional-dependencies.yaml
      weasyprint
      whitenoise

      psycopg2
      fido2

      opentelemetry-api
      opentelemetry-sdk
      opentelemetry-exporter-otlp
      opentelemetry-instrumentation-django
      opentelemetry-instrumentation-requests
      opentelemetry-instrumentation-redis
      opentelemetry-instrumentation-sqlite3
      opentelemetry-instrumentation-system-metrics
      opentelemetry-instrumentation-wsgi
    ]
    ++ django-anymail.optional-dependencies.amazon-ses;

  installPhase = ''
    substituteInPlace src/backend/InvenTree/InvenTree/settings.py --replace-fail "django_slowtests.testrunner.DiscoverSlowestTestsRunner" "django.test.runner.DiscoverRunner"

    mkdir -p $out/opt/inventree
    cp -r . $out/opt/inventree

    echo "Installing frontend"

    mkdir -p $out/opt/inventree/src/backend/InvenTree/web/static/web
    cp -r ${frontend}/* $out/opt/inventree/src/backend/InvenTree/web/static/web/
    cp -r ${frontend}/.* $out/opt/inventree/src/backend/InvenTree/web/static/web/
  '';

  passthru = {
    pythonPath = python3.pkgs.makePythonPath dependencies;
    gunicorn = python3.pkgs.gunicorn;
    inherit frontend;
  };
}
