Cannot install gopls using mason.nvim

I’m just starting with nixos (dont even use flakes). just use it as package manager.
While installing i get the following error:
Installing go package The Go Programming Language
# The Go Programming Language
/nix/store/bp39dh48cdqp89hk5mpdi1lxdf0mjl7x-go-1.22.1/share/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/nix/store/j2y057vz3i19yh4zjsan1s3q256q15rd-binutils-2.41/bin/ld: cannot find crt1.o: No such file or directory
/nix/store/j2y057vz3i19yh4zjsan1s3q256q15rd-binutils-2.41/bin/ld: cannot find crti.o: No such file or directory
/nix/store/j2y057vz3i19yh4zjsan1s3q256q15rd-binutils-2.41/bin/ld: cannot find -lgcc_s: No such file or directory
collect2: error: ld returned 1 exit status

    spawn: go failed with exit code 1 and signal 0. 

from what I’m guessing some tools are missing. i did installed standard build tools but it did not changed much.

Don’t use use the tools from mason. Instead, you should add packages to neovim in home-manager like so:

# home.nix
programs.neovim = {
  enable = true;
  extraPackages = with pkgs; [
    # Formatters
    gofumpt
    goimports-reviser
    golines

    # LSP
    gopls

    # Tools
    go
    gcc
    ...
  ];
};

If you don’t have home-manager installed, you can do it using the following manual:

https://nix-community.github.io/home-manager/

For more inspiration, you can also have a look at this configuration example that someone posted here before:

Yeah I tried that it worked, but i could not get R language server going so i gave up. :upside_down_face: :upside_down_face:

I believe you need to wrap R with the packages you need, then you pass that to neovim in home-manager. With the previous example, it would look like this:

# home.nix
{ config, pkgs, lib, ... }:

with pkgs;
let
  R-with-packages = rWrapper.override { packages = with rPackages; [ languageserver ]; };
in
{
  programs.neovim = {
    enable = true;
    extraPackages = with pkgs; [
      # Formatters
      gofumpt
      goimports-reviser
      golines

      # LSP
      gopls

      # Tools
      go
      gcc
    ] ++ [
      R-with-packages
    ];
  };
}

can I put it anywhere?? i just changed my


  programs.neovim = {
    enable = true;
    defaultEditor = true;
  }; 

to your given snippet and it is giving me

       error: syntax error, unexpected WITH

       at /etc/nixos/configuration.nix:136:2:

          135|
          136|     with pkgs;
             |     ^
          137|     let

I think you tried to put with pkgs; let .. in above programs.neovim, but it should be at the top of the module like in the following example:

https://wiki.nixos.org/wiki/NixOS_modules#Example

This won’t work in /etc/nixos/configuration.nix, however, as neovim.extraPackages only exists in home-manager:

I didn’t know that either, so I didn’t specify where it should be. My apologies :sweat_smile:
I edited my reply to correct that.

On a side note, you can keep this in /etc/nixos/configuration.nix. This is what I also have on my system.

So is there no way to do it without installing home manager??
I was delaying it as it looks little daunting. Guess I have no choice.

You might be able to do it using overrides, but I haven’t tried this:

I should probably look into home manager then fixing it idk but it doesn’t sit right with me. Thanks for your time.

1 Like

That probably would be the best choice as home-manager allows you to configure many things like shells, desktop themes and other stuff. It’s not too hard to set up either.

Good luck and happy nixing :snowflake:

1 Like