Adding programs to PATH: Difference between revisions
m Add example of running hello in an ad-hoc flake-based devshell Tags: Mobile edit Mobile web edit Visual edit |
Explain PATH Tags: Mobile edit Mobile web edit Visual edit |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
[[Category:Tutorial]] | |||
Here is a collection of methods to add a program to the <code>PATH</code> environment variable with [[Nix (package manager)]] with packages from [[Nixpkgs]]. | Here is a collection of methods to add a program to the <code>PATH</code> environment variable with [[Nix (package manager)]] with packages from [[Nixpkgs]]. | ||
The <code>PATH</code> environment variable (often referred to as "the PATH") is an environment variable that tells programs where to find other programs. When you run a command <code>hello</code> in a bash shell, it basically searches for an executable named <code>hello</code> in every directory listed in <code>PATH</code>. | |||
The NixOS method supports installing [[udev]] rules, which may be required for programs interacting with hardware. Services should be enabled and configured with NixOS options rather than by adding them manually to <code>environment.systemPackages</code>. | The NixOS method supports installing [[udev]] rules, which may be required for programs interacting with hardware. Services should be enabled and configured with NixOS options rather than by adding them manually to <code>environment.systemPackages</code>. | ||
| Line 7: | Line 11: | ||
== Persistent == | == Persistent == | ||
These methods install the packages globally (not local to a specific development shell), persist the installation between reboots and | These methods install the packages globally (not local to a specific development shell), persist the installation between reboots and symlink paths together into a specific directory (see the NixOS options {{Nixos:option|environment.systemPackages}} and {{Nixos:option|environment.pathsToLink}} for details). | ||
=== NixOS === | === NixOS === | ||
| Line 85: | Line 89: | ||
devShells.x86_64-linux.default = pkgs.mkShellNoCC { | devShells.x86_64-linux.default = pkgs.mkShellNoCC { | ||
packages = [ pkgs.hello ]; | packages = [ pkgs.hello ]; | ||
} | }; | ||
}; | }; | ||
}|name=flake.nix|lang=nix}} | }|name=flake.nix|lang=nix}}Here is an example of a it working:<syntaxhighlight lang="shell-session"> | ||
[username@hostname:/tmp/example]$ hello | |||
-bash: hello: command not found | |||
[username@hostname:/tmp/example]$ nix develop | |||
warning: creating lock file "/tmp/example/flake.lock": | |||
• Added input 'nixpkgs': | |||
'github:NixOS/nixpkgs/00c21e4c93d963c50d4c0c89bfa84ed6e0694df2?narHash=sha256-AYqlWrX09%2BHvGs8zM6ebZ1pwUqjkfpnv8mewYwAo%2BiM%3D' (2026-02-04) | |||
[username@hostname:/tmp/example]$ hello | |||
Hello, world! | |||
[username@hostname:/tmp/example]$ | |||
</syntaxhighlight> | |||