1
0

grist-core.nix 4.5 KB

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