@@ -47,33 +47,10 @@ into a new directory. This example is tailored for a virtual machine setup
47
47
similar to one on [ Hetzner Cloud] ( https://www.hetzner.com/cloud ) , so you might
48
48
need to adapt it for your setup.
49
49
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
50
If you already have a flake, you can use it by adding
55
51
[ disko configuration] ( https://github.com/nix-community/disko?tab=readme-ov-file#how-to-use-disko )
56
52
to it.
57
53
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
-
77
54
### 3. Configure your SSH key
78
55
79
56
If you cloned
@@ -128,6 +105,11 @@ and add `--env-password` to the `nixos-anywhere` command.
128
105
129
106
### 7. (Optional) Test your NixOS and Disko configuration
130
107
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
+
131
113
The following command will automatically test your nixos configuration and run
132
114
disko inside a virtual machine, where
133
115
@@ -142,7 +124,74 @@ disko inside a virtual machine, where
142
124
nix run github:nix-community/nixos-anywhere -- --flake <path to configuration>#<configuration name> --vm-test
143
125
```
144
126
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
146
195
147
196
You can now run ** nixos-anywhere** from the command line as shown below, where:
148
197
@@ -167,6 +216,22 @@ named `/home/mydir/test` and the IP address of your target machine is
167
216
nix run github:nix-community/nixos-anywhere -- --flake /home/mydir/test#hetzner-cloud root@37.27.18.135
168
217
```
169
218
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
+
170
235
** nixos-anywhere** will then run, showing various output messages at each stage.
171
236
It may take some time to complete, depending on Internet speeds. It should
172
237
finish by showing the messages below before returning to the command prompt.
0 commit comments