29

Suppose I search for a package to install using nix-env's --query operation:

$ nix-env -qa 'aspell.*en'
aspell-dict-en-7.1-0

I write this package name in /etc/nixos/configuration.nix, NixOS's main configuration file:

environment.systemPackages = with pkgs; [
  aspell-dict-en
];

Yet if I run sudo nixos-rebuild switch, NixOS command to update the configuration and install all system-wide packages specified by declaratively, it aborts with an error:

error: undefined variable ‘aspell-dict-en’ at /etc/nixos/configuration.nix:44:5

I know that for many packages, although not all, the name that nix-env returns and the name one should specify in environment.systemPackages configuration option are different, but I don't understand the logic. How do I install a package that I found through nix-env?

6 Answers 6

27

NixOS community has three manuals, always consult them first, if you're stuck:

Every package on Nix is specified by a Nix expression. A Nix expression is some text, written in Nix language, typically residing in a file with extension .nix.

Every expression has the so-called “symbolic name”, a human-readable name that is printed, when you use nix-env. See sample Nix expression. Nix itself doesn't use this symbolic name anywhere internally, so it doesn't matter if your package is named aspell-dict-en, it's just for your, human's, convenience.

What actually matters is the so-called “attribute path”. So your confusion is between symbolic name and attribute path. Every package has an attribute path, which you can use in environment.systemPackages configuration option to install system-wide using declarative package management.

To find out your package's attribute path, add another flag -P to your query:

$ nix-env -qaP 'aspell.*en'
nixos.aspellDicts.en  aspell-dict-en-7.1-0

You should be comfortable using nix-env on a daily basis, so practice calling nix-env with --query and --install options. However you can also browse packages and find out their attribute paths online on Nix packages search. Type aspell, click on aspell-dict-en and you'll see various package's properties, including attribute path as part of the install command:

$ nix-env -iA nixos.pkgs.aspellDicts.en

Now you can put this attribute path into /etc/nixos/configuration.nix:

environment.systemPackages = with pkgs; [
  aspellDicts.en
];

Then update the system by running sudo nixos-rebuild switch.

1
  • 6
    Unfortunately, the -P option does not work with --installed, as can be seen with nix-env -q --installed -P | grep terminus which prints terminus-font instead of terminus_font. The workaround is to use nix-env -qaP | grep terminus-font, but it means that you can't easily dump the output of nix-env -q --installed into the configuration.nix. Oct 14, 2016 at 14:19
5

You can search for packages using the following website:


In case you are using NixOS for Data Science:

Python modules:

nix-env -qaP .\*pylint.\*

or

py_pkgs="nix_packages_py35.txt"
nix-env -qaP | grep -i python36 > ${py_pkgs}
grep pandas ${py_pkgs}

OR if your are searching especially for R packages/libraries

nix-env -f "<nixpkgs>" -qaP -A rPackages .\*tidyverse.\*

alternatively you get e.g. npm packages with:

nix-env -qaPA 'nixos.nodePackages'
1
nix-env -v -qaP '*' | grep "nvim"

I would save the result of nix-env -v -qaP '*' to a file (as it usually takes a while to return).


Bear in mind, nix-env seems to ignore things under haskellPackages (and possibly others). You can search for packages in subcategories such as haskellPackages via nix-env -f '<nixpkgs>' -qaPA haskellPackages


nix-env search is currently quite frustrating as it'll take 5+ seconds and then come back with a error: regex error...

0

Additional to Mirzhans options: you could check /nix/store like grep -irw "programm-name" /nix/store. But this could be a bit confusing. Also in your home directory you could check the directory .local/share for installed programms/apps.

0
nix-search () {
    local cache_file=~/.cache/nix/nix-env-qaP

    if [[ "$1" =~ ^--?c(ache)?$ ]]; then
        mkdir -p $(dirname $cache_file)
        echo -n "Caching packages.."
        nix-env -qaP '*' >$cache_file
        echo " 🏁"
    else
        grep -iE "$1" $cache_file
    fi
}
$ nix-search --cache
Caching packages.. 🏁

$ nix-search nodejs
nixpkgs.haxePackages.hxnodejs_4
nixpkgs.haxePackages.hxnodejs_6
nixpkgs.elmPackages.nodejs
nixpkgs.nodejs-16_x
nixpkgs.nodejs
nixpkgs.nodejs-18_x
nixpkgs.nodejs-slim-14_x
nixpkgs.nodejs-slim
nixpkgs.nodejs-slim-18_x
0

If you know the name of the excutable related to the package you could also use nix-locate (https://github.com/bennofs/nix-index).

nix-locate bin/hello      
haskellPackages.hscharm.out                     765,944 x /nix/store/m64bng6pyhq3dy1j0v6r5q7vymnbfrzx-hscharm-0.0.2/bin/hellocharm
haskellPackages.hello.out                       773,048 x /nix/store/gzkp9400ah5wzycfijcnw717b8v6i8gm-hello-1.0.0.2/bin/hello
python-cosmopolitan.out                       2,767,939 x /nix/store/cnz516l462r73k19pqf7kykdsxsj4zw5-python-cosmopolitan-3.6.14/bin/hello.com
mbedtls.out                                      48,720 x /nix/store/p9yww15m79lmdg678ipaqrvwi9wvj01r-mbedtls-2.28.0/bin/hello
(lutris-free.out)                                     0 s /nix/store/xyhi94jj4jbbmbl5wy83d91k4pnrw51g-lutris-fhs/usr/bin/hello
(lutris-free.out)                                     0 s /nix/store/av0syxwqf3a4mviiahiq4rv033dbj1gc-lutris-usr-target/bin/hello
hpx.out                                         234,312 x /nix/store/fb980g5ddz16k0bfc8qd0jcf2x7bsw2a-hpx-1.7.1/bin/hello_world_1
hpx.out                                         243,904 x /nix/store/fb980g5ddz16k0bfc8qd0jcf2x7bsw2a-hpx-1.7.1/bin/hello_world_2
hpx.out                                         270,464 x /nix/store/fb980g5ddz16k0bfc8qd0jcf2x7bsw2a-hpx-1.7.1/bin/hello_world_distributed
hello.out                                        55,656 x /nix/store/9ywyxky6cv809jh143f8yxg5kc4bk2yq-hello-2.12/bin/hello
hello-wayland.out                                84,280 x /nix/store/djp0pk61bx3ynxh9w65pnv1vq3z2ja07-hello-wayland-unstable-2020-07-27/bin/hello-wayland
fltk14.bin                                      877,328 x /nix/store/nwkr6p4pmrmx7cnkhya823mhv7x8fski-fltk-1.4.x-2021-12-21-bin/bin/hello
fltk14.bin                                       21,000 x /nix/store/nwkr6p4pmrmx7cnkhya823mhv7x8fski-fltk-1.4.x-2021-12-21-bin/bin/hello-shared
fltk.bin                                        604,656 x /nix/store/v3ijc814y1bmhfr2ca7da95m58jk2a37-fltk-1.3.8-bin/bin/hello

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .