grist-core.nix 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. {
  2. lib,
  3. stdenv,
  4. fetchFromGitHub,
  5. python3,
  6. fetchYarnDeps,
  7. yarn,
  8. nodejs,
  9. node-pre-gyp,
  10. node-gyp,
  11. prefetch-yarn-deps,
  12. fixup-yarn-lock,
  13. makeWrapper,
  14. gitUpdater,
  15. pkg-config,
  16. sqlite,
  17. apple-sdk,
  18. cctools,
  19. cacert,
  20. fetchPypi,
  21. python3Packages,
  22. }:
  23. let
  24. friendly-traceback = python3Packages.buildPythonPackage rec {
  25. pname = "friendly-traceback";
  26. version = "0.7.48";
  27. format = "setuptools";
  28. src = fetchPypi {
  29. inherit pname version;
  30. hash = "sha256-A4TEnu4W30GzNWvzBxsDHqqFzaW0tBQgy74J2f+CcKA=";
  31. };
  32. propagatedBuildInputs = with python3.pkgs; [
  33. asttokens
  34. executing
  35. pure-eval
  36. stack-data
  37. ];
  38. doCheck = false;
  39. };
  40. in
  41. stdenv.mkDerivation rec {
  42. pname = "grist-core";
  43. version = "1.7.8";
  44. src = fetchFromGitHub {
  45. owner = "gristlabs";
  46. repo = "grist-core";
  47. tag = "v${version}";
  48. hash = "sha256-e68PtWdlgKdjCj97fp+Rh3WwwwIcvKSXlx4Ry1qUeLg=";
  49. };
  50. offlineCache = fetchYarnDeps {
  51. yarnLock = "${src}/yarn.lock";
  52. hash = "sha256-7zyuBxheftgCXGjjJ+rdwSslIro9IEd/uvmo4xp6I+Q=";
  53. };
  54. gristPython = python3.withPackages (
  55. pkgs: with pkgs; [
  56. friendly-traceback
  57. openpyxl
  58. astroid
  59. roman
  60. chardet
  61. iso8601
  62. phonenumberslite
  63. python-dateutil
  64. sortedcontainers
  65. unittest-xml-reporting
  66. ]
  67. );
  68. nativeBuildInputs = [
  69. yarn
  70. nodejs
  71. node-pre-gyp
  72. node-gyp
  73. prefetch-yarn-deps
  74. fixup-yarn-lock
  75. makeWrapper
  76. pkg-config
  77. python3
  78. ]
  79. ++ lib.optionals stdenv.hostPlatform.isDarwin [
  80. cctools
  81. ];
  82. buildInputs = [
  83. sqlite
  84. ]
  85. ++ lib.optionals stdenv.hostPlatform.isDarwin [
  86. apple-sdk
  87. ];
  88. passthru = {
  89. updateScript = gitUpdater { rev-prefix = "v"; };
  90. tests = { };
  91. };
  92. configurePhase = ''
  93. runHook preConfigure
  94. export HOME=$(mktemp -d)
  95. rm .yarnrc
  96. mkdir -p "$HOME/.node-gyp/${nodejs.version}"
  97. echo 9 >"$HOME/.node-gyp/${nodejs.version}/installVersion"
  98. ln -sfv "${nodejs}/include" "$HOME/.node-gyp/${nodejs.version}"
  99. export npm_config_nodedir=${nodejs}
  100. # Set SSL certificates for node-pre-gyp
  101. export SSL_CERT_FILE="${cacert}/etc/ssl/certs/ca-bundle.crt"
  102. export NODE_EXTRA_CA_CERTS="${cacert}/etc/ssl/certs/ca-bundle.crt"
  103. # Ensure cctools' libtool comes before any other libtool
  104. ${lib.optionalString stdenv.hostPlatform.isDarwin ''
  105. export PATH="${cctools}/bin:$PATH"
  106. ''}
  107. fixup-yarn-lock yarn.lock
  108. yarn config --offline set yarn-offline-mirror ${offlineCache}
  109. yarn --offline --frozen-lockfile --ignore-platform --ignore-engines --no-progress --non-interactive install
  110. patchShebangs node_modules
  111. patchShebangs buildtools
  112. runHook postConfigure
  113. '';
  114. buildPhase = ''
  115. runHook preBuild
  116. yarn --offline run build:prod
  117. runHook postBuild
  118. '';
  119. installPhase = ''
  120. runHook preInstall
  121. mkdir -p "$out/libexec" "$out/bin"
  122. cp -r _build node_modules plugins sandbox static bower_components package.json $out/libexec/
  123. cp -r ${gristPython} $out/libexec/sandbox_venv3
  124. makeWrapper ${lib.getExe nodejs} $out/bin/grist-core \
  125. --add-flags "$out/libexec/_build/stubs/app/server/server.js" \
  126. --set "GRIST_PYTHON_VIRTUALENV" "$out/libexec/sandbox_venv3" \
  127. --set "NODE_PATH" "$out/libexec/_build:$out/libexec/_build/stubs:$out/libexec/_build/ext" \
  128. --set "LD_LIBRARY_PATH" "$out/libexec/sandbox_venv3/lib" \
  129. --prefix PATH : ${gristPython}/bin \
  130. --chdir "$out/libexec"
  131. runHook postInstall
  132. '';
  133. postInstall = ''
  134. # Remove test/dev files that might not exist
  135. rm -f $out/libexec/static/mocha.js
  136. rm -f $out/libexec/static/sinon.js
  137. rm -f $out/libexec/static/mocha.css
  138. # Fix or remove broken symlinks
  139. find $out/libexec/bower_components -type l ! -exec test -e {} \; -delete
  140. # Remove problematic .bin directories
  141. find $out/libexec/node_modules -name '.bin' -type d -print0 | xargs -0 rm -rf 2>/dev/null || true
  142. # Fix ELF binaries in Python virtual environment using autoPatchelf
  143. if [ -d "$out/libexec/sandbox_venv3" ]; then
  144. find "$out/libexec/sandbox_venv3" -type f -executable \
  145. -exec sh -c "file -i '{}' | grep -qE 'x-(.*); charset=binary'" \; -print |
  146. while read file; do
  147. autoPatchelf "$file" || true
  148. done
  149. fi
  150. '';
  151. meta = {
  152. description = "Grist is the evolution of spreadsheets";
  153. homepage = "https://github.com/gristlabs/grist-core";
  154. license = lib.licenses.asl20;
  155. maintainers = with lib.maintainers; [ scandiravian ];
  156. mainProgram = "grist-core";
  157. platforms = lib.platforms.unix;
  158. };
  159. }