Skip to content

Commit

Permalink
rstudio: clean up patches, build panmirror, remove rsconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
TomaSajt committed Nov 18, 2024
1 parent c1b1d1d commit 1da1c18
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 178 deletions.
91 changes: 45 additions & 46 deletions pkgs/applications/editors/rstudio/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
lib,
stdenv,
fetchurl,
fetchzip,
fetchFromGitHub,
replaceVars,
makeDesktopItem,
copyDesktopItems,
cmake,
Expand All @@ -24,23 +25,19 @@
soci,
postgresql,
nodejs,
yarn,
yarnConfigHook,
fetchYarnDeps,
server ? false, # build server version
sqlite,
pam,
nixosTests,
}:

let
mathJaxSrc = fetchurl {
mathJaxSrc = fetchzip {
url = "https://s3.amazonaws.com/rstudio-buildtools/mathjax-27.zip";
hash = "sha256-xWy6psTOA8H8uusrXqPDEtL7diajYCVHcMvLiPsgQXY=";
};

rsconnectSrc = fetchFromGitHub {
owner = "rstudio";
repo = "rsconnect";
rev = "v1.2.2";
hash = "sha256-wvM9Bm7Nb6yU9z0o+uF5lB2kdgjOW5wZSk6y48NPF2U=";
hash = "sha256-J7SZK/9q3HcXTD7WFHxvh++ttuCd89Vc4SEBrUEU0AI=";
};

# Ideally, rev should match the rstudio release name.
Expand Down Expand Up @@ -69,6 +66,13 @@ stdenv.mkDerivation rec {
hash = "sha256-j258eW1MYQrB6kkpjyolXdNuwQ3zSWv9so4q0QLsZuw=";
};

yarnOfflineCache = fetchYarnDeps {
yarnLock = quartoSrc + "/yarn.lock";
hash = "sha256-Qw8O1Jzl2EO0DEF3Jrw/cIT9t22zs3jyKgDA5XZbuGA=";
};

dontYarnInstallDeps = true; # will call manually

nativeBuildInputs =
[
cmake
Expand All @@ -77,6 +81,8 @@ stdenv.mkDerivation rec {
jdk
pandoc
nodejs
yarn
yarnConfigHook
]
++ lib.optionals (!server) [
copyDesktopItems
Expand Down Expand Up @@ -119,7 +125,6 @@ stdenv.mkDerivation rec {
(lib.cmakeBool "RSTUDIO_USE_SYSTEM_YAML_CPP" true)
(lib.cmakeBool "RSTUDIO_DISABLE_CHECK_FOR_UPDATES" true)
(lib.cmakeBool "QUARTO_ENABLED" true)
(lib.cmakeFeature "PANDOC_VERSION" pandoc.version)
(lib.cmakeFeature "CMAKE_INSTALL_PREFIX" "${placeholder "out"}/lib/rstudio")
]
++ lib.optionals (!server) [
Expand All @@ -128,38 +133,22 @@ stdenv.mkDerivation rec {

# Hack RStudio to only use the input R and provided libclang.
patches = [
./r-location.patch
./clang-location.patch
./use-system-node.patch
(replaceVars ./r-location.patch {
R = lib.getBin R;
})
(replaceVars ./clang-location.patch {
libclang = lib.getLib llvmPackages.libclang;
"libclang.so" = "${lib.getLib llvmPackages.libclang}/lib/libclang.so";
})
(replaceVars ./use-system-node.patch {
node = lib.getBin nodejs;
})
./fix-resources-path.patch
./pandoc-nix-path.patch
./use-system-quarto.patch
./ignore-etc-os-release.patch
./dont-yarn-install.patch
./dont-assume-pandoc-in-quarto.patch
];

postPatch = ''
substituteInPlace src/cpp/core/r_util/REnvironmentPosix.cpp --replace-fail '@R@' ${R}
substituteInPlace src/gwt/build.xml \
--replace-fail '@node@' ${nodejs} \
--replace-fail './lib/quarto' ${quartoSrc}
substituteInPlace src/cpp/conf/rsession-dev.conf \
--replace-fail '@node@' ${nodejs}
substituteInPlace src/cpp/core/libclang/LibClang.cpp \
--replace-fail '@libclang@' ${lib.getLib llvmPackages.libclang} \
--replace-fail '@libclang.so@' ${lib.getLib llvmPackages.libclang}/lib/libclang.so
substituteInPlace src/cpp/session/CMakeLists.txt \
--replace-fail '@pandoc@' ${pandoc} \
--replace-fail '@quarto@' ${quarto}
substituteInPlace src/cpp/session/include/session/SessionConstants.hpp \
--replace-fail '@pandoc@' ${pandoc}/bin \
--replace-fail '@quarto@' ${quarto}
'';

hunspellDictionaries = lib.filter lib.isDerivation (lib.unique (lib.attrValues hunspellDicts));
# These dicts contain identically-named dict files, so we only keep the
# -large versions in case of clashes
Expand All @@ -170,25 +159,35 @@ stdenv.mkDerivation rec {
dictionaries = largeDicts ++ otherDicts;

preConfigure = ''
# set up node_modules directory inside quarto so that panmirror can be built
mkdir src/gwt/lib/quarto
cp -r --no-preserve=all ${quartoSrc}/* src/gwt/lib/quarto
pushd src/gwt/lib/quarto
yarnConfigHook
popd
mkdir dependencies/dictionaries
for dict in ${builtins.concatStringsSep " " dictionaries}; do
for i in "$dict/share/hunspell/"*; do
ln -s $i dependencies/dictionaries/
done
done
unzip -q ${mathJaxSrc} -d dependencies/mathjax-27
ln -s ${quarto} dependencies/quarto
ln -s ${mathJaxSrc} dependencies/mathjax-27
# our pandoc version is different, but we don't care
mkdir -p dependencies/pandoc/2.18
ln -s ${lib.getBin pandoc}/bin/* dependencies/pandoc/2.18
# As of Chocolate Cosmos, node 18.20.3 is used for runtime
# 18.18.2 is still used for build
# see https://github.com/rstudio/rstudio/commit/facb5cf1ab38fe77813aaf36590804e4f865d780
mkdir -p dependencies/common/node/18.20.3
mkdir -p dependencies/pandoc/${pandoc.version}
cp ${pandoc}/bin/pandoc dependencies/pandoc/${pandoc.version}/pandoc
cp -r ${rsconnectSrc} dependencies/rsconnect
( cd dependencies && ${R}/bin/R CMD build -d --no-build-vignettes rsconnect )
# our node version is different, but we don't care
mkdir -p dependencies/common/node
ln -s ${nodejs} dependencies/common/node/18.20.3
'';

postInstall = ''
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
diff --git a/src/cpp/session/CMakeLists.txt b/src/cpp/session/CMakeLists.txt
index 0202e84..596b9f8 100644
--- a/src/cpp/session/CMakeLists.txt
+++ b/src/cpp/session/CMakeLists.txt
@@ -59,11 +59,7 @@ endif()


# install pandoc
-# - by default, we use quarto + quarto's bundled pandoc
-# - if quarto is not enabled, use pandoc fallback
-if(QUARTO_ENABLED)
- set(RSTUDIO_DEPENDENCIES_PANDOC_DIR "${RSTUDIO_DEPENDENCIES_QUARTO_DIR}/bin/tools")
-elseif(EXISTS "${RSTUDIO_TOOLS_ROOT}/pandoc/${PANDOC_VERSION}")
+if(EXISTS "${RSTUDIO_TOOLS_ROOT}/pandoc/${PANDOC_VERSION}")
set(RSTUDIO_DEPENDENCIES_PANDOC_DIR "${RSTUDIO_TOOLS_ROOT}/pandoc/${PANDOC_VERSION}")
else()
set(RSTUDIO_DEPENDENCIES_PANDOC_DIR "${RSTUDIO_DEPENDENCIES_DIR}/pandoc/${PANDOC_VERSION}")
@@ -733,11 +729,10 @@ if(NOT RSTUDIO_SESSION_WIN32 AND NOT RSESSION_ALTERNATE_BUILD)
PATTERN ".gitignore"
EXCLUDE)
endif()
- else()
- install(DIRECTORY "${RSTUDIO_DEPENDENCIES_PANDOC_DIR}/"
- DESTINATION "${RSTUDIO_INSTALL_BIN}/pandoc"
- USE_SOURCE_PERMISSIONS)
endif()
+ install(DIRECTORY "${RSTUDIO_DEPENDENCIES_PANDOC_DIR}/"
+ DESTINATION "${RSTUDIO_INSTALL_BIN}/pandoc"
+ USE_SOURCE_PERMISSIONS)

# install embedded packages
foreach(PKG ${RSTUDIO_EMBEDDED_PACKAGES})
diff --git a/src/cpp/session/include/session/SessionConstants.hpp b/src/cpp/session/include/session/SessionConstants.hpp
index e6aef22..57491ec 100644
--- a/src/cpp/session/include/session/SessionConstants.hpp
+++ b/src/cpp/session/include/session/SessionConstants.hpp
@@ -147,11 +147,7 @@
#define kSessionTmpDirEnvVar "RS_SESSION_TMP_DIR"
#define kSessionTmpDir "rstudio-rsession"

-#ifdef QUARTO_ENABLED
-# define kDefaultPandocPath "bin/quarto/bin/tools"
-#else
# define kDefaultPandocPath "bin/pandoc"
-#endif

#define kDefaultNodePath "bin/node"
#define kDefaultQuartoPath "bin/quarto"
16 changes: 16 additions & 0 deletions pkgs/applications/editors/rstudio/dont-yarn-install.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/src/gwt/build.xml b/src/gwt/build.xml
index 27ffe33..4218678 100644
--- a/src/gwt/build.xml
+++ b/src/gwt/build.xml
@@ -139,11 +139,6 @@
<echo message="panmirror minify: ${panmirror.minify}"/>

<mkdir dir="${panmirror.build.dir}"/>
- <exec executable="${yarn.bin}" dir="${panmirror.dir}" resolveexecutable="true" failonerror="true">
- <arg value="install"/>
- <arg value="--network-timeout"/>
- <arg value="240000"/>
- </exec>
<exec executable="${yarn.bin}" dir="${panmirror.dir}" resolveexecutable="true" failonerror="true">
<arg value="build"/>
<arg value="--minify"/>
18 changes: 0 additions & 18 deletions pkgs/applications/editors/rstudio/pandoc-nix-path.patch

This file was deleted.

68 changes: 0 additions & 68 deletions pkgs/applications/editors/rstudio/use-system-node.patch
Original file line number Diff line number Diff line change
Expand Up @@ -11,71 +11,3 @@ index d18362b..98cdd4c 100644

# enable copilot
copilot-enabled=1
diff --git a/src/gwt/build.xml b/src/gwt/build.xml
index 033d605..f1ee63d 100644
--- a/src/gwt/build.xml
+++ b/src/gwt/build.xml
@@ -87,29 +87,7 @@
<!-- ensure version matches RSTUDIO_NODE_VERSION -->
<property name="node.version" value="18.18.2"/>
<property name="node.dir" value="../../dependencies/common/node/${node.version}"/>
- <!-- use yarn from system but will prefer yarn from dependencies if available -->
- <condition property="yarn.bin" value="yarn">
- <not>
- <os family="windows" />
- </not>
- </condition>
- <available
- property="yarn.bin"
- value="${node.dir}/bin/yarn"
- file="${node.dir}/bin/yarn"/>
- <condition property="yarn.bin" value="${node.dir}/node_modules/yarn/bin/yarn.cmd">
- <os family="windows" />
- </condition>
- <!-- use yarn from /opt/rstudio-tools if installed (typical for Docker) -->
- <available
- property="yarn.bin"
- value="/opt/rstudio-tools/dependencies/common/node/${node.version}/bin/yarn"
- file="/opt/rstudio-tools/dependencies/common/node/${node.version}/bin/yarn"/>
- <!-- use yarn from c:/rstudio-tools if installed (typical for Docker on Windows) -->
- <available
- property="yarn.bin"
- value="c:\rstudio-tools\dependencies\common\node\${node.version}\node_modules\yarn\bin\yarn.cmd"
- file="c:\rstudio-tools\dependencies\common\node\${node.version}\node_modules\yarn\bin\yarn.cmd"/>
+ <property name="node.bin" value="@node@/bin/node"/>

<property name="panmirror.dir" value="./lib/quarto/apps/panmirror"/>
<property name="panmirror.build.dir" value="./www/js/panmirror"/>
@@ -133,28 +111,11 @@
<isset property="panmirror.minify" />
</not>
</condition>
-
- <echo message="yarn location: ${yarn.bin}"/>
- <echo message="panmirror location: ${panmirror.dir}"/>
- <echo message="panmirror minify: ${panmirror.minify}"/>
-
<mkdir dir="${panmirror.build.dir}"/>
- <exec executable="${yarn.bin}" dir="${panmirror.dir}" resolveexecutable="true" failonerror="true">
- <arg value="install"/>
- <arg value="--network-timeout"/>
- <arg value="240000"/>
- </exec>
- <exec executable="${yarn.bin}" dir="${panmirror.dir}" resolveexecutable="true" failonerror="true">
- <arg value="build"/>
- <arg value="--minify"/>
- <arg value="${panmirror.minify}"/>
- <arg value="--sourcemap"/>
- <arg value="true"/>
- <env key="PANMIRROR_OUTDIR" value="dist-rstudio"/>
+ <exec executable="${node.bin}" dir="${panmirror.dir}" spawn="${panmirror.spawn}">
+ <arg value="fuse"/>
+ <arg value="${panmirror.target}"/>
</exec>
- <copy todir="${panmirror.build.dir}">
- <fileset dir="${panmirror.dir}/dist-rstudio"/>
- </copy>
</target>

<target name="javac" description="Compile java source">

46 changes: 0 additions & 46 deletions pkgs/applications/editors/rstudio/use-system-quarto.patch

This file was deleted.

0 comments on commit 1da1c18

Please sign in to comment.