Update shell with most recent custom go module build

Hi!

I’m working on a project that needs its binary to be built constantly. That binary (a language server) is included as a dependency in my shell buildInputs because I want to test it without leaving my shell of my tmux session from that shell. I can build that dependency with nix-build --expr '(import <nixpkgs> {}).callPackage ./lspbuilder.nix {} my issue is that my shell doesn’t point (if that’s the right word) to this new version but stays with the one I started my shell with.

My current solution to this problem is to leave the shell and enter again but this is an impractical workflow that will become annoying after a while. My projects needs frequent builds and this workflow won’t be helpful.

Is there a way buildInputs points to my build most recent version? Should I run a flag for nix-shell that accomplishes that?

shell.nix

{pkgs ? import <nixpkgs>{}}:  
pkgs.mkShell {
  packages = with pkgs; [
    go gopls golangci-lint delve gotools 
  ]; 
  buildInputs = with pkgs; [ (callPackage ./lspbuilder.nix {})];
  hardeningDisable = ["fortify"];
  shellHook = ''nu'';
}

lspbuilder.nix

{buildGoModule}:
buildGoModule(finalAttrs: {
  pname = "cslsp";
  version = "0.1";

  src = ./.;
  vendorHash = null;
})

Try direnv instead and you can run direnv reload

2 Likes

Thanks! That’s a good idea. I never thought about it. Right now nixos-rebuild switch freezes on my system when I try to install packages so if your suggestion works I’ll mark it as a the solution to the problem.

1 Like

Alright I’m trying direnv but it falls into infinite recursion. I wonder if calling callPackage ../lspbuilder.nix has anything to do with this issue, I’m not a direnv expert. I’ll spend some time finding out.

On a first glance I do not see anything in the posted code that would lead to an infrec, do you mind sharing a reproducer?

1 Like

Hi! Thanks for taking time!

Just found that shellHook = ''nu''; line was the trouble maker :). Why? I had a previous system that used bash as the default shell.

Alright, I solved my problem with nixos-rebuild switch however direnv reload didn’t work. I guess that the issue here is that tmux creates a new shell maybe but I don’t think it reflects the one you run the shell from. I might be wrong though, will try to open the shell inside tmux to see if that helps.