7.5 KiB
AGENTS.md - Arch Linux Configuration Repository
Project Overview
This is a declarative Arch Linux configuration repository managed by dcli (Declarative CLI for Arch). The project uses YAML-based configuration files to manage packages, modules, and system files across different hosts.
Primary Tool: dcli - Declarative package and configuration manager for Arch Linux
Target Environment: Arch Linux (primarily WSL, but supports bare metal)
Language: Shell scripts (Bash), YAML configuration files
Repository Structure
.
├── config.yaml # Main config (specifies active host)
├── hosts/ # Host-specific configurations
│ └── wsl.yaml # WSL host config (enabled modules, AUR helper)
├── modules/ # Modular package definitions
│ ├── base.yaml # Core utilities (git, neovim, ripgrep, etc.)
│ ├── dev-tools.yaml # Development tools (nodejs, bun, mise)
│ └── zsh/ # Zsh module with dotfiles
│ ├── module.yaml
│ └── packages.yaml
├── files/ # System configuration files to sync
│ └── etc/ # Files that go to /etc
├── scripts/ # Installation and setup scripts
│ ├── install.sh # Main installation script
│ └── wsl-init.sh # WSL-specific initialization
└── state/ # dcli state directory (auto-generated)
Build/Test/Sync Commands
Primary Commands
# Apply configuration (install/update packages, sync files)
dcli sync
# Check what would change without applying
dcli sync --dry-run
# Update configuration from git
cd ~/.config/arch-config && git pull && dcli sync
Installation Commands
# WSL first-time setup (as root)
curl -fsSL https://git.furtherverse.com/imbytecat/archlinux-config/raw/branch/main/scripts/wsl-init.sh | bash -s -- <username>
# Install dcli and clone config (as regular user)
curl -fsSL https://git.furtherverse.com/imbytecat/archlinux-config/raw/branch/main/scripts/install.sh | bash
# Then sync configuration
dcli sync
Testing Scripts
# Test shell scripts for syntax errors
bash -n scripts/install.sh
bash -n scripts/wsl-init.sh
# Run shellcheck if available
shellcheck scripts/*.sh
Package Management
# Install packages manually (if needed)
sudo pacman -S <package> # Official repos
yay -S <package> # AUR packages
# Update system
sudo pacman -Syu
Code Style Guidelines
Shell Scripts
Shebang & Options:
- Always use
#!/bin/bash(not#!/bin/sh) - Start with
set -euo pipefailfor safety - Exit on errors, undefined variables, and pipe failures
Error Handling:
- Check command success with
if ! command; then - Validate user input before proceeding
- Provide clear error messages in Chinese (matching project language)
- Exit with non-zero status on errors
Variables:
- Use
UPPERCASEfor constants and environment variables - Use
lowercasefor local variables - Always quote variables:
"$VAR"not$VAR - Use
${VAR}for clarity when needed
Conditionals:
- Prefer
[[ ]]over[ ]for tests - Use
&> /dev/nullfor suppressing output - Check file existence:
if [ -e "$FILE" ]; then - Check command existence:
if command -v cmd &> /dev/null; then
User Feedback:
- Use
echo "==> Action..."for major steps - Use Chinese for user-facing messages
- Show clear success indicators:
✓ - Provide next steps after completion
Example Pattern:
#!/bin/bash
set -euo pipefail
USERNAME="${1:-}"
if [ -z "$USERNAME" ]; then
echo "用法: script.sh <参数>"
exit 1
fi
echo "==> 执行操作..."
if ! some_command; then
echo "错误:操作失败"
exit 1
fi
echo "✓ 完成!"
YAML Configuration Files
Structure:
- Use
---document separator at the start - Use 2-space indentation (no tabs)
- Keep files minimal and focused
Module Files (modules/*.yaml):
---
description: 模块描述
packages:
- package-name
- another-package
Module with Dotfiles (modules/*/module.yaml):
---
description: 模块描述
dotfiles:
- source: dotfiles/.config/file
target: ~/.config/file
Host Files (hosts/*.yaml):
host: hostname
aur_helper: yay
auto_prune: true
enabled_modules:
- base
- module-name
system_backups:
enabled: false
Main Config (config.yaml):
host: hostname
Naming Conventions:
- Use lowercase with hyphens for module names:
dev-tools, notDevTools - Use descriptive names in Chinese for descriptions
- Keep package lists alphabetically sorted
File Organization
Adding New Modules:
- Create
modules/module-name.yamlwith package list - Add module to
hosts/*.yamlunderenabled_modules - Run
dcli syncto apply
Adding Dotfiles:
- Create
modules/module-name/dotfiles/directory - Add dotfile mapping in
modules/module-name/module.yaml - Place actual dotfiles in the dotfiles subdirectory
Adding System Files:
- Place files in
files/matching target path structure - Example:
files/etc/pacman.d/mirrorlist→/etc/pacman.d/mirrorlist - Scripts handle copying with proper permissions
Git Workflow
Commit Messages:
- Follow commitlint conventional commits format
- Use Chinese for commit messages (matching project language)
- Format:
<type>(<scope>): <subject> - Types:
feat,fix,docs,style,refactor,test,chore - Examples:
feat(modules): 添加开发工具模块fix(scripts): 更新 WSL 初始化脚本docs: 更新 README 说明chore(deps): 更新包列表
Branching:
- Main branch:
main - Work directly on main for personal config repos
- Test changes with
dcli sync --dry-runbefore committing
Important Notes for Agents
-
dcli is the source of truth: Don't manually install packages. Add them to module YAML files and run
dcli sync. -
Host-specific configuration: The active host is defined in
config.yaml. Different hosts can have different enabled modules. -
AUR packages: This repo uses
yayas the AUR helper. Both official and AUR packages go in the samepackages:list. -
WSL-specific: The default configuration targets WSL. For bare metal, create a new host file and switch
config.yaml. -
File syncing: Files in
files/are copied to system locations. Maintain the directory structure matching the target paths. -
No tests: This is a configuration repository. Testing is done via
dcli sync --dry-runand manual verification. -
Language: User-facing messages and documentation are in Chinese. Keep this consistent.
-
Safety first: Scripts use
set -euo pipefailand validate inputs. Maintain this pattern. -
Idempotency: Scripts should be safe to run multiple times. Check if resources exist before creating.
-
State management: The
state/directory is managed by dcli. Don't modify it manually.
Common Tasks
Add a new package:
- Edit appropriate module YAML file
- Add package name to
packages:list - Run
dcli sync
Create a new module:
- Create
modules/new-module.yaml - Add packages and optional dotfiles config
- Enable in
hosts/*.yaml - Run
dcli sync
Update system configuration file:
- Edit file in
files/directory - Run install script or manually copy to system location
- Restart affected services if needed
Switch to a different host:
- Create
hosts/new-host.yamlif needed - Edit
config.yamlto changehost:value - Run
dcli sync