default.nix 4.6 KB

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