Skip to content

Commit 327cb59

Browse files
Mic92mergify[bot]
authored andcommitted
docs: add documentation on nix-channel
1 parent bea2862 commit 327cb59

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

docs/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ Refer to the following documentation for more information.
2020
- [Secrets and full disk encryption](./howtos/secrets.md)
2121
- [Use without flakes](./howtos/use-without-flakes.md)
2222
- [Terraform](./howtos/terraform.md)
23+
- [Nix-channels / `NIX_PATH`](./howtos/nix-path.md)
2324

2425
[Reference](./reference.md): Reference Guide

docs/howtos/INDEX.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@
1717
[Use without flakes](./use-without-flakes.md)
1818

1919
[Terraform](./terraform.md)
20+
21+
[Nix-channels / `NIX_PATH`](./nix-path.md)

docs/howtos/nix-path.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Nix-channels / `NIX_PATH`
2+
3+
nixos-anywhere does not install channels onto the new system by default to save
4+
time and disk space. This for example results in errors like:
5+
6+
```
7+
(stack trace truncated; use '--show-trace' to show the full trace)
8+
9+
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)
10+
11+
at «none»:0: (source not available)
12+
```
13+
14+
when using tools like nix-shell/nix-env that rely on `NIX_PATH` beeing set.
15+
16+
# Solution 1: Set the `NIX_PATH` via nixos configuration (recommended)
17+
18+
Instead of stateful channels, one can also populate the `NIX_PATH` using nixos
19+
configuration instead:
20+
21+
```nix
22+
{
23+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
24+
# ... other inputs
25+
26+
outputs = { nixpkgs, ... }:
27+
{
28+
nixosConfigurations.yoursystem = nixpkgs.lib.nixosSystem {
29+
system = "x86_64-linux"; # adapt to your actual system
30+
modules = [
31+
# This line will populate NIX_PATH
32+
{ nix.nixPath = [ "nixpkgs=${inputs.nixpkgs}" ]; }
33+
# ... other modules and your configuration.nix
34+
];
35+
};
36+
};
37+
}
38+
```
39+
40+
Advantage: This solution will be automatically kept up-to-date everytime the
41+
flake is updated.
42+
43+
In your shell you will see something in your `$NIX_PATH`:
44+
45+
```shellSession
46+
$ echo $NIX_PATH
47+
/root/.nix-defexpr/channels:nixpkgs=/nix/store/8b61j28rpy11dg8hanbs2x710d8w3v0d-source
48+
```
49+
50+
# Solution 2: Manually add the channel
51+
52+
On the installed machine, run:
53+
54+
```shellSession
55+
$ nix-channel --add https://nixos.org/channels/nixos-unstable nixos
56+
$ nix-channel --update
57+
```

0 commit comments

Comments
 (0)