Nix (language): Difference between revisions
imported>Profpatsch Add Update Scripts section to Tips & Tricks |
imported>Profpatsch finding definitions |
||
Line 380: | Line 380: | ||
== Tips & Tricks == | == Tips & Tricks == | ||
=== Finding a (function/package/…) definition === | |||
Nix is often criticized that it has no working “jump to definition”. The good news is that you can something very similar by using a regular expression: | |||
If your package is named <code>hello</code>, searching for the regular expression <code>hello\ =</code> lists all nix symbol definitions that are named this way. In many cases there’s only two or three results. You should find what you are searching for easily. | |||
This trick even works for functions, because their arguments come *after* the equals sign. If you search for <code>mkDerivation\ =</code> for example, you will see that there is more than one definition of that symbol in <code>nixpkgs</code>, but at least all definitions are shown. | |||
You will also notice that searching with <code>grep</code> takes quite a while on a large repository like <code>nixpkgs</code>. Tools like <code>ag</code> (The Silver Searcher) and <code>rg</code> (ripgrep) are orders of magnitudes faster (especially on modern SSDs). | |||
=== Convert a string to an (<code>import</code>-able) path === | === Convert a string to an (<code>import</code>-able) path === |