grist-core.nix 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. , gvisor
  18. ,
  19. }:
  20. stdenv.mkDerivation rec {
  21. pname = "grist-core";
  22. version = "1.7.8";
  23. src = fetchFromGitHub {
  24. owner = "gristlabs";
  25. repo = "grist-core";
  26. tag = "v${version}";
  27. hash = "sha256-e68PtWdlgKdjCj97fp+Rh3WwwwIcvKSXlx4Ry1qUeLg=";
  28. };
  29. offlineCache = fetchYarnDeps {
  30. yarnLock = "${src}/yarn.lock";
  31. hash = "sha256-7zyuBxheftgCXGjjJ+rdwSslIro9IEd/uvmo4xp6I+Q=";
  32. };
  33. nativeBuildInputs = [
  34. yarn
  35. nodejs
  36. prefetch-yarn-deps
  37. fixup-yarn-lock
  38. makeWrapper
  39. pkg-config
  40. python3
  41. ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
  42. cctools
  43. ];
  44. buildInputs = [
  45. sqlite
  46. ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
  47. apple-sdk
  48. ] ++ lib.optionals stdenv.hostPlatform.isLinux [
  49. gvisor
  50. ];
  51. passthru = {
  52. updateScript = gitUpdater { rev-prefix = "v"; };
  53. tests = { };
  54. };
  55. configurePhase = ''
  56. runHook preConfigure
  57. export HOME=$(mktemp -d)
  58. rm .yarnrc
  59. yarn config --offline set yarn-offline-mirror ${offlineCache}
  60. fixup-yarn-lock yarn.lock
  61. mkdir -p "$HOME/.node-gyp/${nodejs.version}"
  62. echo 9 >"$HOME/.node-gyp/${nodejs.version}/installVersion"
  63. ln -sfv "${nodejs}/include" "$HOME/.node-gyp/${nodejs.version}"
  64. export npm_config_nodedir=${nodejs}
  65. # Set SSL certificates for node-pre-gyp
  66. export SSL_CERT_FILE="${cacert}/etc/ssl/certs/ca-bundle.crt"
  67. export NODE_EXTRA_CA_CERTS="${cacert}/etc/ssl/certs/ca-bundle.crt"
  68. # Ensure cctools' libtool comes before any other libtool
  69. ${lib.optionalString stdenv.hostPlatform.isDarwin ''
  70. export PATH="${cctools}/bin:$PATH"
  71. ''}
  72. yarn --offline --frozen-lockfile --ignore-platform --ignore-engines --ignore-optional --no-progress --non-interactive install
  73. yarn install:python
  74. patchShebangs node_modules
  75. patchShebangs buildtools
  76. runHook postConfigure
  77. '';
  78. buildPhase = ''
  79. runHook preBuild
  80. yarn --offline run build:prod
  81. runHook postBuild
  82. '';
  83. installPhase = ''
  84. runHook preInstall
  85. mkdir -p "$out/libexec" "$out/bin"
  86. # Copy runtime files + the sandbox venv
  87. cp -r _build node_modules plugins sandbox static bower_components package.json sandbox_venv3 $out/libexec/
  88. makeWrapper ${lib.getExe nodejs} $out/bin/grist-core \
  89. --add-flags "$out/libexec/_build/stubs/app/server/server.js" \
  90. --set "GRIST_PYTHON_VIRTUALENV" "$out/libexec/sandbox_venv3" \
  91. --set "NODE_PATH" "$out/libexec/_build:$out/libexec/_build/stubs:$out/libexec/_build/ext" \
  92. --chdir "$out/libexec"
  93. runHook postInstall
  94. '';
  95. postInstall = ''
  96. # Remove test/dev files that might not exist
  97. rm -f $out/libexec/static/mocha.js
  98. rm -f $out/libexec/static/sinon.js
  99. rm -f $out/libexec/static/mocha.css
  100. # Fix or remove broken symlinks
  101. find $out/libexec/bower_components -type l ! -exec test -e {} \; -delete
  102. # Remove problematic .bin directories
  103. find $out/libexec/node_modules -name '.bin' -type d -print0 | xargs -0 rm -rf 2>/dev/null || true
  104. '';
  105. meta = {
  106. description = "Grist is the evolution of spreadsheets";
  107. homepage = "https://github.com/gristlabs/grist-core";
  108. license = lib.licenses.asl20;
  109. maintainers = with lib.maintainers; [ scandiravian ];
  110. mainProgram = "grist-core";
  111. platforms = lib.platforms.unix;
  112. };
  113. }