Nix Language: Tips & Tricks: Difference between revisions
imported>Fricklerhandwerk m Fricklerhandwerk moved page Nix Expression Language: Tips & Tricks to Nix Language: Tips & Tricks: nix expression language -> nix language |
mention using :edit as surrogate jump to definition Tag: 2017 source edit |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 17: | Line 17: | ||
</pre> | </pre> | ||
This doesn't work for non-functions or builtin functions, which show <code>«primop»</code>. It will always find the actual lambda, not an attribute that reexports a partial application, for example. | This doesn't work for non-functions or builtin functions, which show <code>«primop»</code>. It will always find the actual lambda, not an attribute that reexports a partial application, for example. | ||
Also in the REPL, you may use the <code>:edit</code> command (or its abbreviation <code>:e</code>) on an expression to open your editor (detected from the <code>$EDITOR</code> environment variable) at the location where an attribute was defined. | |||
<syntaxhighlight lang="bash"> | |||
$ nix repl --expr '{ pkgs = import <nixpkgs> { }; }' | |||
nix-repl> :e pkgs.lib.strings.makeBinPath | |||
</syntaxhighlight> | |||
The position information is not always perfectly accurate, but the above sequence of commands ''should'' open your editor to somewhere close to https://github.com/NixOS/nixpkgs/blob/b6ed1c5ee1470faf835024587c25fafb03693cbe/lib/strings.nix#L228. | |||
== Convert a string to an (<code>import</code>-able) path == | == Convert a string to an (<code>import</code>-able) path == | ||
Line 133: | Line 142: | ||
in writeScript "update-foo.sh" '' | in writeScript "update-foo.sh" '' | ||
echo "updating foo.txt!" | echo "updating foo.txt!" | ||
echo "additional new data" >> ${lib.escapeShellArg textdata} | |||
'' | '' | ||
</syntaxHighlight> | </syntaxHighlight> | ||
Line 160: | Line 169: | ||
== Relevant pages == | == Relevant pages == | ||
* [[Overview of the Nix | * [[Overview of the Nix Language]] | ||
* [[Editor Modes for Nix Files]] | * [[Editor Modes for Nix Files]] | ||
* [[Nix Expression Language: Learning resources|Learning resources]] | * [[Nix Expression Language: Learning resources|Learning resources]] | ||
[[Category: Nix | [[Category: Nix Language]] | ||
[[Category: Cookbook]] | [[Category: Cookbook]] |