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