How do I install scoped packages via nix?

I’m trying to install “@angular/cli” but can’t figure out how. I see it is included pkgs/development/node-packages/node-packages.nix. I just can’t figure out the magic incantation to include it. It chokes on the @. For example:

$ nix-shell -p nodePackages.@angular/cli
error: syntax error, unexpected '@', expecting ID or OR_KW or DOLLAR_CURLY or '"'

       at «string»:1:120:

            1| {...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (nodePackages.@
             |

I tried out various guesses and even got nix to suggest it. For example:

$ nix-shell -p nodePackages.angular-cli
error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'shell'
         whose name attribute is located at /nix/store/q6grqq0faswzfizh2hs0zj0pn5zh008h-nixos-24.05/nixos/pkgs/stdenv/generic/make-derivation.nix:331:7

       … while evaluating attribute 'buildInputs' of derivation 'shell'

         at /nix/store/q6grqq0faswzfizh2hs0zj0pn5zh008h-nixos-24.05/nixos/pkgs/stdenv/generic/make-derivation.nix:378:7:

          377|       depsHostHost                = elemAt (elemAt dependencies 1) 0;
          378|       buildInputs                 = elemAt (elemAt dependencies 1) 1;
             |       ^
          379|       depsTargetTarget            = elemAt (elemAt dependencies 2) 0;

       error: attribute 'angular-cli' missing

       at «string»:1:107:

            1| {...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (nodePackages.angular-cli) ]; } ""
             |                                                                                                           ^
       Did you mean @angular/cli?

I know I’m missing some special syntax but can’t find it in the docs.

Did you try quoting it? Like nix-shell -p nodePackages."@angular/cli"

1 Like

Yup. Same result.

]$ nix-shell -p nodePackages."@angular/cli"
error: syntax error, unexpected '@', expecting ID or OR_KW or DOLLAR_CURLY or '"'

       at «string»:1:120:

            1| {...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (nodePackages.@
             |

For most shells, you need an additional layer of quoting (so that nix receives nodePackages."@angular/cli"), for example nix-shell -p 'nodePackages."@angular/cli"'.

4 Likes

I feel like a doofus. I thought it was a nix issue, but it was just a shell escaping issue. Thank you so much!