NixOS Installation Guide: Difference between revisions
No edit summary |
m fix typo in #Custom_configuration |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 2: | Line 2: | ||
<translate> | <translate> | ||
<!--T:1--> | <!--T:1--> | ||
This guide | This guide serves as a companion guide for the [https://nixos.org/nixos/manual/index.html#ch-installation official manual]. It describes installation of [[NixOS]] as a complete operating system. For instructions on installing [[Nix]] within an existing operating system, refer to the [[Nix Installation Guide]]. | ||
<!--T:2--> | <!--T:2--> | ||
In addition to | In addition to covering the steps from the official manual, it provides known good instructions for common use cases. When there is a discrepancy between the manual and this guide, the supported case is the one described in the manual. | ||
== Installation target == <!--T:4--> | == Installation target == <!--T:4--> | ||
Line 89: | Line 86: | ||
<!--T:28--> | <!--T:28--> | ||
The installation media is hybrid and is capable of booting in both legacy BIOS mode and [[UEFI]] mode. | |||
<!--T:29--> | <!--T:29--> | ||
Line 122: | Line 119: | ||
<!--T:41--> | <!--T:41--> | ||
[[NetworkManager]] is installed on the graphical ISO, meaning that it is possible to use <code>nmtui</code> on the command line to connect to a network. | |||
<!--T:42--> | <!--T:42--> | ||
Line 129: | Line 126: | ||
<!--T:43--> | <!--T:43--> | ||
On the minimal ISO, or if you are more familiar with | On the minimal ISO, or if you are more familiar with [[wpa_supplicant]] then you can also run <code>wpa_passphrase ESSID | sudo tee /etc/wpa_supplicant.conf</code>, then enter your password and <code>systemctl restart wpa_supplicant</code>. | ||
== Partitioning == <!--T:44--> | == Partitioning == <!--T:44--> | ||
<!--T:45--> | <!--T:45--> | ||
To partition the persistent storage run <code>sudo fdisk /dev/diskX</code> and follow instructions for | To partition the persistent storage run <code>sudo fdisk /dev/diskX</code> and follow instructions for MBR or (U)EFI. To determine which mode you are booted into, run: | ||
<syntaxhighlight lang="console"> | |||
$ [ -d /sys/firmware/efi/efivars ] && echo "UEFI" || echo "Legacy" | |||
</syntaxhighlight> | |||
A very simple example setup is given here. | A very simple example setup is given here. | ||
=== | === Legacy Boot (MBR) === <!--T:46--> | ||
<!--T:47--> | <!--T:47--> | ||
Line 170: | Line 173: | ||
* w (write) | * w (write) | ||
== | === Format partitions === <!--T:50--> | ||
<!--T:51--> | <!--T:51--> | ||
The example below uses the [[ext4]] filesystem format. If you wish to use other filesystem formats such as [[Btrfs]] or [[ZFS]]: | |||
* [[Bcachefs#NixOS installation on bcachefs]] | |||
* [[Btrfs#Installation of NixOS on btrfs]] | |||
* [[LVM#Basic Setup]] | |||
* [[ZFS#Simple NixOS ZFS on root installation]] | |||
This is useful for having multiple setups and makes partitions easier to handle<syntaxhighlight lang="console"> | This is useful for having multiple setups and makes partitions easier to handle<syntaxhighlight lang="console"> | ||
$ lsblk | $ lsblk # lists current system block devices | ||
# mkfs.fat -F 32 -n boot /dev/sdX1 | |||
# mkfs.ext4 /dev/sdX2 -L nixos | |||
# mount /dev/disk/by-label/nixos /mnt | |||
# mkdir -p /mnt/boot | |||
# mount /dev/disk/by-label/boot /mnt/boot | |||
</syntaxhighlight> | </syntaxhighlight> | ||
<!--T: | <!--T:53--> | ||
== | == NixOS configuration == | ||
NixOS is configured through a [[Overview of the NixOS Linux distribution#Declarative Configuration|declarative configuration]] file. To generate a default config file, run [[nixos-generate-config]]: | |||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
# nixos-generate-config --root /mnt | |||
# nano /mnt/etc/nixos/configuration.nix | |||
</syntaxhighlight> | </syntaxhighlight> | ||
For information on working with a system configuration, see [[NixOS system configuration]]. For desktop-specific configurations, see [[NixOS as a desktop]]. | |||
Most essential changes: | |||
<!--T:54--> | <!--T:54--> | ||
* keyboard layout, ie <code>[[Keyboard Layout Customization|services.xserver.xkb.layout]]</code> | * keyboard layout, ie <code>[[Keyboard Layout Customization|services.xserver.xkb.layout]]</code> | ||
* [[networking]] (wifi), see below for fix if it breaks | * [[networking]] (wifi), see below for fix if it breaks | ||
* install [[:Category:Text Editor|editor]] to edit the configuration | |||
* install editor to edit the configuration | |||
<!--T:55--> | <!--T:55--> | ||
The self-documenting NixOS options can be searched with [https://search.nixos.org/options NixOS options search]. | The self-documenting NixOS options can be searched with [https://search.nixos.org/options NixOS options search]. | ||
<!--T: | <!--T:52--> | ||
=== Swap file === | |||
For additional methods of configuring swap, see [[Swap]]. The following example demonstrates how to create and enable a [[Swap#Swap file|swap file]]: | |||
{{file|/mnt/etc/nixos/configuration.nix|nix| | |||
<nowiki> | |||
swapDevices = [{ | |||
device = "/var/lib/swapfile"; | |||
size = 16*1024; # 16 GB | |||
}]; | |||
</nowiki> | |||
}} | |||
=== Bootloader === | |||
NixOS supports multiple [[Bootloader|bootloaders]] such as [[GNU GRUB]] and [[Systemd/boot]]. | |||
Systemd-boot is the recommended bootloader. The following example demonstrates how to enable systemd-boot in your configuration: | |||
{{file|/mnt/etc/nixos/configuration.nix|nix| | |||
<nowiki> | |||
boot.loader.systemd-boot.enable = true; | |||
</nowiki> | |||
}} | |||
You may also wish to configure [[Secure Boot]]. | |||
=== Users === | |||
For information on creating and managing users, see [[User management]] and the {{NixOS Manual|name=NixOS Manual: Chapter - Package Management|anchor=#sec-user-management}}. See an example below: | |||
{{file|/mnt/etc/nixos/configuration.nix|nix| | |||
<nowiki> | |||
users.users.alice = { | |||
isNormalUser = true; | |||
initialPassword = "pw123"; | |||
}; | |||
</nowiki> | |||
}} | |||
== NixOS installation == | == NixOS installation == | ||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
# cd /mnt | |||
# nixos-install | |||
</syntaxhighlight>after installation: Run <code>passwd</code> to change user password. | </syntaxhighlight>after installation: Run <code>passwd</code> to change user password. | ||
<!--T:57--> | <!--T:57--> | ||
if internet broke/breaks, try one of the following:<syntaxhighlight lang="console"> | if internet broke/breaks, try one of the following:<syntaxhighlight lang="console"> | ||
# nixos-rebuild switch --option substitute false # no downloads | |||
# nixos-rebuild switch --option binary-caches "" # no downloads | |||
</syntaxhighlight> | </syntaxhighlight> | ||
* wpa_supplicant flags to connect to wifi | * wpa_supplicant flags to connect to wifi | ||
Line 238: | Line 281: | ||
<!--T:62--> | <!--T:62--> | ||
[[Category:Guide]][[Category:Deployment]] | [[Category:Guide]] | ||
[[Category:Deployment]] | |||
[[Category:NixOS]] | |||
</translate> | </translate> |