feat: add Misterio77/nix-starter-configs

This commit is contained in:
Ryan Yin 2023-08-13 12:24:33 +08:00
parent 6ca455048f
commit af34724e5a
2 changed files with 14 additions and 5 deletions

View file

@ -20,7 +20,7 @@ The functions of these four files are:
By modifying these files, you can declaratively change the system and home directory status.
However, as the configuration grows, relying solely on `configuration.nix` and `home.nix` can lead to bloated and difficult-to-maintain files. A better solution is to use the Nix module system to split the configuration into multiple Nix modules and write them in a classified manner.
However, as the configuration grows, relying solely on `configuration.nix` and `home.nix` can lead to bloated and difficult-to-maintain files. A better solution is to use the Nix module system to split the configuration into multiple Nix modules and write them in a classified manner.
The Nix module system provides a parameter, `imports`, which accepts a list of `.nix` files and merges all the configuration defined in these files into the current Nix module. Note that `imports` will not simply overwrite duplicate configuration but handle it more reasonably. For example, if `program.packages = [...]` is defined in multiple modules, then `imports` will merge all `program.packages` defined in all Nix modules into one list. Attribute sets can also be merged correctly. The specific behavior can be explored by yourself.
@ -28,7 +28,11 @@ The Nix module system provides a parameter, `imports`, which accepts a list of `
With the help of `imports`, we can split `home.nix` and `configuration.nix` into multiple Nix modules defined in different `.nix` files.
For example, [ryan4yin/nix-config/v0.0.2](https://github.com/ryan4yin/nix-config/tree/v0.0.2) is the configuration of my previous NixOS system with the i3 window manager. Its structure is as follows:
Here is a nice starter example of modularizing the configuration, Highly recommended:
- [Misterio77/nix-starter-configs](https://github.com/Misterio77/nix-starter-configs)
A more complicated example, [ryan4yin/nix-config/v0.0.2](https://github.com/ryan4yin/nix-config/tree/v0.0.2) is the configuration of my previous NixOS system with the i3 window manager. Its structure is as follows:
```shell
├── flake.lock
@ -83,7 +87,7 @@ For example, [ryan4yin/nix-config/v0.0.2](https://github.com/ryan4yin/nix-config
└── wallpaper.jpg # wallpaper
```
For more details, you can refer to the [ryan4yin/nix-config/v0.0.2](https://github.com/ryan4yin/nix-config/tree/v0.0.2) repository.
There is no need to follow the above structure, you can organize your configuration in any way you like. The key is to use `imports` to import all the submodules into the main module.
## `lib.mkOverride`, `lib.mkDefault`, and `lib.mkForce`

View file

@ -30,7 +30,11 @@ $ tree
我们可以借助 `imports` 参数,将 `home.nix``configuration.nix` 拆分成多个 `.nix` 文件。
比如我之前的 i3wm 系统配置 [ryan4yin/nix-config/v0.0.2](https://github.com/ryan4yin/nix-config/tree/v0.0.2),结构如下:
推荐一个非常好的模块化配置的例子,可以参考一下:
- [Misterio77/nix-starter-configs](https://github.com/Misterio77/nix-starter-configs)
再举个更复杂一点的例子,如下是我之前 i3wm 配置的目录结构 [ryan4yin/nix-config/v0.0.2](https://github.com/ryan4yin/nix-config/tree/v0.0.2)
```shell
├── flake.lock
@ -85,7 +89,7 @@ $ tree
└── wallpaper.jpg # 桌面壁纸,在 i3wm 配置中被引用
```
详细结构与内容,请移步前面提供的 github 仓库链接,这里就不多介绍了
Nix Flakes 对目录结构没有任何要求,你可以参考上面的例子,摸索出适合你自己的目录结构。其中关键点就是通过 `imports` 参数导入其他 `.nix` 文件
## `lib.mkOverride`, `lib.mkDefault` and `lib.mkForce`
@ -251,3 +255,4 @@ nix-repl> outputs.nixosConfigurations.nixos-test.config.environment.systemPackag
- [Nix modules: Improving Nix's discoverability and usability ](https://cfp.nixcon.org/nixcon2020/talk/K89WJY/)
- [Module System - Nixpkgs](https://github.com/NixOS/nixpkgs/blob/nixos-unstable/doc/module-system/module-system.chapter.md)
- [Misterio77/nix-starter-configs](https://github.com/Misterio77/nix-starter-configs)