fixed R.nvim

This commit is contained in:
Daniel Winkler 2026-05-12 15:58:31 +10:00
commit 07d2156dfb
7 changed files with 65 additions and 7 deletions

View file

@ -0,0 +1,8 @@
# nix
- For R.nvim in the Nix wrapper, both RNVIM_COMPLDIR (C server compilation) and a writable R_LIBS_USER directory (nvimcom R package installation) must be configured — fixing only one leaves permission errors in the other. Confidence: 0.65
- For R.nvim writable directories (RNVIM_COMPLDIR, R_LIBS_USER, TMPDIR), prefer project-local paths (e.g., $PWD/.Rlibs) over global cache paths — the cache approach may let the build succeed but still fail at runtime. Confidence: 0.70
# Taste (Continuously Learned by [CommandCode][cmd])
[cmd]: https://commandcode.ai/

View file

@ -46,7 +46,7 @@
nix = true;
optional = false;
python = false;
r = false;
r = true;
};
settings = {
lang_packages = {
@ -199,7 +199,8 @@
zk
];
shellPackages = [nvimPkg]
shellPackages =
[nvimPkg]
++ pkgs.lib.optionals cfg.cats.python pythonPackages
++ pkgs.lib.optionals cfg.cats.r rPackages
++ pkgs.lib.optionals cfg.cats.julia juliaPackages
@ -210,7 +211,13 @@
packages = shellPackages;
nativeBuildInputs = with pkgs; [] ++ (pkgs.lib.optionals cfg.cats.optional [devenv]);
inputsFrom = [];
shellHook = "";
shellHook = ''
echo 'I am a NixShell'
export R_HOME=$(R RHOME)
export R_LIBS_SITE=$(strings "$(command -v R)" | grep -oP '/nix/store/[^:]+/library' | sort -u | paste -sd: -)
export R_LIBS_USER="$PWD/.r-libs"
mkdir -p "$R_LIBS_USER"
'';
};
}
);

View file

@ -43,7 +43,7 @@
nix = lib.mkDefault true;
optional = lib.mkDefault false;
python = lib.mkDefault false;
r = lib.mkDefault false;
r = lib.mkDefault true;
test = lib.mkDefault false;
treesitterParsers = lib.mkDefault true;
utils = lib.mkDefault true;

View file

@ -11,12 +11,17 @@
UV_PYTHON_DOWNLOADS = "never";
UV_PYTHON = pkgs.python.interpreter;
})
(lib.mkIf (config.cats.r or false) {
RNVIM_COMPLDIR = "$PWD/.r-compl";
R_LIBS_USER = "${pkgs.nvimcom}:$PWD/.Rlibs";
TMPDIR = "$PWD/.r-tmp";
})
];
# Environment variables with defaults (can be overridden by user)
config.envDefault = lib.mkMerge [
(lib.mkIf (config.cats.r or false) {
R_LIBS_USER = "./.Rlibs";
R_LIBS_USER = "${pkgs.nvimcom}:$PWD/.Rlibs";
})
];
}

View file

@ -11,7 +11,13 @@
config.specs.r = {
data = with pkgs.vimPlugins; [
config.nvim-lib.neovimPlugins.r
(config.nvim-lib.neovimPlugins.r.overrideAttrs (old: {
postInstall = (old.postInstall or "") + ''
mkdir -p $out/rnvimserver
cp ${pkgs.nvimcom}/bin/rnvimserver $out/rnvimserver/rnvimserver
chmod +x $out/rnvimserver/rnvimserver
'';
}))
quarto-nvim
{
data = otter-nvim;

View file

@ -33,12 +33,38 @@
overlays = [inputs.fran.overlays.default];
}; # rixpkgs.legacyPackages.${prev.stdenv.hostPlatform.system};
# Pre-build nvimcom from R.nvim plugin source so R.nvim never tries to
# compile it at runtime into the read-only nix store.
nvimcom = final.stdenv.mkDerivation {
pname = "nvimcom";
version = "0.9.92";
src = inputs.plugins-r;
nativeBuildInputs = [
(rpkgs.rWrapper.override { packages = []; })
];
buildPhase = ''
mkdir -p $out/bin
R CMD INSTALL -l $out nvimcom
cd rnvimserver
$CC -pthread -O2 -Wall \
complete.c resolve.c hover.c definition.c signature.c \
rhelp.c chunk.c roxygen.c data_structures.c logging.c \
rnvimserver.c obbr.c tcp.c utilities.c ../nvimcom/src/common.c \
-o $out/bin/rnvimserver
cd ..
mkdir -p $out/nvimcom/bin
cp $out/bin/rnvimserver $out/nvimcom/bin/rnvimserver
chmod +x $out/bin/rnvimserver $out/nvimcom/bin/rnvimserver
'';
installPhase = "true";
};
# Standard R packages used by default in rWrapper and quarto
reqPkgs = with rpkgs.rPackages; [
# languageserver
];
in {
inherit rpkgs;
inherit rpkgs nvimcom;
baseRPackages = reqPkgs;
# R wrapper with standard packages

View file

@ -44,6 +44,12 @@ end)
-- r
now(function()
if nix.get_cat("r", false) then
local cwd = vim.fn.getcwd(-1)
vim.env.RNVIM_COMPLDIR = cwd .. "/.r-compl"
vim.env.R_LIBS_USER = (vim.env.R_LIBS_USER or ""):gsub("%$PWD", cwd)
vim.env.TMPDIR = cwd .. "/.r-tmp"
vim.fn.mkdir(vim.env.RNVIM_COMPLDIR, "p")
vim.fn.mkdir(vim.env.TMPDIR, "p")
vim.g.rout_follow_colorscheme = true
require("r").setup({
-- Create a table with the options to be passed to setup()