Skip to content

Commit

Permalink
rstudio: build the electron app instead of the qt app
Browse files Browse the repository at this point in the history
  • Loading branch information
TomaSajt committed Dec 7, 2024
1 parent f607a8d commit 1796aa9
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 41 deletions.
121 changes: 80 additions & 41 deletions pkgs/applications/editors/rstudio/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
zlib,
openssl,
R,
libsForQt5,
makeWrapper,
electron_31,
electron_31-bin,
fontconfig,
quarto,
libuuid,
hunspellDicts,
Expand All @@ -24,7 +27,11 @@
yaml-cpp,
soci,
postgresql,
zip,
git,
nodejs,
npmHooks,
fetchNpmDeps,
yarn,
yarnConfigHook,
fetchYarnDeps,
Expand All @@ -35,6 +42,9 @@
}:

let
electron = electron_31;
electron-bin = electron_31-bin;

mathJaxSrc = fetchzip {
url = "https://s3.amazonaws.com/rstudio-buildtools/mathjax-27.zip";
hash = "sha256-J7SZK/9q3HcXTD7WFHxvh++ttuCd89Vc4SEBrUEU0AI=";
Expand Down Expand Up @@ -91,15 +101,33 @@ stdenv.mkDerivation (finalAttrs: {
ant
jdk
pandoc
zip
git
(nodejs.python.withPackages (ps: [ ps.setuptools ]))
nodejs
npmHooks.npmConfigHook
yarn
yarnConfigHook
]
++ lib.optionals (!server) [
copyDesktopItems
libsForQt5.wrapQtAppsHook
makeWrapper
];

env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";

npmRoot = "src/node/desktop";

npmDeps = fetchNpmDeps {
name = "rstudio-${finalAttrs.version}-npm-deps";
inherit (finalAttrs) src;
patches = [ ./update-nan-and-node-abi.patch ];
postPatch = ''
cd ${finalAttrs.npmRoot}
'';
hash = "sha256-CtHCN4sWeHNDd59TV/TgTC4d6h7X1Cl4E/aJkAfRk7g=";
};

buildInputs =
[
boost183
Expand All @@ -111,26 +139,17 @@ stdenv.mkDerivation (finalAttrs: {
soci
postgresql
quarto
sqlite.dev
]
++ (
if server then
[
sqlite.dev
pam
]
else
[
libsForQt5.qtbase
libsForQt5.qtxmlpatterns
libsForQt5.qtsensors
libsForQt5.qtwebengine
libsForQt5.qtwebchannel
]
);
++ lib.optionals server [
pam
] ++ lib.optionals (!server) [
fontconfig
];

cmakeFlags =
[
(lib.cmakeFeature "RSTUDIO_TARGET" (if server then "Server" else "Desktop"))
(lib.cmakeFeature "RSTUDIO_TARGET" (if server then "Server" else "Electron"))
(lib.cmakeBool "RSTUDIO_USE_SYSTEM_SOCI" true)
(lib.cmakeBool "RSTUDIO_USE_SYSTEM_BOOST" true)
(lib.cmakeBool "RSTUDIO_USE_SYSTEM_YAML_CPP" true)
Expand All @@ -139,7 +158,8 @@ stdenv.mkDerivation (finalAttrs: {
(lib.cmakeFeature "CMAKE_INSTALL_PREFIX" "${placeholder "out"}/lib/rstudio")
]
++ lib.optionals (!server) [
(lib.cmakeFeature "QT_QMAKE_EXECUTABLE" "${libsForQt5.qmake}/bin/qmake")
(lib.cmakeFeature "NODEJS" (lib.getExe' nodejs "node"))
(lib.cmakeFeature "NPM" (lib.getExe' nodejs "npm"))
];

# Hack RStudio to only use the input R and provided libclang.
Expand All @@ -158,6 +178,7 @@ stdenv.mkDerivation (finalAttrs: {
./ignore-etc-os-release.patch
./dont-yarn-install.patch
./dont-assume-pandoc-in-quarto.patch
./update-nan-and-node-abi.patch # TODO: actually, only need to update nan, because we're not specifying --version
];

preConfigure = ''
Expand Down Expand Up @@ -192,31 +213,49 @@ stdenv.mkDerivation (finalAttrs: {
ln -s ${nodejs} dependencies/common/node/18.20.3
'';

postInstall = ''
mkdir -p $out/bin $out/share
${lib.optionalString (!server) ''
mkdir -p $out/share/icons/hicolor/48x48/apps
ln $out/lib/rstudio/rstudio.png $out/share/icons/hicolor/48x48/apps
''}
${lib.optionalString server ''
ln -s $out/lib/rstudio/bin/{crash-handler-proxy,postback,r-ldpath,rpostback,rserver,rserver-pam,rsession,rstudio-server} $out/bin
''}
${lib.optionalString (!server) ''
ln -s $out/lib/rstudio/bin/{diagnostics,rpostback,rstudio} $out/bin
''}
for f in .gitignore .Rbuildignore LICENSE README; do
find . -name $f -delete
done
postConfigure = ''
pushd ../$npmRoot
substituteInPlace package.json \
--replace-fail "npm ci && " ""
### use our electron's headers as out nodedir so that electron-rebuild can rebuild for out electron's ABI
# note: because we're not specifying the `--version` flag to pass to electron-rebuild in forge.config.js,
# it thinks it's compiling for the ABI version chosen by upstream, but this doesn't seem to cause any issues
# note: currently we need to use electron-bin's headers, because electron-source's headers are wrong
mkdir electron-headers
tar xf ${electron-bin.headers} -C electron-headers --strip-components=1
export npm_config_nodedir="$(pwd)/electron-headers"
npm exec -- electron-rebuild -f --version=${electron.version}
rm -r $out/lib/rstudio/{INSTALL,COPYING,NOTICE,README.md,SOURCE,VERSION}
### create the electron archive to be used by electron-packager:
# electron files need to be writable on Darwin
cp -r ${electron.dist} electron-dist
chmod -R u+w electron-dist
pushd electron-dist
zip -0Xqr ../electron.zip .
popd
rm -r electron-dist
# force @electron/packager to use our electron instead of downloading it
substituteInPlace node_modules/@electron/packager/src/index.js \
--replace-fail 'await this.getElectronZipPath(downloadOpts)' '"electron.zip"'
popd
'';

qtWrapperArgs = lib.optionals (!server) [
"--suffix PATH : ${lib.makeBinPath [ gnumake ]}"
];
# TODO: readd rstudio-server related stuff
# TODO: remove junk files that are just copied from electron.zip
postInstall = ''
makeWrapper ${lib.getExe electron} "$out/bin/rstudio" \
--add-flags "$out/lib/rstudio/resources/app/" \
--set-default ELECTRON_FORCE_IS_PACKAGED 1 \
--set-default RSTUDIO_WHICH_R ${lib.getExe R} \
--suffix PATH : ${lib.makeBinPath [ gnumake ]}
'';

desktopItems = lib.optionals (!server) [
(makeDesktopItem {
Expand Down
88 changes: 88 additions & 0 deletions pkgs/applications/editors/rstudio/update-nan-and-node-abi.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
diff --git a/src/node/desktop/package-lock.json b/src/node/desktop/package-lock.json
index 01c11edaf4..5e356470be 100644
--- a/src/node/desktop/package-lock.json
+++ b/src/node/desktop/package-lock.json
@@ -19,7 +19,7 @@
"line-reader": "0.4.0",
"lodash.debounce": "4.0.8",
"net-ipc": "2.1.0",
- "node-abi": "3.52.0",
+ "node-abi": "^3.71.0",
"node-addon-api": "7.0.0",
"node-system-fonts": "1.0.1",
"properties-reader": "2.3.0",
@@ -63,7 +63,7 @@
"json-schema-to-typescript": "13.1.1",
"lint-staged": "15.2.0",
"mocha": "10.2.0",
- "nan": "2.18.0",
+ "nan": "^2.22.0",
"node-loader": "2.0.0",
"nyc": "15.1.0",
"prettier": "3.1.1",
@@ -9768,9 +9768,10 @@
}
},
"node_modules/nan": {
- "version": "2.18.0",
- "resolved": "https://registry.npmjs.org/nan/-/nan-2.18.0.tgz",
- "integrity": "sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w=="
+ "version": "2.22.0",
+ "resolved": "https://registry.npmjs.org/nan/-/nan-2.22.0.tgz",
+ "integrity": "sha512-nbajikzWTMwsW+eSsNm3QwlOs7het9gGJU5dDZzRTQGk03vyBOauxgI4VakDzE0PtsGTmXPsXTbbjVhRwR5mpw==",
+ "license": "MIT"
},
"node_modules/nanoid": {
"version": "3.3.3",
@@ -9863,9 +9864,10 @@
}
},
"node_modules/node-abi": {
- "version": "3.52.0",
- "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.52.0.tgz",
- "integrity": "sha512-JJ98b02z16ILv7859irtXn4oUaFWADtvkzy2c0IAatNVX2Mc9Yoh8z6hZInn3QwvMEYhHuQloYi+TTQy67SIdQ==",
+ "version": "3.71.0",
+ "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.71.0.tgz",
+ "integrity": "sha512-SZ40vRiy/+wRTf21hxkkEjPJZpARzUMVcJoQse2EF8qkUWbbO2z7vd5oA/H6bVH6SZQ5STGcu0KRDS7biNRfxw==",
+ "license": "MIT",
"dependencies": {
"semver": "^7.3.5"
},
diff --git a/src/node/desktop/package.json b/src/node/desktop/package.json
index 059c39f9d7..cf16ebc0fb 100644
--- a/src/node/desktop/package.json
+++ b/src/node/desktop/package.json
@@ -26,9 +26,9 @@
"forge": "./forge.config.js"
},
"devDependencies": {
- "@electron/packager": "18.1.1",
"@electron-forge/cli": "7.2.0",
"@electron-forge/plugin-webpack": "7.2.0",
+ "@electron/packager": "18.1.1",
"@types/chai": "4.3.11",
"@types/crc": "3.8.3",
"@types/line-reader": "0.0.37",
@@ -59,11 +59,11 @@
"json-schema-to-typescript": "13.1.1",
"lint-staged": "15.2.0",
"mocha": "10.2.0",
- "nan": "2.18.0",
+ "nan": "^2.22.0",
"node-loader": "2.0.0",
"nyc": "15.1.0",
- "process": "0.11.10",
"prettier": "3.1.1",
+ "process": "0.11.10",
"sinon": "17.0.1",
"style-loader": "3.3.3",
"ts-loader": "9.5.1",
@@ -83,7 +83,7 @@
"line-reader": "0.4.0",
"lodash.debounce": "4.0.8",
"net-ipc": "2.1.0",
- "node-abi": "3.52.0",
+ "node-abi": "^3.71.0",
"node-addon-api": "7.0.0",
"node-system-fonts": "1.0.1",
"properties-reader": "2.3.0",

0 comments on commit 1796aa9

Please sign in to comment.