{ lib, stdenv, fetchFromGitHub, python3, fetchYarnDeps, yarn, nodejs, node-pre-gyp, node-gyp, prefetch-yarn-deps, fixup-yarn-lock, makeWrapper, gitUpdater, pkg-config, sqlite, apple-sdk, cctools, cacert, fetchPypi, python3Packages, }: let friendly-traceback = python3Packages.buildPythonPackage rec { pname = "friendly-traceback"; version = "0.7.48"; format = "setuptools"; src = fetchPypi { inherit pname version; hash = "sha256-A4TEnu4W30GzNWvzBxsDHqqFzaW0tBQgy74J2f+CcKA="; }; propagatedBuildInputs = with python3.pkgs; [ asttokens executing pure-eval stack-data ]; doCheck = false; }; in stdenv.mkDerivation rec { pname = "grist-core"; version = "1.7.8"; src = fetchFromGitHub { owner = "gristlabs"; repo = "grist-core"; tag = "v${version}"; hash = "sha256-e68PtWdlgKdjCj97fp+Rh3WwwwIcvKSXlx4Ry1qUeLg="; }; offlineCache = fetchYarnDeps { yarnLock = "${src}/yarn.lock"; hash = "sha256-7zyuBxheftgCXGjjJ+rdwSslIro9IEd/uvmo4xp6I+Q="; }; gristPython = python3.withPackages ( pkgs: with pkgs; [ friendly-traceback openpyxl astroid roman chardet iso8601 phonenumberslite python-dateutil sortedcontainers unittest-xml-reporting ] ); nativeBuildInputs = [ yarn nodejs node-pre-gyp node-gyp prefetch-yarn-deps fixup-yarn-lock makeWrapper pkg-config python3 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ cctools ]; buildInputs = [ sqlite ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ apple-sdk ]; passthru = { updateScript = gitUpdater { rev-prefix = "v"; }; tests = { }; }; configurePhase = '' runHook preConfigure export HOME=$(mktemp -d) rm .yarnrc mkdir -p "$HOME/.node-gyp/${nodejs.version}" echo 9 >"$HOME/.node-gyp/${nodejs.version}/installVersion" ln -sfv "${nodejs}/include" "$HOME/.node-gyp/${nodejs.version}" export npm_config_nodedir=${nodejs} # Set SSL certificates for node-pre-gyp export SSL_CERT_FILE="${cacert}/etc/ssl/certs/ca-bundle.crt" export NODE_EXTRA_CA_CERTS="${cacert}/etc/ssl/certs/ca-bundle.crt" # Ensure cctools' libtool comes before any other libtool ${lib.optionalString stdenv.hostPlatform.isDarwin '' export PATH="${cctools}/bin:$PATH" ''} fixup-yarn-lock yarn.lock yarn config --offline set yarn-offline-mirror ${offlineCache} yarn --offline --frozen-lockfile --ignore-platform --ignore-engines --no-progress --non-interactive install patchShebangs node_modules patchShebangs buildtools runHook postConfigure ''; buildPhase = '' runHook preBuild yarn --offline run build:prod runHook postBuild ''; installPhase = '' runHook preInstall mkdir -p "$out/libexec" "$out/bin" cp -r _build node_modules plugins sandbox static bower_components package.json $out/libexec/ cp -r ${gristPython} $out/libexec/sandbox_venv3 makeWrapper ${lib.getExe nodejs} $out/bin/grist-core \ --add-flags "$out/libexec/_build/stubs/app/server/server.js" \ --set "GRIST_PYTHON_VIRTUALENV" "$out/libexec/sandbox_venv3" \ --set "NODE_PATH" "$out/libexec/_build:$out/libexec/_build/stubs:$out/libexec/_build/ext" \ --set "LD_LIBRARY_PATH" "$out/libexec/sandbox_venv3/lib" \ --prefix PATH : ${gristPython}/bin \ --chdir "$out/libexec" runHook postInstall ''; postInstall = '' # Remove test/dev files that might not exist rm -f $out/libexec/static/mocha.js rm -f $out/libexec/static/sinon.js rm -f $out/libexec/static/mocha.css # Fix or remove broken symlinks find $out/libexec/bower_components -type l ! -exec test -e {} \; -delete # Remove problematic .bin directories find $out/libexec/node_modules -name '.bin' -type d -print0 | xargs -0 rm -rf 2>/dev/null || true # Fix ELF binaries in Python virtual environment using autoPatchelf if [ -d "$out/libexec/sandbox_venv3" ]; then find "$out/libexec/sandbox_venv3" -type f -executable \ -exec sh -c "file -i '{}' | grep -qE 'x-(.*); charset=binary'" \; -print | while read file; do autoPatchelf "$file" || true done fi ''; meta = { description = "Grist is the evolution of spreadsheets"; homepage = "https://github.com/gristlabs/grist-core"; license = lib.licenses.asl20; maintainers = with lib.maintainers; [ scandiravian ]; mainProgram = "grist-core"; platforms = lib.platforms.unix; }; }