Attribute nix not found while building a package

Hi!

I’m making my very first NixOS package as a beginner user. It’s an lsp server to work on a static site generator called Hugo but I’m clueless about what’s going wrong with it in spite of checking similar topics on the forum as well as going through the official guide step by step a couple of times.

So, basically I get the following error:

error: attribute ‘nix’ in selection path ‘go-template-lsp.nix’ not found

I feel there isn’t wrong with the code but maybe the way I setup Nix has to do with this since it is managed by the following flake:

~/waves-config/flake.nix

{
  description = "Waves in a room set up";
  inputs = {
    nixpkgs.url = "nixpkgs/nixos-25.11";
    home-manager = {
      url = "github:nix-community/home-manager/release-25.11";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };
  outputs = { self, nixpkgs, home-manager, ... }:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs { inherit system; };
    in {
      nixosConfigurations.hplaptop = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ./configuration.nix
          home-manager.nixosModules.home-manager
          {
            home-manager = {
              useGlobalPkgs = true;
              useUserPackages = true;
              users.wavesinaroom = import ./home.nix;
              backupFileExtension = "backup";
            };
          }
        ];
      };
    };
}

~/waves-config/packages/default.nix

let
  nixpkgs = fetchTarball “https://github.com/NixOS/nixpkgs/tarball/nixos-25.11”;
  pkgs = import nixpkgs {config = { };overlays = ;};
in { go-template-lsp = pkgs.callPackage ./go-template-lsp.nix { }; }

~/waves-config/packages/go-template-lsp.nix

{ stdenv, fetchFromGithub, go }:
stdenv.mkDerivation {
  pname = “go-template-lsp”;
  version = “0.3.4”;
  src = fetchFromGithub {
    owner = “yayolande”;
    repo = “go-template-lsp”;
    rev = “v0.3.4”;
    sha256 = “nix-prefetch-url command output”;
  };
  buildInputs = [ go ];
  preInstall = 
    ‘’
      go get -u
      go build
    ‘’;
  installPhase = 
    ‘’
      runhook preInstall
      mkdir -p $out/bin
      cp go-template-lsp $out/bin
    ‘’;
}

What’s selection path? How can I check it with a nix command? What am I missing/doing wrong this time?

I’d love to learn why things work/don’t work so if you feel I should research some concepts please make your suggestions. I’d be happy to check them out

Can you please share the full error message, including the mentioned filename and error position?

I do not see where the error could come from, just seeing this 3 files.

1 Like

I second @NobbZ wish for the full error message. I also wonder why you are not using pkgs.buildGoModule?

2 Likes

Without the full error message it is somewhat hard to tell. But at least this line contains a syntax error (overlays = ; is missing a value), if both arguments are empty you can also elid them or, in case you want to define them explicitly, replace overlays = ; with overlays = [];. The syntax error would throw quite a different error message, so maybe this was just a manual transfer issue when posting to discourse.

The go-template-lsp.nix itself does not look like it contains any obvious errors. However, it will almost certainly not build with the nix sandbox as go get -u will require an internet connection. Please refer to the nixpkgs manual on packaging Go applications for the relevant packaging helpers. You can also find various examples in nixpkgs, like wego.

Based on the error message, I suspect you forgot the ./ on what you intended to be a path-type. But the file giving the error is very likely not among those you pasted.

2 Likes

Sure!

Here you go a new version with -v flag passed to nix-build command:

~/waves-nixconfig/packages (main *%)-> nix-build -Av go-template-lsp.nix
error: cannot evaluate a function that has an argument without a value ('stdenv')
       Nix attempted to evaluate a function as a top level expression; in
       this case it must have its arguments supplied either by default
       values, or passed explicitly with '--arg' or '--argstr'. See
       https://nix.dev/manual/nix/stable/language/syntax.html#functions.
       at /home/wavesinaroom/waves-nixconfig/packages/go-template-lsp_old.nix:1:3:
            1| { stdenv, fetchFromGithub, go }:
             |   ^
            2| stdenv.mkDerivation {

Sorry about not having the overlay square brackets in the question. I wasn’t easy to format my code in my question. It does exist in my source code though :smiley: Thanks for pointing that out anyway!

The path is correct this time, thanks for taking time to read my question :slight_smile:

This error is completely different from what you have shown before.

It means you are using callPackage wrong or not at all, please share the default.nix

Alright folks!

First of all, thanks for taking time to read my question. Again this is my first time packaging on NixOS therefore I didn’t know about the existence of buildGoModule till now, so cheers for that.

Now, I spent a bit of time reading the documentation and coding a new expression with buildGoModule. I made more sense to do it it that way because I don’t need to bring go into the game like I did on my first version with buildInputs = [ go];. However I’ve got a similar output to the one I shared with @NobbZ.

Here you go the error message:

~/waves-nixconfig/packages (main *%)-> nix-build -Av go-template-lsp.nix
error: cannot evaluate a function that has an argument without a value ('buildGoModule')
       Nix attempted to evaluate a function as a top level expression; in
       this case it must have its arguments supplied either by default
       values, or passed explicitly with '--arg' or '--argstr'. See
       https://nix.dev/manual/nix/stable/language/syntax.html#functions.
       at /home/wavesinaroom/waves-nixconfig/packages/go-template-lsp.nix:1:3:
            1| { buildGoModule, fetchFromGithub }: {
             |   ^
            2|   lsp = buildGoModule (finalAttrs: {

This is my code:

{ buildGoModule, fetchFromGithub }: {
  lsp = buildGoModule (finalAttrs: {
    pname = "go-template-lsp.nix";
    version = "0.3.4";
    src = fetchFromGithub {
      owner = "yayolande";
      repo = "go-template-lsp";
      version = "v${finalAttrs.version}";
      hash = "sha256-18jcyknq9yhbcilk0gbshvbiszyffbjhxn2g6gcrrmnbykns7gj4";
    };

    meta = {
      description =
        "Language server to be used with Hugo static page generator";
      homepage = "https://github.com/yayolande/go-template-lsp";
    };

  });
}

What I don’t this time is that Nix complains about not being able to know what buildGoModule is but I find that weird because there’s already a default.nix file that helps Nix use the pkgs. If this is not the case, what’s causing the problem?

Oh I understand, you can see my default.nix file in the question.

callPackage is called there btw

Btw, you can make code blocks like this:
```
foo
```
becomes:

foo

It makes for much more readable pastes of terminal output or nix code.

1 Like

Thanks! I could finally find out that the rich text editor option was on hence messing my code

No! In impure evaluation (as it happens here) there is a difference between import nixpkgs {} and import nixpkgs {config = {}; overlays = [];}. The former will lookup ~/.config/nixpkgs/config.nix for config as well as ~/.config/nixpkgs/overlays.nix for overlays.

I took the OP packages/default.nix and fixed the obvious syntax errors, then I tried to build with the go-template-lsp.nix from the replied to post.

I again fixed issues as I went, never seeing the error you mentioned.

What I did though was using nix-build -A go-template-lsp.lsp, as that is the attribute path you have choosen for whatever reason.

I was able to get to the point that the deps should be fetched, though that fails, as the repo in question is broken, as it doesn’t commit a go.sum (lock file for go modules), this is required.

The changes I made so far to get where I am now:

diff --git a/default.nix b/default.nix
index 2cd0113f92..74a95b9996 100644
--- a/default.nix
+++ b/default.nix
@@ -1,4 +1,4 @@
 let
-  nixpkgs = fetchTarball “https://github.com/NixOS/nixpkgs/tarball/nixos-25.11”;
-  pkgs = import nixpkgs {config = { };overlays = ;};
+  nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-25.11";
+  pkgs = import nixpkgs {config = { };overlays = [];};
 in { go-template-lsp = pkgs.callPackage ./go-template-lsp.nix { }; }
diff --git a/go-template-lsp.nix b/go-template-lsp.nix
index b1bd945ebd..7f22f6be90 100644
--- a/go-template-lsp.nix
+++ b/go-template-lsp.nix
@@ -1,15 +1,17 @@

-{ buildGoModule, fetchFromGithub }: {
+{ buildGoModule, fetchFromGitHub }: {
   lsp = buildGoModule (finalAttrs: {
     pname = "go-template-lsp.nix";
     version = "0.3.4";
-    src = fetchFromGithub {
+    src = fetchFromGitHub {
       owner = "yayolande";
       repo = "go-template-lsp";
-      version = "v${finalAttrs.version}";
-      hash = "sha256-18jcyknq9yhbcilk0gbshvbiszyffbjhxn2g6gcrrmnbykns7gj4";
+      tag = "v${finalAttrs.version}";
+      hash = "sha256-ArfnJzPS4I4BsqOSlosuJNQfpU5V/FeTzSQyC/Xnfro=";
     };

+    vendorHash = "";
+
     meta = {
       description =
         "Language server to be used with Hugo static page generator";
1 Like

This was helpful, my derivation went well, thanks! I made changes on my side and set vendorHash to null meaning vendorHash = null so this reply complements your changes.

Just last two questions:

I couldn’t find anywhere in my code a line that chooses that attribute path. How and where did I choose? Sorry this is a bit confusing

Last question: How did you copy and paste the git diff like of your changes and my code?

default.nix specifies, go-template-lsp and withing that you have nested the actual derivation under the lsp attribute for whatever reason. It is more common to have not wrap within a callpackaged file.

I selected it in the terminal and then copied it, pasting it back into the browser. Just standard copy/paste workflow.


vendorHash = null is the same as vendorHash = "", I do not see any reason why it should succeed using that, as upstream still lacks a go.sum.

Yeah, you’re right! I see that now, the reason for doing that is because I followed the official guide to strictly to be sure that the derivation work but indeed there’s no need for doing that I get what you mean.

Alright, I thought the forum had a special option for that

I didn’t get any error here but I’ll double-check that. The original repo had an incomplete checklist of features so it’s not surprise that it’s broken, you found that out. That’s a bummer, but I’m cool with having the experience of trying to make my first nix package.

Do you have the sandbox disabled? Though even if force disable it for a test, I get a failing build:

$ sudo nix-build -A go-template-lsp.lsp --option sandbox false --builders ''
unpacking 'https://github.com/NixOS/nixpkgs/tarball/nixos-25.11' into the Git cache...
this derivation will be built:
  /nix/store/vws3h235f5w40139bn5wmbxvhkw5rs3m-go-template-lsp.nix-0.3.4.drv
building '/nix/store/vws3h235f5w40139bn5wmbxvhkw5rs3m-go-template-lsp.nix-0.3.4.drv'...
Running phase: unpackPhase
unpacking source archive /nix/store/gpyak09dkk7fn5xljcsqwm85g0qy7q61-source
source root is source
Running phase: patchPhase
Running phase: updateAutotoolsGnuConfigScriptsPhase
Running phase: configurePhase
Running phase: buildPhase
Building subPackage .
lsp/methods.go:10:2: cannot find module providing package github.com/yayolande/gota: import lookup disabled by -mod=vendor
lsp/methods.go:11:2: cannot find module providing package github.com/yayolande/gota/analyzer: import lookup disabled by -mod=vendor
lsp/methods.go:12:2: cannot find module providing package github.com/yayolande/gota/lexer: import lookup disabled by -mod=vendor
lsp/methods.go:13:2: cannot find module providing package github.com/yayolande/gota/parser: import lookup disabled by -mod=vendor

Run your command on your end and got a clean output, weird I know.

I know screenshots aren’t cool for questions about programming but just wanted to show you what I actually saw in my screen