How to get R Console working in Positron with Nix and direnv setup?

Here’s a concise and clear version of your question for posting to Posit Community or Positron support:


:question: How can I get the R Console to start in Positron with a Nix + direnv setup?

I’m using Nix with direnv to configure my development environment, and I launch R through a shell.nix file like this:

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  buildInputs = [
    pkgs.R
    pkgs.python3
    pkgs.bashInteractive
    pkgs.glibcLocales
  ];

  shellHook = ''
    export LANG=en_US.UTF-8
    export LC_ALL=en_US.UTF-8
    export R_HOME=$(${pkgs.R}/bin/R RHOME)
    export PATH=${pkgs.R}/bin:$PATH
  '';
}

My .envrc simply contains:

use nix

Everything works as expected in a normal terminal:

  • R runs
  • $R_HOME is set
  • IN_NIX_SHELL=impure

But in Positron:

  • The R Console fails to start
  • The terminal inside Positron reports R: command not found
  • I confirmed that direnv is not sourcing .envrc in that terminal

I also tried adding this to settings.json:

"positron.r.customBinaries": [
  "/nix/store/.../bin/R"
]

But it still doesn’t start the R console.


:white_check_mark: What I’m looking for:

  • How can I ensure Positron terminal and R console run inside my Nix shell ?
  • Is there a Positron-specific way to load .bashrc or .envrc?
  • Should I create a wrapper script or use a login shell setting?

Let me know if anything else should be included. I’m happy to share logs or exact paths if needed.


Let me know if you want to customize that more, or I can post it in a format suitable for GitHub issues, community.posit.co, or Stack Overflow.