Adding programs to PATH: Difference between revisions

Axka (talk | contribs)
m Clarify flake devshell section
Tags: Mobile edit Mobile web edit Visual edit
Axka (talk | contribs)
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</code>
[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!


You can also use packages from a local flake with the following command:
[username@hostname:~]$
 
</syntaxhighlight>
<code>nix shell .\#my-package</code>
 
You may also consider the <code>nix run</code> command useful. It reads the package's <code>meta.mainProgram</code> attribute and runs it.
 
<code>nix run nixpkgs\#hello</code>


=== Declarative shell using <code>shell.nix</code> and <code>nix-shell</code> ===
=== Declarative shell using <code>shell.nix</code> and <code>nix-shell</code> ===