fix: update nixos system

This commit is contained in:
Ryan Yin
2025-06-26 09:56:49 +08:00
parent 345ae5e71e
commit 509c89f71e
2 changed files with 16 additions and 4 deletions

View File

@@ -3,6 +3,10 @@
With Flakes, updating the system is straightforward. Simply execute the following commands
in `/etc/nixos` or any other location where you keep the configuration:
> **NOTE**: The `/etc/nixos` directory is owned by and only writable to `root`. Therefore,
> if your flake is located in this directory, you'll need to use `sudo` to update any
> configuration files.
```shell
# Update flake.lock
nix flake update
@@ -11,10 +15,12 @@ nix flake update
nix flake update home-manager
# Apply the updates
sudo nixos-rebuild switch --flake .
sudo nixos-rebuild switch
# Or if your flake is not located at /etc/nixos
sudo nixos-rebuild switch --flake /path/to/flake
# Or to update flake.lock & apply with one command (i.e. same as running "nix flake update" before 'switch')
sudo nixos-rebuild switch --flake .
# Or to update flake.lock & apply with one command (i.e. same as running "nix flake update" before)
sudo nixos-rebuild switch --recreate-lock-file
```
Occasionally, you may encounter a "sha256 mismatch" error when running

View File

@@ -11,7 +11,13 @@ nix flake update
nix flake update home-manager
# 部署系统
sudo nixos-rebuild switch --flake .
sudo nixos-rebuild switch
# 如果你的 flake 不在 /etc/nixos 中,则需要额外使用 --flake 参数指定
sudo nixos-rebuild switch --flake /path/to/flake
# 也可以一行命令同时实现 nix flake update 与系统部署
sudo nixos-rebuild switch --recreate-lock-file
```
另外有时候安装新的包,跑 `sudo nixos-rebuild switch` 时可能会遇到 sha256 不匹配的报错,也