From 509c89f71e9974f9db8ae75ef807a8e88d8ac82c Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Thu, 26 Jun 2025 09:56:49 +0800 Subject: [PATCH] fix: update nixos system --- docs/en/nixos-with-flakes/update-the-system.md | 12 +++++++++--- docs/zh/nixos-with-flakes/update-the-system.md | 8 +++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/en/nixos-with-flakes/update-the-system.md b/docs/en/nixos-with-flakes/update-the-system.md index 14f1f69..7fecfa4 100644 --- a/docs/en/nixos-with-flakes/update-the-system.md +++ b/docs/en/nixos-with-flakes/update-the-system.md @@ -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 diff --git a/docs/zh/nixos-with-flakes/update-the-system.md b/docs/zh/nixos-with-flakes/update-the-system.md index b23ce33..ff31931 100644 --- a/docs/zh/nixos-with-flakes/update-the-system.md +++ b/docs/zh/nixos-with-flakes/update-the-system.md @@ -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 不匹配的报错,也