2 .Dt nixos-generate-config 8
5 .Nm nixos-generate-config
6 .Nd generate NixOS configuration modules
11 .Nm nixos-generate-config
19 This command writes two NixOS configuration modules:
20 .Bl -tag -width indent
21 .It Pa /etc/nixos/hardware-configuration.nix
22 This module sets NixOS configuration options based on your current hardware
23 configuration. In particular, it sets the
25 option to reflect all currently mounted file systems, the
27 option to reflect active swap devices, and the
29 options to ensure that the initial ramdisk contains any kernel modules necessary
30 for mounting the root file system.
32 If this file already exists, it is overwritten. Thus, you should not modify it
33 manually. Rather, you should include it from your
34 .Pa /etc/nixos/configuration.nix Ns
37 to update it whenever your hardware configuration changes.
39 .It Pa /etc/nixos/configuration.nix
40 This is the main NixOS system configuration module. If it already exists, it’s
41 left unchanged. Otherwise,
43 will write a template for you to customise.
49 .Bl -tag -width indent
51 If this option is given, treat the directory
53 as the root of the file system. This means that configuration files will be written to
54 .Ql Ar root Ns /etc/nixos Ns
55 , and that any file systems outside of
57 are ignored for the purpose of generating the
62 If this option is given, write the configuration files to the directory
70 .Pa /etc/nixos/configuration.nix
73 .It Fl -no-filesystems
74 Omit everything concerning file systems and swap devices from the hardware configuration.
76 .It Fl -show-hardware-config
80 .Pa hardware-configuration.nix
81 and print the hardware configuration to stdout only.
87 This command is typically used during NixOS installation to write initial
88 configuration modules. For example, if you created and mounted the target file
94 .Bd -literal -offset indent
95 $ nixos-generate-config --root /mnt
100 .Pa /mnt/etc/nixos/hardware-configuration.nix
101 might look like this:
102 .Bd -literal -offset indent
103 # Do not modify this file! It was generated by 'nixos-generate-config'
104 # and may be overwritten by future invocations. Please make changes
105 # to /etc/nixos/configuration.nix instead.
106 { config, pkgs, ... }:
110 [ <nixos/modules/installer/scan/not-detected.nix>
113 boot.initrd.availableKernelModules = [ "ehci_hcd" "ahci" ];
114 boot.kernelModules = [ "kvm-intel" ];
115 boot.extraModulePackages = [ ];
118 { device = "/dev/disk/by-label/nixos";
120 options = [ "rw" "data=ordered" "relatime" ];
123 fileSystems."/boot" =
124 { device = "/dev/sda1";
126 options = [ "rw" "errors=continue" "user_xattr" "acl" "barrier=1" "data=writeback" "relatime" ];
130 [ { device = "/dev/sda2"; }
138 It will also create a basic
139 .Pa /mnt/etc/nixos/configuration.nix Ns
140 , which you should edit to customise the logical configuration of your system. \
141 This file includes the result of the hardware scan as follows:
142 .Bd -literal -offset indent
143 imports = [ ./hardware-configuration.nix ];
147 After installation, if your hardware configuration changes, you can run:
148 .Bd -literal -offset indent
149 $ nixos-generate-config
154 .Pa /etc/nixos/hardware-configuration.nix Ns
156 .Pa /etc/nixos/configuration.nix
165 .An the Nixpkgs/NixOS contributors