How do I pull in node dependencies in my nix flake?

Hi lovely NixOS community,
Today I’ve been struggling to get my site up off the ground, because I need webpack with some pretty specific configuration and plugins, and I want to use nix flakes to declaratively and reproducibly manage those plugins. Once I created my package.json, I ran node2nix to no end; I was then unable to figure out how to create a simple devShell with all my packages in it that I could enter with nix develop. How do I create a flake for node2nix’s shell? Is there a better way than node2nix to pull in npm packages to my project?

1 Like

Little bit of context and specificity here. The attached nix shell, when run under nix develop, should give me my dependencies, but instead:

error: attribute 'shell' missing

       at /nix/store/cwfpc09sbb3d0l08svlas55nlincg413-source/shell.nix:6:7:

            5|       node2nix
            6|       (callPackage ./default.nix {}).shell.nodeDependencies
             |       ^
            7|     ];
(use '--show-trace' to show detailed location information)

shell.nix:

{ pkgs }: pkgs.mkShell {
  buildInputs = with pkgs;
    with nodePackages; [
      nodejs
      node2nix
      (callPackage ./default.nix {}).shell.nodeDependencies
    ];
  shellHook = ''
    export NODE_PATH=${pkgs.callPackage ./default.nix {}.shell.nodeDependencies}/lib/node_modules
  '';
}

Example: Coding-Dev-Env-With-NixFlake/flake.nix at 14340dc405871f1be5b5a4d50ea616c7923fe239 · GTrunSec/Coding-Dev-Env-With-NixFlake · GitHub

Here’s the thing about that: I know that will theoretically work, but I need to be able to pull in arbitrary dependencies with node2nix.

@GTrunSec What I’m trying to say is that my packages aren’t in nixpkgs.

Sorry my bad, how about this example logseq-nix-flake/dev-shell.nix at 4da67d351e7420f176a62c26b97840332292c965 · GTrunSec/logseq-nix-flake · GitHub

@rocky_fuchsian_frog , For the node2nix shell make sure you have got these exprs like nixpkgs/node-packages.nix at master · NixOS/nixpkgs · GitHub