diff --git a/.Rprofile b/.Rprofile new file mode 100644 index 0000000..7617f61 --- /dev/null +++ b/.Rprofile @@ -0,0 +1,5 @@ +if (Sys.getenv("RNVIM_TMPDIR") == "") { + options(defaultPackages = c("utils", "grDevices", "graphics", "stats", "methods")) +} else { + options(defaultPackages = c("utils", "grDevices", "graphics", "stats", "methods", "nvimcom")) +} diff --git a/.commandcode/taste/taste.md b/.commandcode/taste/taste.md new file mode 100644 index 0000000..4b588b2 --- /dev/null +++ b/.commandcode/taste/taste.md @@ -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/ + diff --git a/flake.lock b/flake.lock index bc20095..b67b913 100644 --- a/flake.lock +++ b/flake.lock @@ -22,11 +22,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1777954456, - "narHash": "sha256-hGdgeU2Nk87RAuZyYjyDjFL6LK7dAZN5RE9+hrDTkDU=", + "lastModified": 1778443072, + "narHash": "sha256-zi7/fsqM/kFdNuED//4WOCUtezGtKKqRNORjMvfwjnA=", "owner": "nixos", "repo": "nixpkgs", - "rev": "549bd84d6279f9852cae6225e372cc67fb91a4c1", + "rev": "da5ad661ba4e5ef59ba743f0d112cbc30e474f32", "type": "github" }, "original": { @@ -69,19 +69,42 @@ "type": "github" } }, - "rixpkgs": { + "r-nvim-nix": { + "inputs": { + "nixpkgs": [ + "rixpkgs" + ], + "rnvimsrc": [ + "plugins-r" + ] + }, "locked": { - "lastModified": 1778520264, - "narHash": "sha256-OjpxoQsZSsyXJxtgKJsbNKX5KaSZRaEeaqQj3rmI5uM=", + "lastModified": 1778643549, + "narHash": "sha256-dJBdYawL+/IVtmXLFZ+kQGOo5fd1cliDJJdJEi0Mqqw=", "owner": "dwinkler1", - "repo": "rixpkgs", - "rev": "88147cbbf4be689ea32ed5cbf9370a6aa95fd08e", + "repo": "r_nvim_nix", + "rev": "c7b880dde56b4fcef09938e311415b63f2262498", "type": "github" }, "original": { "owner": "dwinkler1", - "ref": "nixpkgs", + "repo": "r_nvim_nix", + "type": "github" + } + }, + "rixpkgs": { + "locked": { + "lastModified": 1771303851, + "narHash": "sha256-tgveHozOJ2D/mi3LxVy/FcmLFDlM5XKZxsNB2XpvzaM=", + "owner": "dwinkler1", "repo": "rixpkgs", + "rev": "af2dd3f7b4b172077747c0869d4e30702fb71b0e", + "type": "github" + }, + "original": { + "owner": "dwinkler1", + "repo": "rixpkgs", + "rev": "af2dd3f7b4b172077747c0869d4e30702fb71b0e", "type": "github" } }, @@ -91,6 +114,7 @@ "nixpkgs": "nixpkgs", "plugins-cmp-pandoc-references": "plugins-cmp-pandoc-references", "plugins-r": "plugins-r", + "r-nvim-nix": "r-nvim-nix", "rixpkgs": "rixpkgs", "wrappers": "wrappers" } diff --git a/flake.nix b/flake.nix index 8482605..1ffa69a 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,11 @@ url = "github:BirdeeHub/nix-wrapper-modules"; inputs.nixpkgs.follows = "nixpkgs"; }; - rixpkgs.url = "github:dwinkler1/rixpkgs/nixpkgs"; + rixpkgs.url = "github:dwinkler1/rixpkgs/af2dd3f7b4b172077747c0869d4e30702fb71b0e"; + + r-nvim-nix.url = "github:dwinkler1/r_nvim_nix"; + r-nvim-nix.inputs.rnvimsrc.follows = "plugins-r"; + r-nvim-nix.inputs.nixpkgs.follows = "rixpkgs"; fran = { url = "github:dwinkler1/fran"; @@ -46,7 +50,7 @@ nix = true; optional = false; python = false; - r = false; + r = true; }; settings = { lang_packages = { @@ -61,6 +65,7 @@ janitor languageserver styler + pkgs.nvimcom ]; julia = ["DataFramesMeta" "QuackIO"]; }; @@ -187,6 +192,8 @@ air-formatter yaml-language-server updateR + nvimcom + rnvimserver ]; juliaPackages = let @@ -199,7 +206,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 +218,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" + ''; }; } ); diff --git a/modules/module/settings/cats.nix b/modules/module/settings/cats.nix index 22b3638..3da043e 100644 --- a/modules/module/settings/cats.nix +++ b/modules/module/settings/cats.nix @@ -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; diff --git a/modules/module/settings/env.nix b/modules/module/settings/env.nix index 2ae4b9c..14e0a32 100644 --- a/modules/module/settings/env.nix +++ b/modules/module/settings/env.nix @@ -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}/library:$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}/library:$PWD/.Rlibs"; }) ]; } diff --git a/modules/module/specs/plugins.nix b/modules/module/specs/plugins.nix index ded8195..a47ba65 100644 --- a/modules/module/specs/plugins.nix +++ b/modules/module/specs/plugins.nix @@ -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.rnvimserver}/bin/rnvimserver $out/rnvimserver/rnvimserver + chmod +x $out/rnvimserver/rnvimserver + ''; + })) quarto-nvim { data = otter-nvim; diff --git a/overlays/default.nix b/overlays/default.nix index 821ff88..ebb6518 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -3,12 +3,14 @@ let lib = nixpkgs.lib; rOverlay = import ./r.nix {inherit inputs;}; + rNvimNixOverlay = inputs.r-nvim-nix.overlays.default; franOverlay = inputs.fran.overlays.default; pythonOverlay = import ./python.nix inputs; pluginsOverlay = import ./plugins.nix inputs; dependencyOverlays = [ rOverlay + rNvimNixOverlay pythonOverlay pluginsOverlay ]; @@ -17,6 +19,7 @@ in { inherit rOverlay + rNvimNixOverlay franOverlay pythonOverlay pluginsOverlay @@ -30,6 +33,7 @@ in overlays = { inherit rOverlay + rNvimNixOverlay franOverlay pythonOverlay pluginsOverlay diff --git a/overlays/r.nix b/overlays/r.nix index 2fb71c8..a9961fb 100644 --- a/overlays/r.nix +++ b/overlays/r.nix @@ -33,6 +33,9 @@ overlays = [inputs.fran.overlays.default]; }; # rixpkgs.legacyPackages.${prev.stdenv.hostPlatform.system}; + # nvimcom and rnvimserver are provided by the r-nvim-nix flake overlay + # (inputs.r-nvim-nix.overlays.default) + # Standard R packages used by default in rWrapper and quarto reqPkgs = with rpkgs.rPackages; [ # languageserver diff --git a/plugin/21_datascience.lua b/plugin/21_datascience.lua index 118ee20..62d8f49 100644 --- a/plugin/21_datascience.lua +++ b/plugin/21_datascience.lua @@ -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()