@@ -264,26 +264,9 @@ <h3 id="2-initialize-a-flake"><a class="header" href="#2-initialize-a-flake">2.
264
264
into a new directory. This example is tailored for a virtual machine setup
265
265
similar to one on < a href ="https://www.hetzner.com/cloud "> Hetzner Cloud</ a > , so you might
266
266
need to adapt it for your setup.</ p >
267
- < p > < strong > Hardware-Specific Configuration</ strong > : If you're not using a virtual machine,
268
- you'll need to generate a custom hardware configuration with
269
- < code > nixos-generate-config</ code > .</ p >
270
267
< p > If you already have a flake, you can use it by adding
271
268
< a href ="https://github.com/nix-community/disko?tab=readme-ov-file#how-to-use-disko "> disko configuration</ a >
272
269
to it.</ p >
273
- < h4 id ="get-nixos-generate-config-onto-the-target-machine "> < a class ="header " href ="#get-nixos-generate-config-onto-the-target-machine "> Get < code > nixos-generate-config</ code > onto the Target Machine</ a > </ h4 >
274
- < ol >
275
- < li > < strong > Option 1</ strong > : If NixOS is not installed, boot into an installer without first
276
- installing NixOS.</ li >
277
- < li > < strong > Option 2</ strong > : Use the kexec tarball method, as described
278
- < a href ="https://github.com/nix-community/nixos-images#kexec-tarballs "> here</ a > .</ li >
279
- </ ol >
280
- < h4 id ="generate-configuration "> < a class ="header " href ="#generate-configuration "> Generate Configuration</ a > </ h4 >
281
- < p > Run the following command on the target machine:</ p >
282
- < pre > < code class ="language-bash "> nixos-generate-config --no-filesystems --dir /mnt/etc/nixos
283
- </ code > </ pre >
284
- < p > This creates the necessary configuration files under < code > /mnt/etc/nixos/</ code > , which
285
- you can then customize as needed and copy them to your local machine in order to
286
- include them in your flake.</ p >
287
270
< h3 id ="3-configure-your-ssh-key "> < a class ="header " href ="#3-configure-your-ssh-key "> 3. Configure your SSH key</ a > </ h3 >
288
271
< p > If you cloned
289
272
< a href ="https://github.com/nix-community/nixos-anywhere-examples/blob/main/configuration.nix "> our nixos-anywhere-example</ a >
@@ -322,6 +305,10 @@ <h3 id="6-connectivity-to-the-target-machine"><a class="header" href="#6-connect
322
305
SSH password prompts, set the < code > SSHPASS</ code > environment variable to your password
323
306
and add < code > --env-password</ code > to the < code > nixos-anywhere</ code > command.</ p >
324
307
< h3 id ="7-optional-test-your-nixos-and-disko-configuration "> < a class ="header " href ="#7-optional-test-your-nixos-and-disko-configuration "> 7. (Optional) Test your NixOS and Disko configuration</ a > </ h3 >
308
+ < p > Skip this step and continue with Step 8, if you don't have a hardware
309
+ configuration (hardware-configuration.nix or facter.json) generated yet or make
310
+ sure you don't import non-existing hardware-configuration.nix or facter.json
311
+ during running the vm test.</ p >
325
312
< p > The following command will automatically test your nixos configuration and run
326
313
disko inside a virtual machine, where</ p >
327
314
< ul >
@@ -337,7 +324,58 @@ <h3 id="7-optional-test-your-nixos-and-disko-configuration"><a class="header" hr
337
324
</ ul >
338
325
< pre > < code > nix run github:nix-community/nixos-anywhere -- --flake <path to configuration>#<configuration name> --vm-test
339
326
</ code > </ pre >
340
- < h3 id ="8-run-it "> < a class ="header " href ="#8-run-it "> 8. Run it</ a > </ h3 >
327
+ < h3 id ="8-prepare-hardware-configuration "> < a class ="header " href ="#8-prepare-hardware-configuration "> 8. Prepare Hardware Configuration</ a > </ h3 >
328
+ < p > If you're not using a virtual machine, it's recommended to allow
329
+ < code > nixos-anywhere</ code > to generate a hardware configuration during installation. This
330
+ ensures that essential drivers, such as those required for disk detection, are
331
+ properly configured.</ p >
332
+ < p > To enable < code > nixos-anywhere</ code > to integrate its generated configuration into your
333
+ NixOS setup, you need to include an import for the hardware configuration
334
+ beforehand.</ p >
335
+ < p > Here’s an example:</ p >
336
+ < pre > < code class ="language-diff "> nixosConfigurations.generic = nixpkgs.lib.nixosSystem {
337
+ system = "x86_64-linux";
338
+ modules = [
339
+ disko.nixosModules.disko
340
+ ./configuration.nix
341
+ + ./hardware-configuration.nix
342
+ ];
343
+ };
344
+ </ code > </ pre >
345
+ < p > When running < code > nixos-anywhere</ code > , this file is automatically generated by including
346
+ the following flags in your command:
347
+ < code > --generate-hardware-config nixos-generate-config ./hardware-configuration.nix</ code > .
348
+ The second flag, < code > ./hardware-configuration.nix</ code > , specifies where
349
+ < code > nixos-generate-config</ code > will store the configuration. Adjust this path to
350
+ reflect the location where you want the < code > hardware-configuration.nix</ code > for this
351
+ machine to be saved.</ p >
352
+ < h4 id ="81-nixos-facter "> < a class ="header " href ="#81-nixos-facter "> 8.1 nixos-facter</ a > </ h4 >
353
+ < p > As an alternative to < code > nixos-generate-config</ code > , you can use the experimental
354
+ < a href ="https://github.com/numtide/nixos-facter "> nixos-facter</ a > command, which offers
355
+ more comprehensive hardware reports and advanced configuration options.</ p >
356
+ < p > To use < code > nixos-facter</ code > , add the following to your flake inputs:</ p >
357
+ < pre > < code class ="language-diff "> {
358
+ + inputs.nixos-facter-modules.url = "github:numtide/nixos-facter-modules";
359
+ }
360
+ </ code > </ pre >
361
+ < p > Next, import the module into your configuration and specify < code > facter.json</ code > as the
362
+ path where the hardware report will be saved:</ p >
363
+ < pre > < code class ="language-diff "> nixosConfigurations.generic-nixos-facter = nixpkgs.lib.nixosSystem {
364
+ system = "x86_64-linux";
365
+ modules = [
366
+ disko.nixosModules.disko
367
+ ./configuration.nix
368
+ + nixos-facter-modules.nixosModules.facter
369
+ + { config.facter.reportPath = ./facter.json }
370
+ ];
371
+ };
372
+ </ code > </ pre >
373
+ < p > To generate the configuration for < code > nixos-facter</ code > with < code > nixos-anywhere</ code > , use the
374
+ following flags: < code > --generate-hardware-config nixos-facter ./facter.json</ code > . The
375
+ second flag, < code > ./facter.json</ code > , specifies where < code > nixos-generate-config</ code > will store
376
+ the hardware report. Adjust this path to suit the location where you want the
377
+ < code > facter.json</ code > to be saved.</ p >
378
+ < h3 id ="9-run-it "> < a class ="header " href ="#9-run-it "> 9. Run it</ a > </ h3 >
341
379
< p > You can now run < strong > nixos-anywhere</ strong > from the command line as shown below, where:</ p >
342
380
< ul >
343
381
< li >
@@ -360,6 +398,15 @@ <h3 id="8-run-it"><a class="header" href="#8-run-it">8. Run it</a></h3>
360
398
< code > 37.27.18.135</ code > :</ p >
361
399
< pre > < code > nix run github:nix-community/nixos-anywhere -- --flake /home/mydir/test#hetzner-cloud root@37.27.18.135
362
400
</ code > </ pre >
401
+ < p > If you also need to generate hardware configuration amend flags for
402
+ nixos-generate-config:</ p >
403
+ < pre > < code > 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>
404
+ </ code > </ pre >
405
+ < p > Or these flags if you are using nixos-facter instead:</ p >
406
+ < pre > < code > nix run --generate-hardware-config nixos-facter ./facter.json github:nix-community/nixos-anywhere -- --flake <path to configuration>#<configuration name> root@<ip address>
407
+ </ code > </ pre >
408
+ < p > Adjust the location of < code > ./hardware-configuration.nix</ code > and < code > ./facter.json</ code >
409
+ accordingly.</ p >
363
410
< p > < strong > nixos-anywhere</ strong > will then run, showing various output messages at each stage.
364
411
It may take some time to complete, depending on Internet speeds. It should
365
412
finish by showing the messages below before returning to the command prompt.</ p >
@@ -775,12 +822,20 @@ <h2 id="command-line-usage"><a class="header" href="#command-line-usage">Command
775
822
build the closure on the remote machine instead of locally and copy-closuring it
776
823
* --vm-test
777
824
build the system and test the disk configuration inside a VM without installing it to the target.
825
+ * --generate-hardware-config nixos-facter|nixos-generate-config <path>
826
+ generate a hardware-configuration.nix file using the specified backend and write it to the specified path.
827
+ The backend can be either 'nixos-facter' or 'nixos-generate-config'.
778
828
* --phases
779
829
comma separated list of phases to run. Default is: kexec,disko,install,reboot
780
830
kexec: kexec into the nixos installer
781
831
disko: first unmount and destroy all filesystems on the disks we want to format, then run the create and mount mode
782
832
install: install the system
783
833
reboot: reboot the machine
834
+ * --disko-mode create|mount|disko
835
+ set the disko mode to create, mount or destroy. Default is disko.
836
+ format: create partition tables, zpools, lvms, raids and filesystems (Experimental: Can be run increntally, but use with caution and good backups)
837
+ mount: mount the partition at the specified root-mountpoint
838
+ disko: first unmount and destroy all filesystems on the disks we want to format, then run the create and mount mode
784
839
</ code > </ pre >
785
840
< h2 id ="explanation-of-known-error-messages "> < a class ="header " href ="#explanation-of-known-error-messages "> Explanation of known error messages</ a > </ h2 >
786
841
< p > TODO: Add additional error messages and meanings. Fill in missing explanations</ p >
0 commit comments