at master 4.2 kB view raw
1.Dd January 1, 1980 2.Dt nixos-generate-config 8 3.Os 4.Sh NAME 5.Nm nixos-generate-config 6.Nd generate NixOS configuration modules 7. 8. 9. 10.Sh SYNOPSIS 11.Nm nixos-generate-config 12.Op Fl -force 13.Op Fl -root Ar root 14.Op Fl -dir Ar dir 15.Op Fl -flake 16.Op Fl -kernel Ar <lts|latest> 17. 18. 19. 20.Sh DESCRIPTION 21This command writes two NixOS configuration modules: 22.Bl -tag -width indent 23.It Pa /etc/nixos/hardware-configuration.nix 24This module sets NixOS configuration options based on your current hardware 25configuration. In particular, it sets the 26.Va fileSystem 27option to reflect all currently mounted file systems, the 28.Va swapDevices 29option to reflect active swap devices, and the 30.Va boot.initrd.* 31options to ensure that the initial ramdisk contains any kernel modules necessary 32for mounting the root file system. 33.Pp 34If this file already exists, it is overwritten. Thus, you should not modify it 35manually. Rather, you should include it from your 36.Pa /etc/nixos/configuration.nix Ns 37, and re-run 38.Nm 39to update it whenever your hardware configuration changes. 40. 41.It Pa /etc/nixos/configuration.nix 42This is the main NixOS system configuration module. If it already exists, it’s 43left unchanged. Otherwise, 44.Nm 45will write a template for you to customise. 46.El 47. 48. 49. 50.Sh OPTIONS 51.Bl -tag -width indent 52.It Fl -root Ar root 53If this option is given, treat the directory 54.Ar root 55as the root of the file system. This means that configuration files will be written to 56.Ql Ar root Ns /etc/nixos Ns 57, and that any file systems outside of 58.Ar root 59are ignored for the purpose of generating the 60.Va fileSystems 61option. 62. 63.It Fl -dir Ar dir 64If this option is given, write the configuration files to the directory 65.Ar dir 66instead of 67.Pa /etc/nixos Ns 68\&. 69. 70.It Fl -kernel Ar <lts|latest> 71Set the kernel in the generated configuration file. 72. 73.It Fl -force 74Overwrite 75.Pa /etc/nixos/configuration.nix 76(and 77.Pa /etc/nixos/flake.nix 78if --flake is passed) if already present. 79. 80.It Fl -flake 81Also generate 82.Pa /etc/nixos/flake.nix Ns 83\&. 84. 85.It Fl -no-filesystems 86Omit everything concerning file systems and swap devices from the hardware configuration. 87. 88.It Fl -show-hardware-config 89Don't generate 90.Pa configuration.nix 91or 92.Pa hardware-configuration.nix 93and print the hardware configuration to stdout only. 94.El 95. 96. 97. 98.Sh EXAMPLES 99This command is typically used during NixOS installation to write initial 100configuration modules. For example, if you created and mounted the target file 101systems on 102.Pa /mnt 103and 104.Pa /mnt/boot Ns 105, you would run: 106.Bd -literal -offset indent 107$ nixos-generate-config --root /mnt 108.Ed 109. 110.Pp 111The resulting file 112.Pa /mnt/etc/nixos/hardware-configuration.nix 113might look like this: 114.Bd -literal -offset indent 115# Do not modify this file! It was generated by 'nixos-generate-config' 116# and may be overwritten by future invocations. Please make changes 117# to /etc/nixos/configuration.nix instead. 118{ config, pkgs, ... }: 119 120{ 121 imports = 122 [ <nixos/modules/installer/scan/not-detected.nix> 123 ]; 124 125 boot.initrd.availableKernelModules = [ "ehci_hcd" "ahci" ]; 126 boot.kernelModules = [ "kvm-intel" ]; 127 boot.extraModulePackages = [ ]; 128 129 fileSystems."/" = 130 { device = "/dev/disk/by-label/nixos"; 131 fsType = "ext3"; 132 options = [ "rw" "data=ordered" "relatime" ]; 133 }; 134 135 fileSystems."/boot" = 136 { device = "/dev/sda1"; 137 fsType = "ext3"; 138 options = [ "rw" "errors=continue" "user_xattr" "acl" "barrier=1" "data=writeback" "relatime" ]; 139 }; 140 141 swapDevices = 142 [ { device = "/dev/sda2"; } 143 ]; 144 145 nix.maxJobs = 8; 146} 147.Ed 148. 149.Pp 150It will also create a basic 151.Pa /mnt/etc/nixos/configuration.nix Ns 152, which you should edit to customise the logical configuration of your system. \ 153This file includes the result of the hardware scan as follows: 154.Bd -literal -offset indent 155imports = [ ./hardware-configuration.nix ]; 156.Ed 157. 158.Pp 159After installation, if your hardware configuration changes, you can run: 160.Bd -literal -offset indent 161$ nixos-generate-config 162.Ed 163. 164.Pp 165to update 166.Pa /etc/nixos/hardware-configuration.nix Ns 167\&. Your 168.Pa /etc/nixos/configuration.nix 169will 170.Em not 171be overwritten. 172. 173.Sh AUTHORS 174.An -nosplit 175.An Eelco Dolstra 176and 177.An the Nixpkgs/NixOS contributors