nix

How do you install a nix nodePackages entry that contains "@" in its name


Normally when installing a nix package, I do

{ config, pkgs, lib, osConfig, ... }:
{
# ... more stuff...
home.stateVersion = "23.05";
home.packages =  [

  pkgs.nodejs
  pkgs.typescript      
  pkgs.nodePackages.gitmoji-cli

  ...
]
}

now I want to install a new package with an "@" I get a syntax error

home.packages = [
    pkgs.nodejs
    pkgs.typescript      
    pkgs.nodePackages.gitmoji-cli
    pkgs.nodePackages.@withgraphite/graphite-cli
]

Solution

  • Add quotes around names that aren't valid on their own to use them as attrset keys. (This is not unique to Nix -- it's also syntax that works in jq, for example).

    To demonstrate, the following was run in a current nixpkgs source tree:

    $ NIXPKGS_ALLOW_UNFREE=1 nix repl
    Welcome to Nix 2.18.1. Type :? for help.
    
    nix-repl> pkgs = import ./. {}
    
    nix-repl> pkgs.nodePackages."@withgraphite/graphite-cli"
    «derivation /nix/store/jxkmxb3sl8ck5nxg3jbyp23736j3n4x7-graphite-cli-1.3.5.drv»
    
    nix-repl> pkgs.graphite-cli
    «derivation /nix/store/jxkmxb3sl8ck5nxg3jbyp23736j3n4x7-graphite-cli-1.3.5.drv»
    

    Note how the existence of an alias in nixpkgs means you don't need to access through nodePackages at all.