1
0

default.nix 4.5 KB

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