feat: accelerating-dotfiles-debugging

This commit is contained in:
Ryan Yin 2024-01-11 12:44:43 +08:00
parent eef309f6de
commit cd8704345e
5 changed files with 83 additions and 5 deletions

View File

@ -205,7 +205,10 @@ function themeConfigEnglish() {
{ text: "callPackage", link: "/nixpkgs/callpackage.md" },
{ text: "Overridding", link: "/nixpkgs/overriding.md" },
{ text: "Overlays", link: "/nixpkgs/overlays.md" },
{ text: "Mutiple Nixpkgs Instances", link: "/nixpkgs/multiple-nixpkgs.md" },
{
text: "Mutiple Nixpkgs Instances",
link: "/nixpkgs/multiple-nixpkgs.md",
},
],
},
{
@ -220,6 +223,10 @@ function themeConfigEnglish() {
text: "Simplify NixOS-related Commands",
link: "/best-practices/simplify-nixos-related-commands.md",
},
{
text: "Accelerating Dotfiles Debugging",
link: "/best-practices/accelerating-dotfiles-debugging.md",
},
{
text: "Custom NIX_PATH and Flake Registry",
link: "/best-practices/nix-path-and-flake-registry.md",
@ -396,7 +403,10 @@ function themeConfigChinese() {
{ text: "callPackage", link: "/zh/nixpkgs/callpackage.md" },
{ text: "Overridding", link: "/zh/nixpkgs/overriding.md" },
{ text: "Overlays", link: "/zh/nixpkgs/overlays.md" },
{ text: "多 Nixpkgs 实例", link: "/zh/nixpkgs/multiple-nixpkgs.md" },
{
text: "多 Nixpkgs 实例",
link: "/zh/nixpkgs/multiple-nixpkgs.md",
},
],
},
{
@ -411,6 +421,10 @@ function themeConfigChinese() {
text: "使用 Makefile 简化常用命令",
link: "/zh/best-practices/simplify-nixos-related-commands.md",
},
{
text: "Accelerating Dotfiles Debugging",
link: "/zh/best-practices/accelerating-dotfiles-debugging.md",
},
{
text: "自定义 NIX_PATH 与 Flake Registry",
link: "/zh/best-practices/nix-path-and-flake-registry.md",

View File

@ -0,0 +1,29 @@
# Accelerating Dotfiles Debugging
When managing our Dotfiles with Home Manager, a common challenge arises each modification to our Dotfiles requires executing `sudo nixos-rebuild switch`(or `home-manager switch` if you use don't integrate home-manager into NixOS) to take effect. However, running this command recalculates the entire system state each time, even though Nix internally employs various caching mechanisms to expedite the process, it can still be cumbersome.
Take my Neovim/Emacs configurations as an example; I frequently make high-frequency modifications to them, sometimes dozens or hundreds of times a day. If each modification necessitates waiting for `nixos-rebuild` to run for several seconds, it becomes a significant time drain.
Fortunately, with the solution outlined in [Simplifying NixOS Commands using Justfile](./en/best-practices/simplify-nixos-related-commands.md), we can expedite testing and verification of frequently modified Dotfiles by adding specific configurations to the `Justfile`.
For instance, I've added the following content to my Justfile:
> The latest Justfile I'm using: [ryan4yin/nix-config/Justfile](https://github.com/ryan4yin/nix-config/blob/main/Justfile)
```Makefile
###############################################################
# Quick Test - Neovim
###############################################################
nvim-test:
rm -rf $"($env.HOME)/.config/astronvim/lua/user"
rsync -avz --copy-links --chmod=D2755,F744 home/base/desktop/editors/neovim/astronvim_user/ $"($env.HOME)/.config/astronvim/lua/user"
nvim-clean:
rm -rf $"($env.HOME)/.config/astronvim/lua/user"
```
Now, when I need to quickly test my Neovim configuration after making changes, I simply run `just nvim-test`. Once testing is complete, I execute `just nvim-clean`, followed by redeploying the configuration using `nixos-rebuild`. This allows for swift testing and seamless restoration of the configuration.

View File

@ -6,7 +6,9 @@ Alternatively, you can also use similar tools like Makefile or [cargo-make](http
Below is an example of how my Justfile looks:
```justfile
> The latest Justfile I'm using: [ryan4yin/nix-config/Justfile](https://github.com/ryan4yin/nix-config/blob/main/Justfile)
```Makefile
# just is a command runner, Justfile is very similar to Makefile, but simpler.
############################################################################

View File

@ -0,0 +1,31 @@
# 加速 Dotfiles 的调试
在使用了 Home Manager 管理我们的 Dotfiles 后,会遇到的一个问题是,每次修改完我们的 Dotfiles都需要通过跑一遍 `sudo nixos-rebuild switch`(或者如果你是单独使用 home manager 的话,应该是这个指令 `home-manager switch`) 才能生效,但每次运行这个指令都会重新计算整个系统的状态,即使 Nix 内部现在已经有了很多缓存机制可以加速这个计算,这仍然是很痛苦的。
以我的 Neovim/Emacs 配置为例,我日常修改它们的频率非常高,有时候一天要改几十上百次,如果每次修改都要等 `nixos-rebuild` 跑个几十秒,这简直是在浪费时间。
幸运的是,在有了 [使用 Justfile 简化 NixOS 相关命令](./zh/best-practices/simplify-nixos-related-commands.md) 这个方案后,我们可以通过往 `Justfile` 里添加些配置来实现快速的测试验证这些需要频繁修改的 Dotfiles.
比如我现在添加了这些 Justfile 内容:
> 我使用的 Justfile 最新版: [ryan4yin/nix-config/Justfile](https://github.com/ryan4yin/nix-config/blob/main/Justfile)
```Makefile
###############################################################
# Quick Test - Neovim
###############################################################
nvim-test:
rm -rf $"($env.HOME)/.config/astronvim/lua/user"
rsync -avz --copy-links --chmod=D2755,F744 home/base/desktop/editors/neovim/astronvim_user/ $"($env.HOME)/.config/astronvim/lua/user"
nvim-clean:
rm -rf $"($env.HOME)/.config/astronvim/lua/user"
```
然后在需要快速测试 Neovim 配置时,每次修改完配置后,跑一下 `just nvim-test`,我的配置就更新了。
测试完毕后,运行下 `just nvim-clean`,再重新用 `nixos-rebuild` 部署下配置,就完成了配置的还原。

View File

@ -5,9 +5,11 @@
我使用了 [just](https://github.com/casey/just) 来管理我的 flake 配置相关的命令,简化使用。
你也可以使用其他类似的工具来干这个活(比如说 Makefile 或 [cargo-make](https://github.com/sagiegurari/cargo-make)),这里我仅介绍下我的用法以供参考。
我的 Justfile 大概内容截取如下(最新版本见 [ryan4yin/nix-config/Justfile](https://github.com/ryan4yin/nix-config/blob/main/Justfile)
我的 Justfile 大概内容截取如下:
```justfile
> 我使用的 Justfile 最新版: [ryan4yin/nix-config/Justfile](https://github.com/ryan4yin/nix-config/blob/main/Justfile)
```Makefile
# just is a command runner, Justfile is very similar to Makefile, but simpler.
############################################################################