This document provides guidelines for working with code in this repository. Following these conventions ensures consistency and maintainability across the codebase.
This is a NixOS configuration repository that manages multiple machines and custom packages using Nix flakes. It provides a declarative and reproducible way to manage systems. The repository acts as a centralized configuration system, enabling consistent environment setups across different hosts.
The repository is organized into several key directories:
- hosts/: Contains machine-specific configurations organized by architecture (x86_64-linux, aarch64-darwin)
- profiles/: Reusable configuration templates for different system types (desktop, server, laptop, workstation)
- modules/: Core system functionality modules (networking, services, authentication)
- secrets/: Encrypted configuration files managed with agenix
- flake/: Components of the flake configuration (packages, hosts, devenv)
- users/: User-specific configurations using home-manager
- packages/: Custom package definitions not yet in nixpkgs
The repository includes a custom world command (accessible through a wrapped Justfile) that provides various utilities:
# Update existing system from GitHub
nixos-rebuild switch --flake github:johnae/world --use-remote-sudo
# Update from local clone
nixos-rebuild switch --flake . --use-remote-sudo
# Upgrade the system (Linux)
world upgrade [flake_ref]
# Upgrade the system (macOS)
world upgrade [flake_ref]
# Build without applying (Linux)
world build [flake_ref]
# Build without applying (macOS)
world build [flake_ref]
# Search for packages
world search <query>
# Open a shell with packages available
world shell <packages>
# Garbage collect
world gc# Format disk and install
nix build .#<hostname>-diskformat
./result/bin/diskformat
nixos-rebuild switch --flake .#<hostname> --no-root-passwd# Lint the codebase
world lint
# Check for dead code
world dead
# Check flake for old inputs
world dscheck
# Run flake checks
world checkThe configuration follows a hierarchical approach:
- Base System: Defined in
profiles/defaults.nix, setting up core packages and configs - Profile Layer: Specialized templates like server, desktop, laptop in the
profiles/directory - Host-specific config: Individual machine configurations in
hosts/directory - User Configurations: User-specific settings managed through home-manager
Secrets are managed using agenix (age-encrypted secrets) stored in the secrets/ directory. The secrets are decrypted during system activation.
To add a new machine:
- Create a configuration file in the relevant architecture folder under
hosts/ - Reference appropriate profiles for the machine type
- Define machine-specific configuration
- Build and install using the commands above
- Minimize modifications: Always prefer editing existing files over creating new ones
- Use profiles: Prefer using existing profiles over adding host-specific configuration
- Follow patterns: When adding new components, examine existing ones for patterns and conventions
- Test changes: Use the built-in
worldcommands to verify changes before committing - Documentation: Only create documentation when it adds significant value to the project
- Formatting: Use Alejandra for Nix files, fnlfmt for Fennel files, stylua for Lua files
- Naming: Follow existing patterns in similar files/directories
- Imports: Group imports logically by functionality
- Error Handling: Use appropriate Nix error handling patterns
- Commits: Follow conventional commit format ("feat:", "fix:", "chore:", etc.)
Always run linting etc before committing: world lint && world dead && world dscheck
- Always check which host configuration you're modifying
- Use the built-in
worldcommands for common operations - When adding new packages, check if they should be added to a specific profile or globally
- Keep changes focused and minimal - do what needs to be done, nothing more
The repository uses CI (buildkite) for automated updates. Updates create pull requests where all custom packages and machine configurations are built and tested before merging.
For more information, consult:
- The README.md file for project overview
- The Justfile (
files/Justfile) for available commands - Documentation for NixOS, Nix flakes, and flake-parts