You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

man-nixos-generate-config.xml 6.3KB

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