nixos-generate-config - Man Page
generate NixOS configuration modules
Synopsis
Description
This command writes two NixOS configuration modules:
- /etc/nixos/hardware-configuration.nix
This module sets NixOS configuration options based on your current hardware configuration. In particular, it sets the fileSystem option to reflect all currently mounted file systems, the swapDevices option to reflect active swap devices, and the boot.initrd.* options to ensure that the initial ramdisk contains any kernel modules necessary for mounting the root file system.
If this file already exists, it is overwritten. Thus, you should not modify it manually. Rather, you should include it from your /etc/nixos/configuration.nix, and re-run nixos-generate-config to update it whenever your hardware configuration changes.
- /etc/nixos/configuration.nix
This is the main NixOS system configuration module. If it already exists, it’s left unchanged. Otherwise, nixos-generate-config will write a template for you to customise.
Options
This command accepts the following options:
- --root
If this option is given, treat the directory root as the root of the file system. This means that configuration files will be written to root/etc/nixos, and that any file systems outside of root are ignored for the purpose of generating the fileSystems option.
- --dir
If this option is given, write the configuration files to the directory dir instead of /etc/nixos.
- --force
Overwrite /etc/nixos/configuration.nix if it already exists.
- --no-filesystems
Omit everything concerning file systems and swap devices from the hardware configuration.
- --show-hardware-config
Don't generate configuration.nix or hardware-configuration.nix and print the hardware configuration to stdout only.
Examples
This command is typically used during NixOS installation to write initial configuration modules. For example, if you created and mounted the target file systems on /mnt and /mnt/boot, you would run:
$ nixos-generate-config --root /mnt
The resulting file /mnt/etc/nixos/hardware-configuration.nix might look like this:
# Do not modify this file! It was generated by ‘nixos-generate-config’ # and may be overwritten by future invocations. Please make changes # to /etc/nixos/configuration.nix instead. { config, pkgs, ... }: { imports = [ <nixos/modules/installer/scan/not-detected.nix> ]; boot.initrd.availableKernelModules = [ "ehci_hcd" "ahci" ]; boot.kernelModules = [ "kvm-intel" ]; boot.extraModulePackages = [ ]; fileSystems."/" = { device = "/dev/disk/by-label/nixos"; fsType = "ext3"; options = [ "rw" "data=ordered" "relatime" ]; }; fileSystems."/boot" = { device = "/dev/sda1"; fsType = "ext3"; options = [ "rw" "errors=continue" "user_xattr" "acl" "barrier=1" "data=writeback" "relatime" ]; }; swapDevices = [ { device = "/dev/sda2"; } ]; nix.maxJobs = 8; }
It will also create a basic /mnt/etc/nixos/configuration.nix, which you should edit to customise the logical configuration of your system. This file includes the result of the hardware scan as follows:
imports = [ ./hardware-configuration.nix ];
After installation, if your hardware configuration changes, you can run:
$ nixos-generate-config
to update /etc/nixos/hardware-configuration.nix. Your /etc/nixos/configuration.nix will not be overwritten.
Author
Eelco Dolstra
Author
Copyright
Copyright © 2007-2020 Eelco Dolstra