feat: update system, simplify nixos-related commands

This commit is contained in:
Ryan Yin 2024-01-11 13:30:33 +08:00
parent 08d834d05d
commit b1a2957837
4 changed files with 33 additions and 6 deletions

View File

@ -23,18 +23,28 @@ deploy:
debug:
nixos-rebuild switch --flake . --use-remote-sudo --show-trace --verbose
update:
up:
nix flake update
# Update specific input
# usage: make upp i=home-manager
upp:
nix flake lock --update-input $(i)
history:
nix profile history --profile /nix/var/nix/profiles/system
gc:
repl:
nix repl -f flake:nixpkgs
clean:
# remove all generations older than 7 days
sudo nix profile wipe-history --profile /nix/var/nix/profiles/system --older-than 7d
gc:
# garbage collect all unused nix store entries
sudo nix store gc --debug
sudo nix-collect-garbage --delete-old
############################################################################
#

View File

@ -6,8 +6,11 @@ With Flakes, updating the system is straightforward. Simply execute the followin
# Update flake.lock
nix flake update
# Or replace only the specific input, such as home-manager:
nix flake lock --update-input home-manager
# Apply the updates
sudo nixos-rebuild switch --flake .
```
Occasionally, you may encounter a "sha256 mismatch" error when running `nixos-rebuild switch`. This error can be resolved by updating `flake.lock` using `nix flake update`.
Occasionally, you may encounter a "sha256 mismatch" error when running `nixos-rebuild switch`. This error can be resolved by updating `flake.lock` using `nix flake update`.

View File

@ -24,18 +24,28 @@ deploy:
debug:
nixos-rebuild switch --flake . --use-remote-sudo --show-trace --verbose
update:
up:
nix flake update
# Update specific input
# usage: make upp i=home-manager
upp:
nix flake lock --update-input $(i)
history:
nix profile history --profile /nix/var/nix/profiles/system
gc:
repl:
nix repl -f flake:nixpkgs
clean:
# remove all generations older than 7 days
sudo nix profile wipe-history --profile /nix/var/nix/profiles/system --older-than 7d
gc:
# garbage collect all unused nix store entries
sudo nix store gc --debug
sudo nix-collect-garbage --delete-old
############################################################################
#

View File

@ -3,8 +3,12 @@
在使用了 Nix Flakes 后,要更新系统也很简单,先更新 flake.lock 文件,然后部署即可。在配置文件夹中执行如下命令:
```shell
# 更新 flake.lock
# 更新 flake.lock(更新所有依赖项)
nix flake update
# 或者也可以只更新特定的依赖项,比如只更新 home-manager:
nix flake lock --update-input home-manager
# 部署系统
sudo nixos-rebuild switch --flake .
```