Skip to content

Commit 553320c

Browse files
Mic92mergify[bot]
authored andcommitted
docs: document hardware generation flags
1 parent a2adda7 commit 553320c

File tree

1 file changed

+89
-24
lines changed

1 file changed

+89
-24
lines changed

docs/quickstart.md

Lines changed: 89 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,33 +47,10 @@ 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-
5450
If you already have a flake, you can use it by adding
5551
[disko configuration](https://github.com/nix-community/disko?tab=readme-ov-file#how-to-use-disko)
5652
to it.
5753

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.
76-
7754
### 3. Configure your SSH key
7855

7956
If you cloned
@@ -128,6 +105,11 @@ and add `--env-password` to the `nixos-anywhere` command.
128105

129106
### 7. (Optional) Test your NixOS and Disko configuration
130107

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

@@ -142,7 +124,74 @@ disko inside a virtual machine, where
142124
nix run github:nix-community/nixos-anywhere -- --flake <path to configuration>#<configuration name> --vm-test
143125
```
144126

145-
### 8. Run it
127+
### 8. Prepare Hardware Configuration
128+
129+
If you're not using a virtual machine, it's recommended to allow
130+
`nixos-anywhere` to generate a hardware configuration during installation. This
131+
ensures that essential drivers, such as those required for disk detection, are
132+
properly configured.
133+
134+
To enable `nixos-anywhere` to integrate its generated configuration into your
135+
NixOS setup, you need to include an import for the hardware configuration
136+
beforehand.
137+
138+
Here’s an example:
139+
140+
```diff
141+
nixosConfigurations.generic = nixpkgs.lib.nixosSystem {
142+
system = "x86_64-linux";
143+
modules = [
144+
disko.nixosModules.disko
145+
./configuration.nix
146+
+ ./hardware-configuration.nix
147+
];
148+
};
149+
```
150+
151+
When running `nixos-anywhere`, this file is automatically generated by including
152+
the following flags in your command:
153+
`--generate-hardware-config nixos-generate-config ./hardware-configuration.nix`.
154+
The second flag, `./hardware-configuration.nix`, specifies where
155+
`nixos-generate-config` will store the configuration. Adjust this path to
156+
reflect the location where you want the `hardware-configuration.nix` for this
157+
machine to be saved.
158+
159+
#### 8.1 nixos-facter
160+
161+
As an alternative to `nixos-generate-config`, you can use the experimental
162+
[nixos-facter](https://github.com/numtide/nixos-facter) command, which offers
163+
more comprehensive hardware reports and advanced configuration options.
164+
165+
To use `nixos-facter`, add the following to your flake inputs:
166+
167+
```diff
168+
{
169+
+ inputs.nixos-facter-modules.url = "github:numtide/nixos-facter-modules";
170+
}
171+
```
172+
173+
Next, import the module into your configuration and specify `facter.json` as the
174+
path where the hardware report will be saved:
175+
176+
```diff
177+
nixosConfigurations.generic-nixos-facter = nixpkgs.lib.nixosSystem {
178+
system = "x86_64-linux";
179+
modules = [
180+
disko.nixosModules.disko
181+
./configuration.nix
182+
+ nixos-facter-modules.nixosModules.facter
183+
+ { config.facter.reportPath = ./facter.json }
184+
];
185+
};
186+
```
187+
188+
To generate the configuration for `nixos-facter` with `nixos-anywhere`, use the
189+
following flags: `--generate-hardware-config nixos-facter ./facter.json`. The
190+
second flag, `./facter.json`, specifies where `nixos-generate-config` will store
191+
the hardware report. Adjust this path to suit the location where you want the
192+
`facter.json` to be saved.
193+
194+
### 9. Run it
146195

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

@@ -167,6 +216,22 @@ named `/home/mydir/test` and the IP address of your target machine is
167216
nix run github:nix-community/nixos-anywhere -- --flake /home/mydir/test#hetzner-cloud [email protected]
168217
```
169218

219+
If you also need to generate hardware configuration amend flags for
220+
nixos-generate-config:
221+
222+
```
223+
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>
224+
```
225+
226+
Or these flags if you are using nixos-facter instead:
227+
228+
```
229+
nix run --generate-hardware-config nixos-facter ./facter.json github:nix-community/nixos-anywhere -- --flake <path to configuration>#<configuration name> root@<ip address>
230+
```
231+
232+
Adjust the location of `./hardware-configuration.nix` and `./facter.json`
233+
accordingly.
234+
170235
**nixos-anywhere** will then run, showing various output messages at each stage.
171236
It may take some time to complete, depending on Internet speeds. It should
172237
finish by showing the messages below before returning to the command prompt.

0 commit comments

Comments
 (0)