Adding programs to PATH: Difference between revisions
m Clarify flake devshell section Tags: Mobile edit Mobile web edit Visual edit |
m Put commands into code blocks Tags: Mobile edit Mobile web edit Visual edit |
||
| Line 45: | Line 45: | ||
=== Ad-hoc shell using <code>nix shell</code> (Flakes) === | === Ad-hoc shell using <code>nix shell</code> (Flakes) === | ||
Run the following command to create a new shell with the <code>hello</code> package from the <code>nixpkgs</code> [[Flakes|flake]] added to the <code>PATH</code> environment variable. | Run the following command to create a new shell with the <code>hello</code> package from the <code>nixpkgs</code> [[Flakes|flake]] added to the <code>PATH</code> environment variable.<syntaxhighlight lang="shell-session"> | ||
[username@hostname:~]$ nix shell nixpkgs\#hello | |||
<code>nix shell nixpkgs\#hello | [username@hostname:~]$ | ||
</syntaxhighlight>You may also consider the <code>nix run</code> command useful. It reads the package's <code>meta.mainProgram</code> attribute and runs it.<syntaxhighlight lang="shell-session"> | |||
[username@hostname:~]$ nix run nixpkgs\#hello | |||
Hello, world! | |||
[username@hostname:~]$ | |||
</syntaxhighlight> | |||
=== Declarative shell using <code>shell.nix</code> and <code>nix-shell</code> === | === Declarative shell using <code>shell.nix</code> and <code>nix-shell</code> === | ||