1<refentry xmlns="http://docbook.org/ns/docbook"
2 xmlns:xlink="http://www.w3.org/1999/xlink"
3 xmlns:xi="http://www.w3.org/2001/XInclude">
4 <refmeta>
5 <refentrytitle><command>nixos-generate-config</command>
6 </refentrytitle><manvolnum>8</manvolnum>
7 <refmiscinfo class="source">NixOS</refmiscinfo>
8<!-- <refmiscinfo class="version"><xi:include href="version.txt" parse="text"/></refmiscinfo> -->
9 </refmeta>
10 <refnamediv>
11 <refname><command>nixos-generate-config</command></refname>
12 <refpurpose>generate NixOS configuration modules</refpurpose>
13 </refnamediv>
14 <refsynopsisdiv>
15 <cmdsynopsis>
16 <command>nixos-generate-config</command>
17 <arg>
18 <option>--force</option>
19 </arg>
20
21 <arg>
22 <arg choice='plain'>
23 <option>--root</option>
24 </arg>
25 <replaceable>root</replaceable>
26 </arg>
27
28 <arg>
29 <arg choice='plain'>
30 <option>--dir</option>
31 </arg>
32 <replaceable>dir</replaceable>
33 </arg>
34 </cmdsynopsis>
35 </refsynopsisdiv>
36 <refsection>
37 <title>Description</title>
38 <para>
39 This command writes two NixOS configuration modules:
40 <variablelist>
41 <varlistentry>
42 <term>
43 <option>/etc/nixos/hardware-configuration.nix</option>
44 </term>
45 <listitem>
46 <para>
47 This module sets NixOS configuration options based on your current
48 hardware configuration. In particular, it sets the
49 <option>fileSystem</option> option to reflect all currently mounted file
50 systems, the <option>swapDevices</option> option to reflect active swap
51 devices, and the <option>boot.initrd.*</option> options to ensure that
52 the initial ramdisk contains any kernel modules necessary for mounting
53 the root file system.
54 </para>
55 <para>
56 If this file already exists, it is overwritten. Thus, you should not
57 modify it manually. Rather, you should include it from your
58 <filename>/etc/nixos/configuration.nix</filename>, and re-run
59 <command>nixos-generate-config</command> to update it whenever your
60 hardware configuration changes.
61 </para>
62 </listitem>
63 </varlistentry>
64 <varlistentry>
65 <term>
66 <option>/etc/nixos/configuration.nix</option>
67 </term>
68 <listitem>
69 <para>
70 This is the main NixOS system configuration module. If it already
71 exists, it’s left unchanged. Otherwise,
72 <command>nixos-generate-config</command> will write a template for you
73 to customise.
74 </para>
75 </listitem>
76 </varlistentry>
77 </variablelist>
78 </para>
79 </refsection>
80 <refsection>
81 <title>Options</title>
82 <para>
83 This command accepts the following options:
84 </para>
85 <variablelist>
86 <varlistentry>
87 <term>
88 <option>--root</option>
89 </term>
90 <listitem>
91 <para>
92 If this option is given, treat the directory
93 <replaceable>root</replaceable> as the root of the file system. This
94 means that configuration files will be written to
95 <filename><replaceable>root</replaceable>/etc/nixos</filename>, and that
96 any file systems outside of <replaceable>root</replaceable> are ignored
97 for the purpose of generating the <option>fileSystems</option> option.
98 </para>
99 </listitem>
100 </varlistentry>
101 <varlistentry>
102 <term>
103 <option>--dir</option>
104 </term>
105 <listitem>
106 <para>
107 If this option is given, write the configuration files to the directory
108 <replaceable>dir</replaceable> instead of
109 <filename>/etc/nixos</filename>.
110 </para>
111 </listitem>
112 </varlistentry>
113 <varlistentry>
114 <term>
115 <option>--force</option>
116 </term>
117 <listitem>
118 <para>
119 Overwrite <filename>/etc/nixos/configuration.nix</filename> if it already
120 exists.
121 </para>
122 </listitem>
123 </varlistentry>
124 <varlistentry>
125 <term>
126 <option>--no-filesystems</option>
127 </term>
128 <listitem>
129 <para>
130 Omit everything concerning file systems and swap devices from the
131 hardware configuration.
132 </para>
133 </listitem>
134 </varlistentry>
135 <varlistentry>
136 <term>
137 <option>--show-hardware-config</option>
138 </term>
139 <listitem>
140 <para>
141 Don't generate <filename>configuration.nix</filename> or
142 <filename>hardware-configuration.nix</filename> and print the hardware
143 configuration to stdout only.
144 </para>
145 </listitem>
146 </varlistentry>
147 </variablelist>
148 </refsection>
149 <refsection>
150 <title>Examples</title>
151 <para>
152 This command is typically used during NixOS installation to write initial
153 configuration modules. For example, if you created and mounted the target
154 file systems on <filename>/mnt</filename> and
155 <filename>/mnt/boot</filename>, you would run:
156<screen>
157<prompt>$ </prompt>nixos-generate-config --root /mnt
158</screen>
159 The resulting file
160 <filename>/mnt/etc/nixos/hardware-configuration.nix</filename> might look
161 like this:
162<programlisting>
163# Do not modify this file! It was generated by ‘nixos-generate-config’
164# and may be overwritten by future invocations. Please make changes
165# to /etc/nixos/configuration.nix instead.
166{ config, pkgs, ... }:
167
168{
169 imports =
170 [ <nixos/modules/installer/scan/not-detected.nix>
171 ];
172
173 boot.initrd.availableKernelModules = [ "ehci_hcd" "ahci" ];
174 boot.kernelModules = [ "kvm-intel" ];
175 boot.extraModulePackages = [ ];
176
177 fileSystems."/" =
178 { device = "/dev/disk/by-label/nixos";
179 fsType = "ext3";
180 options = [ "rw" "data=ordered" "relatime" ];
181 };
182
183 fileSystems."/boot" =
184 { device = "/dev/sda1";
185 fsType = "ext3";
186 options = [ "rw" "errors=continue" "user_xattr" "acl" "barrier=1" "data=writeback" "relatime" ];
187 };
188
189 swapDevices =
190 [ { device = "/dev/sda2"; }
191 ];
192
193 nix.maxJobs = 8;
194}
195</programlisting>
196 It will also create a basic
197 <filename>/mnt/etc/nixos/configuration.nix</filename>, which you should edit
198 to customise the logical configuration of your system. This file includes
199 the result of the hardware scan as follows:
200<programlisting>
201 imports = [ ./hardware-configuration.nix ];
202</programlisting>
203 </para>
204 <para>
205 After installation, if your hardware configuration changes, you can run:
206<screen>
207<prompt>$ </prompt>nixos-generate-config
208</screen>
209 to update <filename>/etc/nixos/hardware-configuration.nix</filename>. Your
210 <filename>/etc/nixos/configuration.nix</filename> will
211 <emphasis>not</emphasis> be overwritten.
212 </para>
213 </refsection>
214</refentry>