Skip to content

How To: Use vscode-ruby-lsp with flake.nix based dev enviroment #1851

@StoryparkNick

Description

@StoryparkNick

Description

Hello! Thanks for this awesome set of libraries.

This is not a bug report, rather a quick info dump for anyone who uses nix flakes and vscode-ruby-lsp and wants to use the custom Ruby activation to make use of the Ruby from their flake.nix.

In essence, add a command to your flake.nix outputs, hardcoded here to use aarch64-dawin.

      # used to help vscode-ruby-lsp find the appropriate ruby and gems
      packages.aarch64-darwin.activate-ruby = pkgs.writeScriptBin "activate-ruby-nix" ''
        echo "export GEM_HOME=\"$GEM_HOME\""
        echo "export GEM_PATH=\"$GEM_PATH\""
        echo "export PATH=\"$(command -v ruby | xargs dirname):$GEM_HOME/bin:\$PATH\""
      '';

Add the follow lines to your VSCode config:

  "rubyLsp.rubyVersionManager": "custom",
  "rubyLsp.customRubyCommand": "eval \"$(nix run .#activate-ruby)\"",

Restart code, this will ensure the GEM_HOME, GEM_PATH and PATH env variables are set correctly, and vscode-ruby-lsp should now be able to find the appropriate Ruby exposed by your flake.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions