Jump to content

Nixos-generate-config: Difference between revisions

From NixOS Wiki
Pigs (talk | contribs)
No edit summary
Pigs (talk | contribs)
move ssd trim info to filesystems wiki page, other minor formatting
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
<syntaxHighlight lang=bash>
Generate NixOS configuration modules.
 
This command is part of the {{nixos:package|nixos-install-tools}} package. It analyzes your hardware configuration and generates two files of:
* <code>/etc/nixos/configuration.nix</code> - the main system configuration file.
* <code>/etc/nixos/hardware-configuration.nix</code> - a hardware-specific configuration file, including detected devices and modules.
 
For details on configuring the system configuration file, see [[Overview of the NixOS Linux distribution#Declarative Configuration]].
 
= Usage =
 
<syntaxHighlight lang=console>
# nixos-generate-config
# nixos-generate-config
</syntaxHighlight>
</syntaxHighlight>


This command is part of the <code>nixos-install-tools</code> package. It analyzes your hardware configuration and generates two files of:
This will create configuration files based on the currently mounted system. This is typically used where NixOS is already installed. By default, <code>nixos-generate-config</code> will not overwrite an existing <code>configuration.nix</code>. To force overwrite an existing file, pass the <code>--force</code> option.
* <code>/etc/nixos/configuration.nix</code>
 
* <code>/etc/nixos/hardware-configuration.nix</code>
== Generate configuration for a target root ==
 
To generate configuration files with a specific root directory (commonly used during installation):
 
<syntaxhighlight lang="console">
# nixos-generate-config --root /mnt
</syntaxhighlight>
 
This writes configuration files to <code>/mnt/etc/nixos/</code>.
 
== Show hardware configuration ==
 
To print the detected hardware configuration to standard output without writing to disk:
 
<syntaxhighlight lang="console">
# nixos-generate-config --show-hardware-config
</syntaxhighlight>


== hardware specific notes ==
= Specifying specific hardware =


If you are using an SSD it may be useful to enable TRIM support as well as set filesystem flags to improve the SSD performance:
A collection of hardware specific platforms with their config can be found at [https://github.com/NixOS/nixos-hardware NixOS Hardware repository].  
{{file|/etc/nixos/configuration.nix|nix|
<nowiki>
fileSystems."/".options = [ "noatime" "nodiratime" "discard" ];
</nowiki>
}}


A collection of hardware specific platforms with their config can be found at [https://github.com/NixOS/nixos-hardware NixOS Hardware repository]
[[Category:NixOS]]
[[Category:Configuration]]

Latest revision as of 18:00, 24 May 2025

Generate NixOS configuration modules.

This command is part of the nixos-install-tools package. It analyzes your hardware configuration and generates two files of:

  • /etc/nixos/configuration.nix - the main system configuration file.
  • /etc/nixos/hardware-configuration.nix - a hardware-specific configuration file, including detected devices and modules.

For details on configuring the system configuration file, see Overview of the NixOS Linux distribution#Declarative Configuration.

Usage

# nixos-generate-config

This will create configuration files based on the currently mounted system. This is typically used where NixOS is already installed. By default, nixos-generate-config will not overwrite an existing configuration.nix. To force overwrite an existing file, pass the --force option.

Generate configuration for a target root

To generate configuration files with a specific root directory (commonly used during installation):

# nixos-generate-config --root /mnt

This writes configuration files to /mnt/etc/nixos/.

Show hardware configuration

To print the detected hardware configuration to standard output without writing to disk:

# nixos-generate-config --show-hardware-config

Specifying specific hardware

A collection of hardware specific platforms with their config can be found at NixOS Hardware repository.