首页/ AI 技能 / @skilllib/skill-2014279423611056131
Skill站外收录 @skilllib/skill-2014279423611056131

naming

规范 Nix 代码中的命名与组织方式,统一变量用 camelCase、文件目录用 kebab-case、常量用 UPPER_CASE,并强制采用 cfg 配置路径模式,按功能分组属性,保持扁平化点号语法和结构清晰性。

0.0 (0) 530 次安装 原作者 编程导航
收录于 2026-01-22
效率工具 AI 技能

Skills.MD

# Naming Conventions ## Quick Reference | Element | Style | Examples | | ----------- | ---------- | ----------------------------------- | | Variables | camelCase | `cfg`, `userName`, `enableFeature` | | Files/dirs | kebab-case | `my-module.nix`, `window-managers/` | | Constants | UPPER_CASE | `MAX_RETRIES`, `DEFAULT_PORT` | | Cfg pattern | Always use | `cfg = config.namespace.module;` | ## Variables ```nix let # Correct - camelCase userName = "khaneliman"; serverHostname = "myserver"; enableAutoStart = true; # Wrong user_name = "..."; # snake_case UserName = "..."; # PascalCase in ``` ## The cfg Pattern Always use this pattern: ```nix let cfg = config.khanelinix.programs.myApp; in { config = lib.mkIf cfg.enable { ... }; } ``` ## File Naming ``` # Correct - kebab-case modules/home/programs/my-app/default.nix modules/nixos/services/my-service.nix # Wrong modules/home/programs/myApp/default.nix # camelCase modules/nixos/services/my_service.nix # snake_case ``` ## Attribute Organization Group by function, then alphabetical: ```nix { # Options first options.namespace.module = { ... }; # Config second config = { # Group related settings programs.git = { ... }; programs.vim = { ... }; # Then packages home.packages = [ ... ]; }; } ``` ## Formatting - Use `nixfmt` for consistent formatting - Prefer flat dot-notation: `services.nginx.enable = true` - Avoid deep nesting when flat works

评论 0

还没有评论,来抢沙发。