NixOS Installation Guide: Difference between revisions

Sk7Str1p3 (talk | contribs)
Marked this version for translation
Ardenet (talk | contribs)
Marked this version for translation
Tags: Mobile edit Mobile web edit
 
(7 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<translate>
<!--T:1-->
<!--T:1-->
This guide is 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 installation of [[Nix]] within an existing operating system, see [[Nix Installation 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 describing 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.
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.
 
<!--T:3-->
Use this guide as a step-by-step guide, choices will be presented, use only the selected section, and continue at the section it tells you to at the end.


== Installation target == <!--T:4-->
== Installation target == <!--T:4-->
Line 88: Line 86:


<!--T:28-->
<!--T:28-->
Since the installation media is hybrid, it will boot both in legacy bios mode and UEFI mode.
The installation media is hybrid and is capable of booting in both legacy BIOS mode and [[UEFI]] mode.


<!--T:29-->
<!--T:29-->
Line 121: Line 119:


<!--T:41-->
<!--T:41-->
Network Manager 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.
[[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 128: Line 126:


<!--T:43-->
<!--T:43-->
On the minimal ISO, or if you are more familiar with <code>wpa_supplicant</code> 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>.
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 DOS or (U)EFI.
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:
</translate>
 
<syntaxhighlight lang="console">
$ [ -d /sys/firmware/efi/efivars ] && echo "UEFI" || echo "Legacy"
</syntaxhighlight>
 
<translate>
<!--T:63-->
A very simple example setup is given here.
A very simple example setup is given here.


=== DOS === <!--T:46-->
=== Legacy Boot (MBR) === <!--T:46-->


<!--T:47-->
<!--T:47-->
Line 169: Line 175:
* w (write)
* w (write)


== Label partitions == <!--T:50-->
=== Format partitions === <!--T:50-->
 
<!--T:64-->
The example below uses the [[ext4]] filesystem format. If you wish to use other filesystem formats such as [[Btrfs]] or [[ZFS]]:
 
<!--T:65-->
* [[Bcachefs#NixOS installation on bcachefs]]
* [[Btrfs#Installation of NixOS on btrfs]]
* [[LVM#Basic Setup]]
* [[ZFS#Simple NixOS ZFS on root installation]]


<!--T:51-->
<!--T:51-->
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
$ lsblk
</translate>
$ sudo mkfs.fat -F 32 /dev/sdX1
 
$ sudo fatlabel /dev/sdX1 NIXBOOT
<syntaxhighlight lang="console">
$ sudo mkfs.ext4 /dev/sdX2 -L NIXROOT
$ lsblk # lists current system block devices
$ sudo mount /dev/disk/by-label/NIXROOT /mnt
# mkfs.fat -F 32 -n boot /dev/sdX1
$ sudo mkdir -p /mnt/boot
# mkfs.ext4 /dev/sdX2 -L nixos
$ sudo mount /dev/disk/by-label/NIXBOOT /mnt/boot
# mount /dev/disk/by-label/nixos /mnt
# mkdir -p /mnt/boot
# mount /dev/disk/by-label/boot /mnt/boot
</syntaxhighlight>
</syntaxhighlight>


<!--T:52-->
<translate>
== Swap file ==
== NixOS configuration == <!--T:53-->
 
<!--T:66-->
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]]:
</translate>
 
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
$ sudo dd if=/dev/zero of=/mnt/.swapfile bs=1024 count=2097152 (2GB size)
# nixos-generate-config --root /mnt
$ sudo chmod 600 /mnt/.swapfile
# nano /mnt/etc/nixos/configuration.nix
$ sudo mkswap /mnt/.swapfile
$ sudo swapon /mnt/.swapfile
</syntaxhighlight>
</syntaxhighlight>


<!--T:53-->
<translate>
== NixOS config ==
<!--T:67-->
<syntaxhighlight lang="console">
For information on working with a system configuration, see [[NixOS system configuration]]. For desktop-specific configurations, see [[NixOS as a desktop]].
$ sudo nixos-generate-config --root /mnt
 
$ cd /mnt/etc/nixos/
<!--T:68-->
$ sudo vim configuration.nix
Most essential changes:
</syntaxhighlight>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>
* <code>users.users.user</code> with adding entry <code>initialPassword = "pw123";</code>
* [[networking]] (wifi), see below for fix if it breaks
* [[networking]] (wifi), see below for fix if it breaks
* <code>boot.loader.grub.device = "/dev/sda"; #or "nodev" for efi only</code>
* install [[:Category:Text Editor|editor]] to edit the configuration
* install editor to edit the configuration
* change hardware config to use labels


<!--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:56-->
=== Swap file === <!--T:52-->
== NixOS installation ==
 
<!--T:69-->
For additional methods of configuring swap, see [[Swap]]. The following example demonstrates how to create and enable a [[Swap#Swap file|swap file]]:
</translate>
 
{{file|/mnt/etc/nixos/configuration.nix|nix|
<nowiki>
  swapDevices = [{
    device = "/var/lib/swapfile";
    size = 16*1024; # 16 GB
  }];
</nowiki>
}}
 
<translate>
=== Bootloader === <!--T:70-->
 
<!--T:71-->
NixOS supports multiple [[Bootloader|bootloaders]] such as [[GNU GRUB]] and [[Systemd/boot]].
 
<!--T:72-->
Systemd-boot is the recommended bootloader. The following example demonstrates how to enable systemd-boot in your configuration:
</translate>
 
{{file|/mnt/etc/nixos/configuration.nix|nix|
<nowiki>
  boot.loader.systemd-boot.enable = true;
</nowiki>
}}
 
<translate>
<!--T:73-->
You may also wish to configure [[Secure Boot]].
 
=== Users === <!--T:74-->
 
<!--T:75-->
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:
</translate>
 
{{file|/mnt/etc/nixos/configuration.nix|nix|
<nowiki>
  users.users.alice = {
    isNormalUser = true;
    initialPassword = "pw123";
  };
</nowiki>
}}
 
<translate>
== NixOS installation == <!--T:56-->
</translate>
 
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
$ cd /mnt
# cd /mnt
$ sudo nixos-install
# nixos-install
</syntaxhighlight>after installation: Run <code>passwd</code> to change user password.
</syntaxhighlight>
 
<translate>
<!--T:76-->
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:
$ nixos-rebuild switch --option substitute false # no downloads
</translate>
$ nixos-rebuild switch --option binary-caches "" # no downloads
 
<syntaxhighlight lang="console">
# nixos-rebuild switch --option substitute false # no downloads
# nixos-rebuild switch --option binary-caches "" # no downloads
</syntaxhighlight>
</syntaxhighlight>
<translate>
<!--T:58-->
* wpa_supplicant flags to connect to wifi
* wpa_supplicant flags to connect to wifi
</translate>


<!--T:58-->
<hr />
<hr />


<translate>
== Additional notes for specific hardware == <!--T:59-->
== Additional notes for specific hardware == <!--T:59-->


Line 237: Line 316:


<!--T:62-->
<!--T:62-->
[[Category:Guide]][[Category:Deployment]]
[[Category:Guide]]
[[Category:Deployment]]
[[Category:NixOS]]
</translate>
</translate>