mirror of
https://github.com/ryan4yin/nixos-and-flakes-book
synced 2024-11-12 23:57:07 +00:00
feat: intro
This commit is contained in:
parent
e30b9a44f2
commit
a09d77f0c8
3 changed files with 31 additions and 3 deletions
|
@ -28,4 +28,19 @@ To my delight, NixOS has exceeded my expectations. The most astonishing aspect i
|
|||
|
||||
The rollback capability and reproducibility of NixOS has instilled a great deal of confidence in me—I no longer fear breaking the system. I've even ventured into experimenting with new things on NixOS, such as the hyprland compositor. Previously, on EndeavourOS, I wouldn't have dared to tinker with such novel compositors, as any system mishaps would have entailed significant manual troubleshooting using various workarounds.
|
||||
|
||||
This is why I chose NixOS.
|
||||
As I get more and more involved with NixOS and Nix, I find it also very suitable for synchronously managing the configuration of multiple hosts.
|
||||
Currently my personal [ryan4yin/nix-config] (https://github.com/ryan4yin/nix-config) synchronously manages the configuration of many hosts:
|
||||
|
||||
- Desktop computers
|
||||
- 1 Macbook Pro 2020 (Intel amd64).
|
||||
- 1 Macbook Pro 2022 (M2 aarch64).
|
||||
- 1 NixOS desktop PC (amd64).
|
||||
- Servers
|
||||
- 3 NixOS virtual machines (amd64).
|
||||
- Several development boards for aarch64 and riscv64.
|
||||
|
||||
The development environment of three desktop computers is managed by Home Manager,
|
||||
the main configuration is completely shared, and the configuration modified on any host can be seamlessly synchronized to other hosts through Git.
|
||||
|
||||
Nix almost completely shielded me from the differences between OS and architecture at the bottom of the three machines, and the experience was very slippery!
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
Now that we have learned the basics of the Nix language, we can start using it to configure our NixOS system. The default configuration file for NixOS is located at `/etc/nixos/configuration.nix`. This file contains all the declarative configuration for the system, including settings for the time zone, language, keyboard layout, network, users, file system, and boot options.
|
||||
|
||||
To modify the system state in a reproducible manner (which is highly recommended), we need to manually edit the `/etc/nixos/configuration.nix` file and then execute `sudo nixos-rebuild switch` to apply the modified configuration. This command generates a new system environment based on the modified configuration file, sets the new environment as the default one, and preserves the previous environment in the boot options of grub/systemd-boot. This ensures that we can always roll back to the old environment if the new one fails to start.
|
||||
To modify the system state in a reproducible manner (which is highly recommended), we need to manually edit the `/etc/nixos/configuration.nix` file and then execute `sudo nixos-rebuild switch` to apply the modified configuration. This command generates a new system environment based on the modified configuration file, sets the new environment as the default one, and preserves the previous environment in the boot options of grub/systemd-boot. This ensures that we can always roll back to the old environment even if the new one fails to start.
|
||||
|
||||
While `/etc/nixos/configuration.nix` is the classic method for configuring NixOS, it relies on data sources configured by `nix-channel` and lacks a version-locking mechanism, making it challenging to ensure the reproducibility of the system. A better approach is to use Flakes, which provides reproducibility and facilitates configuration management.
|
||||
|
||||
|
|
|
@ -33,4 +33,17 @@ Nix 是一个声明式的软件包管理器,用户需要通过某些配置声
|
|||
NixOS 的回滚能力与可复现能力给了我非常大的底气,我现在再也不用怕把系统搞挂了(挂了直接回滚就恢复了),于是我又在 NixOS 尝试了许多新鲜玩意儿!
|
||||
在以前 EndeavourOS 上我肯定是不太敢这么玩的,因为万一要是把系统玩出问题了,就必须手动修复系统状态,那可是相当麻烦。
|
||||
|
||||
这就是我选择 NixOS 的原因。
|
||||
随着我对 NixOS 与 Nix 的使用越来越深入,我发现它还非常适合用于同步管理多台主机的配置。
|
||||
目前我的个人配置 [ryan4yin/nix-config](https://github.com/ryan4yin/nix-config) 同步管理了许多主机的配置:
|
||||
|
||||
- 桌面电脑
|
||||
- 一台 Macbook Pro 2020 (Intel amd64)
|
||||
- 一台 Macbook Pro 2022 (M2 aarch64)
|
||||
- 一台 NixOS 桌面 PC (amd64)
|
||||
- 服务器
|
||||
- 三台 NixOS 虚拟机(amd64)
|
||||
- 若干块 aarch64 跟 riscv64 的开发板
|
||||
|
||||
其中三台桌面电脑的开发环境都通过 Home Manager 管理,主要配置完全共用,在任意一台主机上修改的配置,可以通过 Git 无缝同步到其他主机上。NixOS 几乎完全帮我屏蔽了三台机器底层的 OS 与芯片架构差异,体验非常丝滑!
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue