mirror of
https://github.com/ryan4yin/nixos-and-flakes-book.git
synced 2025-08-18 08:29:40 +02:00
fix: update nixos system
This commit is contained in:
@@ -3,6 +3,10 @@
|
|||||||
With Flakes, updating the system is straightforward. Simply execute the following commands
|
With Flakes, updating the system is straightforward. Simply execute the following commands
|
||||||
in `/etc/nixos` or any other location where you keep the configuration:
|
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
|
```shell
|
||||||
# Update flake.lock
|
# Update flake.lock
|
||||||
nix flake update
|
nix flake update
|
||||||
@@ -11,10 +15,12 @@ nix flake update
|
|||||||
nix flake update home-manager
|
nix flake update home-manager
|
||||||
|
|
||||||
# Apply the updates
|
# 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')
|
# Or to update flake.lock & apply with one command (i.e. same as running "nix flake update" before)
|
||||||
sudo nixos-rebuild switch --flake .
|
sudo nixos-rebuild switch --recreate-lock-file
|
||||||
```
|
```
|
||||||
|
|
||||||
Occasionally, you may encounter a "sha256 mismatch" error when running
|
Occasionally, you may encounter a "sha256 mismatch" error when running
|
||||||
|
@@ -11,7 +11,13 @@ nix flake update
|
|||||||
nix flake update home-manager
|
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 不匹配的报错,也
|
另外有时候安装新的包,跑 `sudo nixos-rebuild switch` 时可能会遇到 sha256 不匹配的报错,也
|
||||||
|
Reference in New Issue
Block a user