mirror of
https://github.com/thegeneralist01/config.git
synced 2026-03-07 10:59:55 +01:00
5.7 KiB
5.7 KiB
AGENTS.md - AI Assistant Context
This file provides context for AI assistants working with thegeneralist's Nix configuration.
Quick Commands
Build & Deploy Commands
# Build specific host
nixos-rebuild switch --flake .#<hostname> # Linux
darwin-rebuild switch --flake .#<hostname> # macOS
# Update flake dependencies
nix flake update
# Check configuration validity
nix flake check
# Format Nix files
nixpkgs-fmt **/*.nix
# Clean up old generations
nh clean all --keep 3 --keep-since 4d
Development Commands
# Enter dev shell with tools
nix develop
# Edit secrets
agenix -e <secret-name>.age
# Re-encrypt all secrets
agenix -r
Architecture Overview
File Structure Conventions
flake.nix- Main entry point, defines inputs/outputshosts/- Host-specific configurations- Each host has
default.nixthat callslib.mkSystem configuration.nixcontains host-specific settings
- Each host has
modules/- Reusable system modulescommon/- Cross-platform modules (always loaded)darwin/- macOS-specific moduleslinux/- Linux-specific modules
lib/- Custom library functionsmkSystem- Main system builder function
Host Naming & Categorization
- Hosts ending in
mbpor containingcentral-mbp→ Darwin - All others → NixOS
- Current hosts:
thegeneralist(NixOS)thegeneralist-central(NixOS)thegeneralist-mbp(Darwin)thegeneralist-central-mbp(Darwin)
Code Conventions
Nix Style Guidelines
- Use
nixpkgs-fmtfor formatting - Prefer explicit attribute sets over
withstatements - Use meaningful variable names
- Add comments for complex logic
Module Organization
# Standard module structure
{ config, lib, pkgs, ... }:
{
# Module configuration here
}
Host Configuration Pattern
# hosts/<hostname>/default.nix
lib: inputs: self: lib.mkSystem "<os>" ./configuration.nix
# hosts/<hostname>/configuration.nix
{ config, pkgs, ... }: {
# Host-specific settings
}
Common Modification Patterns
Adding a New Package
- System-wide: Add to appropriate
modules/*/packages.nix - User-specific: Add to home-manager config in host's
configuration.nix
Adding a New Module
- Create
.nixfile in appropriatemodules/subdirectory - Module is auto-discovered and loaded
Theme Defaults
modules/common/theme.nixdefines shared theme options used by multiple modules (e.g.,bat,ghostty)- Adjust
config.theme.*there or override per-host inhosts/<hostname>/configuration.nix
Adding a New Host
- Create
hosts/<hostname>/directory - Add
default.nixwith system type - Add
configuration.nixwith host settings - Optionally add
hardware-configuration.nix
Managing Secrets
- Define in
secrets.nixwith proper recipients - Reference as
config.age.secrets.<name>.path - Edit with
agenix -e <secret>.age
Key Features to Remember
Distributed Builds
thegeneralist-centralis the main build machine- Other hosts offload builds via SSH
- SSH keys and build users configured automatically
Binary Caches
- Personal:
cache.thegeneralist01.com - Community:
cache.garnix.io - Official:
cache.nixos.org
Home Manager Integration
- Configured via
modules/common/home-manager.nix - Per-host customization in host's
configuration.nix - Includes
nhtool for optimized rebuilds
Development Tools
- Development shell includes:
nil,nixpkgs-fmt,agenix - Custom options available via
lib.mkOption - Flake inputs follow nixpkgs for consistency
Rebuild Helper
rebuild.nuat repo root wrapsnhfor local/remote rebuilds- Shell alias
rebuildpoints to the script (defined inmodules/common/shell/aliases.nix)
Debugging Tips
Build Issues
- Check syntax:
nix flake check - Update dependencies:
nix flake update - Clear cache:
nix-collect-garbage -d - Verify module imports and paths
Secret Issues
- Check
keys.nixhas correct public keys - Verify secret recipient list in
secrets.nix - Re-encrypt if needed:
agenix -r
Module Not Loading
- Verify file is in correct
modules/subdirectory - Check file extension is
.nix - Ensure valid Nix syntax
Nushell Warnings
- Deprecated
get -iwarning from direnv integration is a short-term workaround inmodules/common/shell/direnv.nix(custom Nushell hook withget -oand HM integration disabled) until upstream home-manager updates.
Performance Optimizations
Recommended Practices
- Use distributed builds when available
- Leverage binary caches
- Regular garbage collection via
nh clean - Keep flake inputs updated but stable
Avoiding Rebuilds
- Prefer adding packages to existing modules over creating new ones
- Use overlays for package modifications
- Consider impact on all hosts when modifying common modules
Testing Strategy
Before Major Changes
- Test on single host first
- Verify flake builds:
nix flake check - Check that all hosts can still build
- Consider impact on secrets/distributed builds
Rollback Strategy
# System level rollback
nixos-rebuild switch --rollback
darwin-rebuild switch --rollback
# Or boot into previous generation from bootloader
User Preferences
Code Style
- Clean, readable Nix code
- Proper indentation and formatting
- Meaningful comments for complex logic
- Consistent naming conventions
Organization Preferences
- Modular approach over monolithic configs
- Platform-specific separation (darwin/linux/common)
- Host-specific customization in host directories
- Secrets properly encrypted and organized
This configuration emphasizes maintainability, security, and cross-platform consistency.