NixOS Installation Guide: Difference between revisions

Mayer (talk | contribs)
No edit summary
Pigs (talk | contribs)
extra configuration examples, link to more pages, clean up wording
Line 2: Line 2:
<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 89: 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 122: 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 129: 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:
 
<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.


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


<!--T:47-->
<!--T:47-->
Line 170: Line 173:
* w (write)
* w (write)


== Label partitions == <!--T:50-->
=== 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
$ sudo mkfs.fat -F 32 /dev/sdX1
# mkfs.fat -F 32 -n boot /dev/sdX1
$ sudo fatlabel /dev/sdX1 NIXBOOT
# mkfs.ext4 /dev/sdX2 -L nixos
$ sudo mkfs.ext4 /dev/sdX2 -L NIXROOT
# mount /dev/disk/by-label/boot /mnt
$ sudo mount /dev/disk/by-label/NIXROOT /mnt
# mkdir -p /mnt/boot
$ sudo mkdir -p /mnt/boot
# mount /dev/disk/by-label/boot /mnt/boot
$ sudo mount /dev/disk/by-label/NIXBOOT /mnt/boot
</syntaxhighlight>
</syntaxhighlight>


<!--T:52-->
<!--T:53-->
== Swap file ==
== 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">
$ 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-->
Most essential changes:
== NixOS config ==
<syntaxhighlight lang="console">
$ sudo nixos-generate-config --root /mnt
$ cd /mnt/etc/nixos/
$ sudo vim configuration.nix
</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: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]].
Sysyemd-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>
}}


<!--T:56-->
<!--T:56-->
== NixOS installation ==
== NixOS installation ==
<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>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 substitute false # no downloads
$ nixos-rebuild switch --option binary-caches "" # 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 280:


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