Pi coding agent: how to install (npm) extensions?

OK, so I came up with this solution (home-manager module):

{ pkgs, config, ... }:

{
  home.packages = [    
    (pkgs.symlinkJoin {
      name = "pi-coding-agent";
      buildInputs = [ pkgs.makeWrapper ];
      paths = [ pkgs.pi-coding-agent ];
      postBuild = ''
        wrapProgram $out/bin/pi \
          --set NPM_CONFIG_PREFIX ${config.home.homeDirectory}/.pi/npm/ \
          --prefix PATH : ${
            pkgs.lib.makeBinPath [
              pkgs.nodejs_latest
            ]
          }
      '';
    })
  ];
}

I’m redirecting NPM packages to ~/.pi/npm/ only for Pi, because I didn’t want to change the NPM global prefix via ~/.npmrc for all packages. By doing this, I have all Pi related NPM packages in one place. I’ve also tried to set PI_PACKAGE_DIR but that didn’t work (I guess that would have to be done during build time, but I’m not sure).

Also, note that I’ve added nodejs_latest to the runtime dependencies. Without Node.js, the plugins don’t work. Imo, this should be a dependency of the original nixpkgs derivation (because Pi is barely usable without extensions), but for some reason it’s not.

Of course, this is not an ideal solution (i.e. not fully declarative and reproducible). But as long as the nixpkgs package doesn’t support extension management, this works for me.

3 Likes