Recently installed a NixOS 22.05 The computer as the main system , Record the installation process .( At the time of writing this article ,NixOS The latest version of is NixOS 22.05)
1 Preparing the installation disk
You need an Internet connected computer to prepare NixOS Installation disk of . This computer needs to be Linux perhaps MacOS,Windows If the system has been installed WSL(Linux Subsystem ) It's fine too , Because we need to use it later
dd
This command line tool is used to make the installation disk .
On this computer , Use the download tool from
NixOS The official download address of
https://nixos.org/download.html hold NixOS Of iso Download the file locally .NixOS 22.05 Of iso File size is 2GB about .

While waiting for the download , You can read
NixOS Manuals ( english )
:https://nixos.org/manual/nixos/stable/
When the download is complete , You need to prepare a blank sheet U disc , Plug in USB Interface .
open Linux perhaps MacOS Command line tools for ( For example, the system comes with Terminal), Use
dd
The command will be downloaded iso File output to your U On the disk :
dd if= Just downloaded iso File path of=/dev/ Yours U Disk file path
After the copy is done , Yours USB The installation disk is ready . Unplug spare .
2 Enter the installation disk
You need an Internet connected computer for installation NixOS My target computer .
Insert... On the target computer USB Mounting plate , Plug in the cable .(NixOS The installation process of requires networking , The installation disk may not recognize the wireless network , So the plug-in cable is the most reliable )
After power on, enter BIOS Set the interface , Make two settings :1、 Set the startup sequence to USB first ;2、 close SecureBoot( If you have this option ).
After setting up , Save and exit .
If all goes well , The computer will restart and enter USB On the installation disk NixOS, And enter its graphical installation interface by default .
My lesson is : Do not use this graphical installation interface . This graphical installation interface does not show the progress of the installation at all , Show only one progress bar , If the installation process gets stuck , You can't see where it's stuck . It is recommended to directly click Cancel Button to close the graphical installation interface .
3 Disk partition
Now partition the disk . We use the... Provided with the installation disk GParted Graphical tools to create zones .
Swing the mouse to the upper left corner of the screen , A row of software icons will appear at the bottom of the screen . find GParted, Click the icon to open it .

To build a 512MiB The size of FAT32 Partition , Used to mount /boot Catalog .
To build a EXT4 Format primary partition , Used to mount / root directory . The primary partition can be allocated the size according to its own needs .
To build a 8GiB The size of linux-swap Partition .( This swap Partition if your computer memory is large enough, you can actually do without configuration )
stay GParted After the partition is created , Apply changes .

thus , Disk partition completed . Record the paths of the three partitions for backup .( For example, the paths I generate here are /dev/nvme0n1p1 /dev/nvme0n1p2 /dev/nvme0n1p3)
4 Configure the installation path
Now you need to open the terminal for command line operation .
Swing the mouse to the upper left corner of the screen , Find... In the software icon at the bottom of the screen “ terminal / Console ”, Click the icon to open it .

Enter the instructions in turn :
sudo -i
mount /dev/ You just created EXT4 Partition path /mnt
mkdir -p /mnt/boot
mount /dev/ You just created FAT32 Partition path /mnt/boot
swapon /dev/ You just created LinuxSwap Partition path
nixos-generate-config --root /mnt
After this step , You can edit it manually nixos Configuration file for
/mnt/etc/nixos/configuration.nix
. By default, the installation disk provides nano Editor .
5 edit nixos The configuration file
configuration.nix
The configuration file is nixos The essence of , The system configuration and software installation you want can be written here .
You can contrast
Editing :https://nixos.org/manual/nixos/stable/index.html#ch-configuration
The manual also provides a
:https://nixos.org/manual/nixos/stable/options.html
For Chinese users , More important is the configuration related to Chinese support , Here are my related configurations posted for reference :
time.timeZone = "Asia/Shanghai";
i18n.defaultLocale = "zh_CN.UTF-8";
i18n.inputMethod = {
enabled = "ibus";
ibus.engines = with pkgs.ibus-engines; [ libpinyin ];
};
nix.settings.substituters = [ "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store" ];
If you are right about nixos You are not familiar with , The configuration file section can be skipped first . In the future nixos Play , This configuration file is full of opportunities to do .
6 install
Input instruction :
nixos-install
After the return ,nixos It's time to install , You can see the progress of the installation on the console . The whole installation will take about ten minutes .
nixos After installation , The installer will ask you to enter root password :
setting root password...
New password: ***
Retype new password: ***
Put your root Enter the password twice to complete .
7 Restart the computer
Input instruction :
reboot
After reboot , You will enter the startup selection interface , wait for 5 Seconds or press enter to enter the one you just installed nixos System .

above ,NixOS 22.05 Installation completed !
Installed NixOS You can edit
configuration.nix
Document and
nixos-rebuild
The command continues to customize . A configuration file can customize a system , And each customization can generate an independent version that can be accessed , If you encounter problems, you can directly restart and return to the boot interface to rollback to the previous version , It is said that this design is especially friendly to students who need to maintain many machines or need to change machines frequently .
原网站版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206121749455596.html