Skip to content

Snowveil基于目录约定的 NixOS 配置框架

按约定扫描 hosts/、homes/ 和 modules/,生成对应的 Flake outputs。

手写装配与目录约定 ​

手写配置Snowveil 配置
nix
nixosConfigurations.desktop =
  nixpkgs.lib.nixosSystem {
    modules = [
      ./hosts/desktop
      ./modules/common.nix
      ./modules/desktop.nix
    ];
  };
text
hosts/
└── desktop/
    ├── default.nix
    └── meta.nix
modules/
├── _common/
└── desktop/
homes/
└── rhen/
    └── desktop.nix

Snowveil 扫描目录并组装模块;NixOS 和 Home Manager 继续处理模块求值。

文件扫描与模块求值 ​

text
                         Snowveil
                            │
                ┌───────────┴───────────┐
                │                       │
            Discovery               Composition
                │                       │
        ┌───────┼────────┐              │
        ▼       ▼        ▼              ▼
      hosts/  users/  modules/    Nix module system
        │       │        │              │
        ▼       ▼        ▼              │
      Host    User    Feature            │
        │       │        │              │
        └───────┴────────┴──────────────┘
                            │
                            ▼
             nixosConfigurations / homeConfigurations
             packages / apps / devShells / checks

文件扫描读取目录和 meta.nix;随后 Snowveil 按规则选择模块,并交给 NixOS 和 Home Manager。它不改变 option merge、mkIf、mkDefault 或系统配置的求值方式。

Snowveil 与 Nix 模块系统 ​

SnowveilNix 模块系统
扫描目录求值模块
读取 magic 文件和 meta.nix合并 options
生成 outputs处理 mkIf、mkDefault
区分 NixOS 与 Home Manager 模块解析模块依赖
传入模块求值最终配置

目录和 outputs ​

text
                              Snowveil
                                 │
                         文件系统扫描
                                 │
              ┌──────────────────┼──────────────────┐
              ▼                  ▼                  ▼
           hosts/             modules/            homes/
              │                  │                  │
              ▼                  ▼                  ▼
           NixOS              模块集合         Home Manager
              │                  │                  │
              └──────────────────┼──────────────────┘
                                 ▼
                            Flake outputs
                         ┌───────┴────────┐
                         ▼                ▼
              nixosConfigurations  homeConfigurations

可查看仓库中的示例项目,也可以直接阅读从普通 flake 迁移。

MIT 许可发布