What's the right way to access NixOS package/namespace/module definitions?

This might be a silly question, but both wiki pages and guides often mention to look at the definitions of some expression. For example, the wiki page for manpages says

See also: the other options in the `documentation` namespace.

How do I do this the best way possible? I have cloned nixpkgs into an arbitrary directory and am browsing it with my editor, but I don’t think I have any (good) way of knowing if the expression I’m looking at corresponds to the same version available on my system (since pkgs are updated).

Is there a canonical way to access the definitions? And as a sidenote, if there is, how do you actually search them? It feels somewhat silly to just open up fzf and vim, but I haven’t seen many other options.

2 Likes

NixOS Search is probably what you’re looking for, you’re able to type in command names, and it will show you the related package it’s present in.

1 Like

other useful commands: nix-env -qa <package/command> to see what is present in your current environment; and nix search <package> is useful to see what’s available through your channels

1 Like

For a long time I wasn’t aware of the nix repl tool. It’s quite useful in browsing around nixpkgs. Just fire it up, enter :l <nixpkgs> and tab-complete away. (This will work for packages. I’m pretty sure there’s a way to get nixos options too) The upcoming Release will also be able to drop you into an editor: nix repl: add :edit command · NixOS/nix@73ff84f · GitHub

2 Likes

second @knedlsepp on nix repl, it’s great. Just wanted to add that you can also just do :l and it will attempt to load a default.nix, so if you do this at the root of nixpkgs, it will load your checked-out version of nixpkgs.

As @knedlsepp said as well, nix repl also has great tab completion, so it’s a great way to poke-around and see what you’re able to reference when creating expressions.

I use man configuration.nix (also mentioned on that wiki page) a lot. It has all the nixos options in it.

1 Like

I use nix-edit -f "<nixpgks>" <expr>.