Skip to content

Commit 9ae674f

Browse files
committed
docs: document hardware generation flags
1 parent fcd846d commit 9ae674f

File tree

1 file changed

+77
-27
lines changed

1 file changed

+77
-27
lines changed

docs/quickstart.md

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,7 @@ into a new directory. This example is tailored for a virtual machine setup
4747
similar to one on [Hetzner Cloud](https://www.hetzner.com/cloud), so you might
4848
need to adapt it for your setup.
4949

50-
**Hardware-Specific Configuration**: If you're not using a virtual machine,
51-
you'll need to generate a custom hardware configuration with
52-
`nixos-generate-config`.
53-
54-
If you already have a flake, you can use it by adding
55-
[disko configuration](https://github.com/nix-community/disko?tab=readme-ov-file#how-to-use-disko)
56-
to it.
57-
58-
#### Get `nixos-generate-config` onto the Target Machine
59-
60-
1. **Option 1**: If NixOS is not installed, boot into an installer without first
61-
installing NixOS.
62-
2. **Option 2**: Use the kexec tarball method, as described
63-
[here](https://github.com/nix-community/nixos-images#kexec-tarballs).
64-
65-
#### Generate Configuration
66-
67-
Run the following command on the target machine:
68-
69-
```bash
70-
nixos-generate-config --no-filesystems --dir /mnt/etc/nixos
71-
```
72-
73-
This creates the necessary configuration files under `/mnt/etc/nixos/`, which
74-
you can then customize as needed and copy them to your local machine in order to
75-
include them in your flake.
50+
If you already have a flake, you can use it by adding [disko configuration](https://github.com/nix-community/disko?tab=readme-ov-file#how-to-use-disko) to it.
7651

7752
### 3. Configure your SSH key
7853

@@ -128,6 +103,10 @@ and add `--env-password` to the `nixos-anywhere` command.
128103

129104
### 7. (Optional) Test your NixOS and Disko configuration
130105

106+
Skip this step and continue with Step 8, if you don't have a hardware configuration
107+
(hardware-configuration.nix or facter.json) generated yet or make sure you don't
108+
import non-existing hardware-configuration.nix or facter.json during running the vm test.
109+
131110
The following command will automatically test your nixos configuration and run
132111
disko inside a virtual machine, where
133112

@@ -142,7 +121,64 @@ disko inside a virtual machine, where
142121
nix run github:nix-community/nixos-anywhere -- --flake <path to configuration>#<configuration name> --vm-test
143122
```
144123

145-
### 8. Run it
124+
### 8. Prepare hardware configuration
125+
126+
If you are not using a virtual machine, it is recommended to let `nixos-anywhere` generate a hardware configuration during installation.
127+
This ensures that, for example, drivers needed to detect disks are set up correctly.
128+
129+
To allow `nixos-anywhere` to import its generated configuration into your NixOS configuration, you need to add an import for the hardware configuration upfront.
130+
131+
Here is an example:
132+
133+
```diff
134+
nixosConfigurations.generic = nixpkgs.lib.nixosSystem {
135+
system = "x86_64-linux";
136+
modules = [
137+
disko.nixosModules.disko
138+
./configuration.nix
139+
+ ./hardware-configuration.nix
140+
];
141+
};
142+
```
143+
144+
When running `nixos-anywhere`, this file is then generated by adding the following flags:
145+
`--generate-hardware-config nixos-generate-config ./hardware-configuration.nix`
146+
to your `nixos-anywhere` command. The second flag, `./hardware-configuration.nix`, is the path where `nixos-generate-config` will write the configuration.
147+
Adjust it to the path where the `hardware-configuration.nix` for this machine should be stored.
148+
149+
#### 8.1 nixos-facter
150+
151+
Instead of `nixos-generate-config`, you can also use the new [nixos-facter](https://github.com/numtide/nixos-facter) command.
152+
`nixos-facter` is currently experimental but provides more comprehensive hardware reports and more advanced hardware configuration modules.
153+
154+
In your flake inputs, add `nixos-facter-modules`:
155+
156+
```diff
157+
{
158+
+ inputs.nixos-facter-modules.url = "github:numtide/nixos-facter-modules";
159+
}
160+
```
161+
162+
Then, import the module into your configuration and set `facter.json` to the path where you will later import it:
163+
164+
```diff
165+
nixosConfigurations.generic-nixos-facter = nixpkgs.lib.nixosSystem {
166+
system = "x86_64-linux";
167+
modules = [
168+
disko.nixosModules.disko
169+
./configuration.nix
170+
+ nixos-facter-modules.nixosModules.facter
171+
+ { config.facter.reportPath = ./facter.json }
172+
];
173+
};
174+
```
175+
176+
To let `nixos-anywhere` generate a configuration for `nixos-facter`, add the following flags:
177+
`--generate-hardware-config nixos-facter ./facter.json`.
178+
The second flag, `./facter.json`, is the path where the `nixos-generate-config` will write the configuration.
179+
Adjust it to the path where the `facter.json` for this machine should be stored.
180+
181+
### 9. Run it
146182

147183
You can now run **nixos-anywhere** from the command line as shown below, where:
148184

@@ -167,6 +203,20 @@ named `/home/mydir/test` and the IP address of your target machine is
167203
nix run github:nix-community/nixos-anywhere -- --flake /home/mydir/test#hetzner-cloud root@37.27.18.135
168204
```
169205

206+
If you also need to generate hardware configuration amend flags for nixos-generate-config:
207+
208+
```
209+
nix run --generate-hardware-config nixos-generate-config ./hardware-configuration.nix github:nix-community/nixos-anywhere -- --flake <path to configuration>#<configuration name> root@<ip address>
210+
```
211+
212+
Or these flags if you are using nixos-facter instead:
213+
214+
```
215+
nix run --generate-hardware-config nixos-facter ./facter.json github:nix-community/nixos-anywhere -- --flake <path to configuration>#<configuration name> root@<ip address>
216+
```
217+
218+
Adjust the location of `./hardware-configuration.nix` and `./facter.json` accordingly.
219+
170220
**nixos-anywhere** will then run, showing various output messages at each stage.
171221
It may take some time to complete, depending on Internet speeds. It should
172222
finish by showing the messages below before returning to the command prompt.

0 commit comments

Comments
 (0)