Difference between revisions of "FAQ/nixpkgs"
m (rollback unauthorized mass edits) Tag: Rollback |
(Formatting fixes + Hint on setting <nixpkgs> version to that of system flake) |
||
| Line 3: | Line 3: | ||
Answer: | Answer: | ||
| − | Use <code>nix repl '<nixpkgs>' </code> on shell and then enter <code>path</code> in the repl to know what nixpkgs is currently being used. | + | Use <code>nix repl '<nixpkgs>'</code> on shell and then enter <code>path</code> in the repl to know what nixpkgs is currently being used. |
| − | Nix tools use <code>$NIX_PATH </code> to decide which path to use in the <code> import </code> call. The first entry in that variable is typically <code> <userhome>/.nix-defexpr/channels </code>. If a user has explicitly added a channel named <code>nixpkgs</code>, then that channel is used in the <code>import <nixpkgs></code> call. Otherwise, the <code>nixpkgs=</code> named entry is used for the <code>import <nixpkgs> </code> call. | + | Nix tools use <code>$NIX_PATH</code> to decide which path to use in the <code> import</code> call. The first entry in that variable is typically <code><userhome>/.nix-defexpr/channels</code>. If a user has explicitly added a channel named <code>nixpkgs</code>, then that channel is used in the <code>import <nixpkgs></code> call. Otherwise, the <code>nixpkgs=</code> named entry is used for the <code>import <nixpkgs></code> call. To have <code><nixpkgs></code> represent the same version of nixpkgs as your system flake, you can set <code>nix.nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];</code> in your system flake. |
| − | Some tools don't fully respect <code>$NIX_PATH </code> and instead search <code>~/.nix-defexpr</code> so there might be some unexpected behavior. | + | Some tools don't fully respect <code>$NIX_PATH</code> and instead search <code>~/.nix-defexpr</code> so there might be some unexpected behavior. |
Latest revision as of 12:12, 5 January 2026
Question: When I do an import <nixpkgs> {}, which channel or path gets imported.
Answer:
Use nix repl '<nixpkgs>' on shell and then enter path in the repl to know what nixpkgs is currently being used.
Nix tools use $NIX_PATH to decide which path to use in the import call. The first entry in that variable is typically <userhome>/.nix-defexpr/channels. If a user has explicitly added a channel named nixpkgs, then that channel is used in the import <nixpkgs> call. Otherwise, the nixpkgs= named entry is used for the import <nixpkgs> call. To have <nixpkgs> represent the same version of nixpkgs as your system flake, you can set nix.nixPath = [ "nixpkgs=${inputs.nixpkgs}" ]; in your system flake.
Some tools don't fully respect $NIX_PATH and instead search ~/.nix-defexpr so there might be some unexpected behavior.