new stuff
This commit is contained in:
parent
6014ad7d7a
commit
01c8bfce80
18 changed files with 721 additions and 285 deletions
194
AGENTS.md
Normal file
194
AGENTS.md
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
# AGENTS.md - AI Assistant Context
|
||||
|
||||
This file provides context for AI assistants working with thegeneralist's Nix configuration.
|
||||
|
||||
## Quick Commands
|
||||
|
||||
### Build & Deploy Commands
|
||||
```bash
|
||||
# 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
|
||||
```bash
|
||||
# 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/outputs
|
||||
- **`hosts/`** - Host-specific configurations
|
||||
- Each host has `default.nix` that calls `lib.mkSystem`
|
||||
- `configuration.nix` contains host-specific settings
|
||||
- **`modules/`** - Reusable system modules
|
||||
- `common/` - Cross-platform modules (always loaded)
|
||||
- `darwin/` - macOS-specific modules
|
||||
- `linux/` - Linux-specific modules
|
||||
- **`lib/`** - Custom library functions
|
||||
- `mkSystem` - Main system builder function
|
||||
|
||||
### Host Naming & Categorization
|
||||
- Hosts ending in `mbp` or containing `central-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-fmt` for formatting
|
||||
- Prefer explicit attribute sets over `with` statements
|
||||
- Use meaningful variable names
|
||||
- Add comments for complex logic
|
||||
|
||||
### Module Organization
|
||||
```nix
|
||||
# Standard module structure
|
||||
{ config, lib, pkgs, ... }:
|
||||
{
|
||||
# Module configuration here
|
||||
}
|
||||
```
|
||||
|
||||
### Host Configuration Pattern
|
||||
```nix
|
||||
# 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
|
||||
1. **System-wide**: Add to appropriate `modules/*/packages.nix`
|
||||
2. **User-specific**: Add to home-manager config in host's `configuration.nix`
|
||||
|
||||
### Adding a New Module
|
||||
1. Create `.nix` file in appropriate `modules/` subdirectory
|
||||
2. Module is auto-discovered and loaded
|
||||
|
||||
### Adding a New Host
|
||||
1. Create `hosts/<hostname>/` directory
|
||||
2. Add `default.nix` with system type
|
||||
3. Add `configuration.nix` with host settings
|
||||
4. Optionally add `hardware-configuration.nix`
|
||||
|
||||
### Managing Secrets
|
||||
1. Define in `secrets.nix` with proper recipients
|
||||
2. Reference as `config.age.secrets.<name>.path`
|
||||
3. Edit with `agenix -e <secret>.age`
|
||||
|
||||
## Key Features to Remember
|
||||
|
||||
### Distributed Builds
|
||||
- `thegeneralist-central` is 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 `nh` tool for optimized rebuilds
|
||||
|
||||
### Development Tools
|
||||
- Development shell includes: `nil`, `nixpkgs-fmt`, `agenix`
|
||||
- Custom options available via `lib.mkOption`
|
||||
- Flake inputs follow nixpkgs for consistency
|
||||
|
||||
## Debugging Tips
|
||||
|
||||
### Build Issues
|
||||
1. Check syntax: `nix flake check`
|
||||
2. Update dependencies: `nix flake update`
|
||||
3. Clear cache: `nix-collect-garbage -d`
|
||||
4. Verify module imports and paths
|
||||
|
||||
### Secret Issues
|
||||
1. Check `keys.nix` has correct public keys
|
||||
2. Verify secret recipient list in `secrets.nix`
|
||||
3. Re-encrypt if needed: `agenix -r`
|
||||
|
||||
### Module Not Loading
|
||||
1. Verify file is in correct `modules/` subdirectory
|
||||
2. Check file extension is `.nix`
|
||||
3. Ensure valid Nix syntax
|
||||
|
||||
## 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
|
||||
1. Test on single host first
|
||||
2. Verify flake builds: `nix flake check`
|
||||
3. Check that all hosts can still build
|
||||
4. Consider impact on secrets/distributed builds
|
||||
|
||||
### Rollback Strategy
|
||||
```bash
|
||||
# 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.
|
||||
248
docs/README.md
248
docs/README.md
|
|
@ -1,2 +1,246 @@
|
|||
# config
|
||||
My Nix flake and dotfiles
|
||||
# thegeneralist's Nix Configuration
|
||||
|
||||
A comprehensive Nix flake configuration supporting both NixOS (Linux) and nix-darwin (macOS) systems with home-manager integration.
|
||||
|
||||
## Overview
|
||||
|
||||
This configuration provides a unified way to manage multiple machines across different platforms:
|
||||
- **NixOS hosts**: `thegeneralist`, `thegeneralist-central`
|
||||
- **Darwin hosts**: `thegeneralist-mbp`, `thegeneralist-central-mbp`
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Prerequisites
|
||||
- Nix package manager with flakes enabled
|
||||
- Git for cloning the repository
|
||||
|
||||
### Installation
|
||||
|
||||
1. Clone the repository:
|
||||
```bash
|
||||
git clone https://github.com/thegeneralist01/config.git ~/config
|
||||
cd ~/config
|
||||
```
|
||||
|
||||
2. For NixOS systems:
|
||||
```bash
|
||||
sudo nixos-rebuild switch --flake .#<hostname>
|
||||
```
|
||||
|
||||
3. For Darwin systems:
|
||||
```bash
|
||||
darwin-rebuild switch --flake .#<hostname>
|
||||
```
|
||||
|
||||
### Development Environment
|
||||
|
||||
Enter the development shell for configuration management:
|
||||
```bash
|
||||
nix develop
|
||||
```
|
||||
|
||||
This provides:
|
||||
- `nil` - Nix language server
|
||||
- `nixpkgs-fmt` - Nix formatter
|
||||
- `agenix` - Secret management
|
||||
|
||||
## Architecture
|
||||
|
||||
### Directory Structure
|
||||
|
||||
```
|
||||
├── docs/ # Documentation
|
||||
├── flake.nix # Main flake configuration
|
||||
├── flake.lock # Locked dependency versions
|
||||
├── hosts/ # Host-specific configurations
|
||||
│ ├── default.nix # Host discovery and categorization
|
||||
│ └── <hostname>/ # Individual host configurations
|
||||
├── lib/ # Custom library functions
|
||||
│ ├── default.nix # Library entry point
|
||||
│ ├── option.nix # Option utilities
|
||||
│ └── system.nix # System building functions
|
||||
├── modules/ # Reusable system modules
|
||||
│ ├── common/ # Cross-platform modules
|
||||
│ ├── darwin/ # macOS-specific modules
|
||||
│ └── linux/ # Linux-specific modules
|
||||
├── keys.nix # Age public keys for secrets
|
||||
└── secrets.nix # Encrypted secrets
|
||||
```
|
||||
|
||||
### Key Components
|
||||
|
||||
#### Flake Inputs
|
||||
- **nixpkgs**: Main package repository (nixos-unstable)
|
||||
- **home-manager**: Dotfiles and user environment management
|
||||
- **nix-darwin**: macOS system configuration
|
||||
- **agenix**: Age-based secret management
|
||||
- **ghostty**: Modern terminal emulator
|
||||
- **fenix**: Rust toolchain provider
|
||||
|
||||
#### Library Functions
|
||||
- `mkSystem`: Core system builder for both Linux and Darwin
|
||||
- `mkOption`: Custom option utilities
|
||||
- Host auto-discovery and categorization
|
||||
|
||||
## Host Configuration
|
||||
|
||||
### Adding a New Host
|
||||
|
||||
1. Create a new directory under `hosts/`:
|
||||
```bash
|
||||
mkdir hosts/new-hostname
|
||||
```
|
||||
|
||||
2. Create the host's `default.nix`:
|
||||
```nix
|
||||
lib: inputs: self: lib.mkSystem "linux" ./configuration.nix
|
||||
# or for macOS:
|
||||
lib: inputs: self: lib.mkSystem "darwin" ./configuration.nix
|
||||
```
|
||||
|
||||
3. Create `configuration.nix` with your host-specific settings:
|
||||
```nix
|
||||
{ config, pkgs, ... }: {
|
||||
# Host-specific configuration here
|
||||
}
|
||||
```
|
||||
|
||||
4. Rebuild your flake:
|
||||
```bash
|
||||
nix flake lock # Update lock file if needed
|
||||
nixos-rebuild switch --flake .#new-hostname
|
||||
```
|
||||
|
||||
### Host Categorization
|
||||
|
||||
Hosts are automatically categorized based on naming conventions:
|
||||
- Names ending with `mbp` or containing `central-mbp` → Darwin
|
||||
- All others → NixOS
|
||||
|
||||
## Module System
|
||||
|
||||
### Common Modules
|
||||
Located in `modules/common/`, these are loaded on all systems:
|
||||
- `nix.nix` - Nix configuration, caches, and distributed builds
|
||||
- `home-manager.nix` - User environment management
|
||||
- `packages.nix` - Common packages
|
||||
- `git.nix`, `neovim.nix`, `zsh.nix` - Development tools
|
||||
- `agenix.nix` - Secret management
|
||||
|
||||
### Platform-Specific Modules
|
||||
- `modules/darwin/` - macOS-specific (SSH, Karabiner, packages)
|
||||
- `modules/linux/` - Linux-specific (boot, networking, X11, NVIDIA)
|
||||
|
||||
### Creating Custom Modules
|
||||
|
||||
1. Add your module to the appropriate directory:
|
||||
```nix
|
||||
# modules/common/mymodule.nix
|
||||
{ config, pkgs, ... }: {
|
||||
# Module configuration
|
||||
}
|
||||
```
|
||||
|
||||
2. The module is automatically discovered and loaded
|
||||
|
||||
## Secret Management
|
||||
|
||||
Uses `agenix` for encrypted secrets management:
|
||||
|
||||
1. Add recipient public keys to [`keys.nix`](file:///Users/thegeneralist/misc/config-copy/keys.nix)
|
||||
2. Define secrets in [`secrets.nix`](file:///Users/thegeneralist/misc/config-copy/secrets.nix)
|
||||
3. Edit secrets: `agenix -e secret-name.age`
|
||||
4. Reference in configuration: `config.age.secrets.secret-name.path`
|
||||
|
||||
## Distributed Builds
|
||||
|
||||
The configuration includes distributed build support:
|
||||
- `thegeneralist-central` serves as the build machine
|
||||
- Other hosts can offload builds via SSH
|
||||
- Shared binary caches for faster builds
|
||||
|
||||
## Binary Caches
|
||||
|
||||
Configured caches for improved build performance:
|
||||
- `cache.thegeneralist01.com` - Personal cache
|
||||
- `cache.garnix.io` - Community cache
|
||||
- `cache.nixos.org` - Official cache
|
||||
|
||||
## Development Workflow
|
||||
|
||||
### Updating Dependencies
|
||||
```bash
|
||||
nix flake update
|
||||
```
|
||||
|
||||
### Formatting Code
|
||||
```bash
|
||||
nixpkgs-fmt **/*.nix
|
||||
```
|
||||
|
||||
### Checking Configuration
|
||||
```bash
|
||||
nix flake check
|
||||
```
|
||||
|
||||
### Cleaning Up
|
||||
```bash
|
||||
# Via nh (configured in home-manager)
|
||||
nh clean all --keep 3 --keep-since 4d
|
||||
|
||||
# Manual cleanup
|
||||
nix-collect-garbage -d
|
||||
```
|
||||
|
||||
## Common Tasks
|
||||
|
||||
### Installing Packages System-wide
|
||||
Add to the appropriate `modules/*/packages.nix` file.
|
||||
|
||||
### Installing User Packages
|
||||
Modify the home-manager configuration in your host's `configuration.nix`.
|
||||
|
||||
### Updating a Single Host
|
||||
```bash
|
||||
nixos-rebuild switch --flake .#hostname
|
||||
# or
|
||||
darwin-rebuild switch --flake .#hostname
|
||||
```
|
||||
|
||||
### Rolling Back Changes
|
||||
```bash
|
||||
nixos-rebuild switch --rollback
|
||||
# or
|
||||
darwin-rebuild switch --rollback
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Build Failures
|
||||
1. Check flake lock compatibility: `nix flake update`
|
||||
2. Clear build cache: `nix-collect-garbage -d`
|
||||
3. Verify module syntax: `nix flake check`
|
||||
|
||||
### Secret Access Issues
|
||||
1. Verify keys are properly configured in `keys.nix`
|
||||
2. Re-encrypt secrets: `agenix -r`
|
||||
3. Check file permissions on age keys
|
||||
|
||||
### Performance Issues
|
||||
1. Enable distributed builds to `thegeneralist-central`
|
||||
2. Verify binary cache access
|
||||
3. Use `nh` for optimized rebuilds
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Follow existing code style and organization
|
||||
2. Test changes on a single host before applying broadly
|
||||
3. Update documentation for significant changes
|
||||
4. Use meaningful commit messages
|
||||
|
||||
## References
|
||||
|
||||
- [NixOS Manual](https://nixos.org/manual/nixos/stable/)
|
||||
- [Nix-Darwin](https://github.com/nix-darwin/nix-darwin)
|
||||
- [Home Manager](https://nix-community.github.io/home-manager/)
|
||||
- [Agenix](https://github.com/ryantm/agenix)
|
||||
|
|
|
|||
147
flake.lock
generated
147
flake.lock
generated
|
|
@ -64,43 +64,6 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-compat_2": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1747046372,
|
||||
"narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=",
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-parts": {
|
||||
"inputs": {
|
||||
"nixpkgs-lib": [
|
||||
"nix",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1733312601,
|
||||
"narHash": "sha256-4pDvzqnegAfRkPwO3wmwBhVi/Sye1mzps0zHWYnP88c=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "205b12d8b7cd4802fbcb8e8ef6a0f1408781a4f9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems_2"
|
||||
|
|
@ -142,37 +105,6 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"git-hooks-nix": {
|
||||
"inputs": {
|
||||
"flake-compat": [
|
||||
"nix"
|
||||
],
|
||||
"gitignore": [
|
||||
"nix"
|
||||
],
|
||||
"nixpkgs": [
|
||||
"nix",
|
||||
"nixpkgs"
|
||||
],
|
||||
"nixpkgs-stable": [
|
||||
"nix",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1734279981,
|
||||
"narHash": "sha256-NdaCraHPp8iYMWzdXAt5Nv6sA3MUzlCiGiR586TCwo0=",
|
||||
"owner": "cachix",
|
||||
"repo": "git-hooks.nix",
|
||||
"rev": "aa9f40c906904ebd83da78e7f328cd8aeaeae785",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"repo": "git-hooks.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"home-manager": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
|
|
@ -193,28 +125,6 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nix": {
|
||||
"inputs": {
|
||||
"flake-compat": "flake-compat_2",
|
||||
"flake-parts": "flake-parts",
|
||||
"git-hooks-nix": "git-hooks-nix",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"nixpkgs-23-11": "nixpkgs-23-11",
|
||||
"nixpkgs-regression": "nixpkgs-regression"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1748188105,
|
||||
"narHash": "sha256-skPu7lTZrTr6gShsN47IGPUX4+Y0CbI2gl8tG3Dh7hM=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nix",
|
||||
"rev": "543cee1c9272238f9402e5643402b99f952415c3",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nix",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"nix-darwin": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
|
|
@ -238,11 +148,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1747179050,
|
||||
"narHash": "sha256-qhFMmDkeJX9KJwr5H32f1r7Prs7XbQWtO0h3V0a0rFY=",
|
||||
"lastModified": 1755186698,
|
||||
"narHash": "sha256-wNO3+Ks2jZJ4nTHMuks+cxAiVBGNuEBXsT29Bz6HASo=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "adaa24fbf46737f3f1b5497bf64bae750f82942e",
|
||||
"rev": "fbcf476f790d8a217c3eab4e12033dc4a0f6d23c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
@ -252,38 +162,6 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-23-11": {
|
||||
"locked": {
|
||||
"lastModified": 1717159533,
|
||||
"narHash": "sha256-oamiKNfr2MS6yH64rUn99mIZjc45nGJlj9eGth/3Xuw=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "a62e6edd6d5e1fa0329b8653c801147986f8d446",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "a62e6edd6d5e1fa0329b8653c801147986f8d446",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-regression": {
|
||||
"locked": {
|
||||
"lastModified": 1643052045,
|
||||
"narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-stable": {
|
||||
"locked": {
|
||||
"lastModified": 1741992157,
|
||||
|
|
@ -316,31 +194,14 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1755186698,
|
||||
"narHash": "sha256-wNO3+Ks2jZJ4nTHMuks+cxAiVBGNuEBXsT29Bz6HASo=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "fbcf476f790d8a217c3eab4e12033dc4a0f6d23c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"agenix": "agenix",
|
||||
"fenix": "fenix",
|
||||
"ghostty": "ghostty",
|
||||
"home-manager": "home-manager",
|
||||
"nix": "nix",
|
||||
"nix-darwin": "nix-darwin",
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"rust-analyzer-src": {
|
||||
|
|
|
|||
53
flake.nix
53
flake.nix
|
|
@ -1,48 +1,65 @@
|
|||
{
|
||||
{
|
||||
description = "thegeneralist's config flake";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
|
||||
home-manager = {
|
||||
url = "github:nix-community/home-manager";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
nix-darwin = {
|
||||
url = "github:nix-darwin/nix-darwin/master";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
agenix = {
|
||||
url = "github:ryantm/agenix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
inputs.home-manager.follows = "home-manager";
|
||||
inputs.darwin.follows = "nix-darwin";
|
||||
};
|
||||
|
||||
ghostty = {
|
||||
url = "github:ghostty-org/ghostty";
|
||||
};
|
||||
|
||||
fenix = {
|
||||
url = "github:nix-community/fenix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
#nix.url = "github:DeterminateSystems/nix-src";
|
||||
};
|
||||
|
||||
outputs = inputs@{ self, nixpkgs, nix-darwin, nix, ... }: let
|
||||
inherit (builtins) readDir;
|
||||
inherit (nixpkgs.lib) attrsToList const groupBy listToAttrs mapAttrs;
|
||||
#nix.enable = false;
|
||||
outputs = inputs@{ self, nixpkgs, nix-darwin, ... }:
|
||||
let
|
||||
# Extend nixpkgs lib with darwin and custom functions
|
||||
lib = nixpkgs.lib.extend (
|
||||
_: _: nix-darwin.lib // (import ./lib inputs)
|
||||
);
|
||||
|
||||
lib' = nixpkgs.lib.extend (_: _: nix-darwin.lib);
|
||||
lib = lib'.extend <| import ./lib inputs;
|
||||
# Import host configurations
|
||||
hostConfigs = import ./hosts { inherit lib inputs self; };
|
||||
in
|
||||
{
|
||||
# NixOS configurations for Linux hosts
|
||||
nixosConfigurations = hostConfigs.nixos or {};
|
||||
|
||||
targetHost = readDir ./hosts
|
||||
|> mapAttrs (name: const <| import ./hosts/${name} lib inputs self)
|
||||
|> attrsToList
|
||||
|> groupBy (host:
|
||||
if host.name == "thegeneralist" || host.name == "thegeneralist-central" then
|
||||
"nixosConfigurations"
|
||||
else
|
||||
"darwinConfigurations")
|
||||
|> mapAttrs (const listToAttrs);
|
||||
in targetHost;
|
||||
# Darwin configurations for macOS hosts
|
||||
darwinConfigurations = hostConfigs.darwin or {};
|
||||
|
||||
# Development shells
|
||||
devShells = lib.genAttrs [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ] (system:
|
||||
let pkgs = nixpkgs.legacyPackages.${system};
|
||||
in {
|
||||
default = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
nil
|
||||
nixpkgs-fmt
|
||||
inputs.agenix.packages.${system}.default
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
33
hosts/default.nix
Normal file
33
hosts/default.nix
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
{ lib, inputs, self }:
|
||||
let
|
||||
inherit (lib)
|
||||
mapAttrs filterAttrs hasPrefix hasSuffix;
|
||||
|
||||
# Read host directories
|
||||
hostDirs = builtins.readDir ./.;
|
||||
|
||||
# Build a single host configuration
|
||||
mkHostConfig = name: _type:
|
||||
let
|
||||
hostPath = ./${name};
|
||||
hostModule = import hostPath;
|
||||
in
|
||||
hostModule lib inputs self;
|
||||
|
||||
# Determine if host is Darwin or NixOS based on naming
|
||||
isDarwin = name:
|
||||
hasPrefix "thegeneralist" name &&
|
||||
(hasSuffix "mbp" name || hasSuffix "central-mbp" name);
|
||||
|
||||
# Build all host configurations
|
||||
allHosts = mapAttrs mkHostConfig
|
||||
(filterAttrs (_: type: type == "directory") hostDirs);
|
||||
|
||||
# Separate Darwin and NixOS configurations
|
||||
darwinHosts = filterAttrs (name: _: isDarwin name) allHosts;
|
||||
nixosHosts = filterAttrs (name: _: !isDarwin name) allHosts;
|
||||
in
|
||||
{
|
||||
darwin = darwinHosts;
|
||||
nixos = nixosHosts;
|
||||
}
|
||||
|
|
@ -1 +1 @@
|
|||
lib: inputs: self: lib.system "darwin" ./configuration.nix
|
||||
lib: inputs: self: lib.mkSystem "darwin" ./configuration.nix
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
lib: inputs: self: lib.system "linux" ./configuration.nix
|
||||
lib: inputs: self: lib.mkSystem "linux" ./configuration.nix
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
lib: inputs: self: lib.system "darwin" ./configuration.nix
|
||||
lib: inputs: self: lib.mkSystem "darwin" ./configuration.nix
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
lib: inputs: self: lib.system "linux" ./configuration.nix
|
||||
lib: inputs: self: lib.mkSystem "linux" ./configuration.nix
|
||||
|
|
|
|||
|
|
@ -1,6 +1,21 @@
|
|||
inputs: self: super:
|
||||
inputs:
|
||||
let
|
||||
system = import ./system.nix inputs self super;
|
||||
option = import ./option.nix inputs self super;
|
||||
inherit (inputs.nixpkgs.lib) makeExtensible;
|
||||
in
|
||||
system // option
|
||||
makeExtensible (self:
|
||||
let
|
||||
callLib = file: import file inputs self;
|
||||
optionUtils = callLib ./option.nix;
|
||||
in
|
||||
{
|
||||
# Core system building functions
|
||||
mkSystem = (callLib ./system.nix).mkSystem;
|
||||
|
||||
# Custom option utilities
|
||||
mkConst = optionUtils.mkConst;
|
||||
mkValue = optionUtils.mkValue;
|
||||
|
||||
# Host detection and configuration
|
||||
mkHosts = callLib ./hosts.nix;
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,66 +1,64 @@
|
|||
inputs: self: super:
|
||||
inputs: self:
|
||||
let
|
||||
inherit (self)
|
||||
hasSuffix
|
||||
filesystem
|
||||
attrValues
|
||||
filter
|
||||
getAttrFromPath
|
||||
hasAttrByPath
|
||||
;
|
||||
inherit (inputs.nixpkgs.lib)
|
||||
hasSuffix filesystem attrValues filter getAttrFromPath
|
||||
hasAttrByPath mapAttrsToList concatMap;
|
||||
|
||||
collectModules = path: filesystem.listFilesRecursive path |> filter (hasSuffix ".nix");
|
||||
# Helper to collect all .nix files recursively in a directory
|
||||
collectModules = path:
|
||||
if builtins.pathExists path
|
||||
then filter (hasSuffix ".nix") (filesystem.listFilesRecursive path)
|
||||
else [];
|
||||
|
||||
collectInputModules =
|
||||
packagePath:
|
||||
(attrValues inputs) |> filter (hasAttrByPath packagePath) |> map (getAttrFromPath packagePath);
|
||||
# Collect modules from flake inputs with fallback handling
|
||||
collectInputModules = packagePath:
|
||||
let
|
||||
getModule = input:
|
||||
if hasAttrByPath packagePath input
|
||||
then [ (getAttrFromPath packagePath input) ]
|
||||
else [];
|
||||
in
|
||||
concatMap getModule (attrValues inputs);
|
||||
|
||||
# Shared arguments for all configurations
|
||||
specialArgs = inputs // {
|
||||
inherit inputs;
|
||||
inherit self;
|
||||
inherit inputs self;
|
||||
};
|
||||
|
||||
# All modules
|
||||
# Collect platform-specific modules
|
||||
modulesCommon = collectModules ../modules/common;
|
||||
modulesLinux = collectModules ../modules/linux;
|
||||
modulesDarwin = collectModules ../modules/darwin;
|
||||
|
||||
inputModulesNixos = collectInputModules [
|
||||
"nixosModules"
|
||||
"default"
|
||||
];
|
||||
inputModulesDarwin = collectInputModules [
|
||||
"darwinModules"
|
||||
"default"
|
||||
];
|
||||
# Collect input modules by platform
|
||||
inputModulesNixos = collectInputModules [ "nixosModules" "default" ];
|
||||
inputModulesDarwin = collectInputModules [ "darwinModules" "default" ];
|
||||
|
||||
# Overlays
|
||||
overlays = collectInputModules [
|
||||
"overlays"
|
||||
"default"
|
||||
];
|
||||
# Collect overlays from inputs
|
||||
overlays = collectInputModules [ "overlays" "default" ];
|
||||
|
||||
overlayModules = {
|
||||
overlayModule = {
|
||||
nixpkgs.overlays = overlays;
|
||||
};
|
||||
in
|
||||
{
|
||||
system =
|
||||
os: configFile:
|
||||
(if os == "darwin" then
|
||||
super.darwinSystem
|
||||
else
|
||||
super.nixosSystem) {
|
||||
inherit specialArgs;
|
||||
# Main system builder function
|
||||
mkSystem = os: configFile:
|
||||
let
|
||||
systemBuilder = if os == "darwin"
|
||||
then inputs.nix-darwin.lib.darwinSystem
|
||||
else inputs.nixpkgs.lib.nixosSystem;
|
||||
|
||||
modules =
|
||||
[
|
||||
overlayModules
|
||||
configFile
|
||||
]
|
||||
++ modulesCommon
|
||||
++ (
|
||||
if os == "darwin" then modulesDarwin ++ inputModulesDarwin else modulesLinux ++ inputModulesNixos
|
||||
);
|
||||
};
|
||||
platformModules = if os == "darwin"
|
||||
then modulesDarwin ++ inputModulesDarwin
|
||||
else modulesLinux ++ inputModulesNixos;
|
||||
in
|
||||
systemBuilder {
|
||||
inherit specialArgs;
|
||||
|
||||
modules = [
|
||||
overlayModule
|
||||
configFile
|
||||
] ++ modulesCommon ++ platformModules;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
26
modules/common/amp.nix
Normal file
26
modules/common/amp.nix
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
let
|
||||
enableAmp = (!config.onLinux) || (!config.isServer);
|
||||
ampHomeModule = { lib, pkgs, ... }: {
|
||||
home.sessionPath = [ "$HOME/.amp/bin" ];
|
||||
home.activation.ampInstall = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
|
||||
amp_bin="$HOME/.amp/bin/amp"
|
||||
if [ -x "$amp_bin" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
export PATH="${lib.makeBinPath [
|
||||
pkgs.coreutils
|
||||
pkgs.gnugrep
|
||||
pkgs.curl
|
||||
pkgs.bash
|
||||
]}:$PATH"
|
||||
|
||||
# Prevent installer from trying to mutate shell rc files (Home Manager manages those).
|
||||
SHELL="amp-installer" ${pkgs.curl}/bin/curl -fsSL https://ampcode.com/install.sh | ${pkgs.bash}/bin/bash
|
||||
'';
|
||||
};
|
||||
in
|
||||
lib.mkIf enableAmp {
|
||||
home-manager.sharedModules = [ ampHomeModule ];
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ in {
|
|||
options.dnsServers = mkOption {
|
||||
default = [
|
||||
"100.100.100.100#shorthair-wall.ts.net"
|
||||
"1.1.1.1#"
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ in {
|
|||
builders-use-substitutes = true;
|
||||
};
|
||||
|
||||
nix.package = pkgs.nixVersions.nix_2_30;
|
||||
|
||||
nix.distributedBuilds = true;
|
||||
nix.buildMachines = if (config.networking.hostName != "thegeneralist-central") then [{
|
||||
hostName = "thegeneralist-central";
|
||||
|
|
|
|||
|
|
@ -71,6 +71,14 @@ alias rb = nh os switch . -v -- --show-trace --verbose
|
|||
def greeting [] {
|
||||
let quotes = [
|
||||
"What is impossible for you is not impossible for me."
|
||||
"Why do we fall, Master Wayne? So that we can learn to pick ourselves up. - Alfred Pennyworth"
|
||||
"Endure, Master Wayne. Take it. They’ll hate you for it, but that’s the point of Batman. He can be the outcast. He can make the choice… that no one else can make. The right choice. - Alfred Pennyworth"
|
||||
"— I never said thank you. — And you will never have to."
|
||||
"A hero can be anyone, even a man doing something as simple and reassuring as putting a coat on a young boy's shoulders to let him know that the world hadn't ended. - Batman"
|
||||
"— Come with me. Save yourself. You don't owe these ppl anymore, you've given them everything.\n —Not everything. Not yet."
|
||||
"The night is always darkest before the dawn, but I promise you, the dawn is coming. - Harvey Dent"
|
||||
"It's not who you are underneath, but what you do that defines you. - Batman"
|
||||
"The idea was to be a symbol. Batman... could be anybody. That was the point. - Bruce Wayne"
|
||||
]
|
||||
echo ($quotes | get (random int 0..(($quotes | length) - 1)))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,71 +1,106 @@
|
|||
{ config, pkgs, lib, ... }: let
|
||||
inherit (lib) readFile getExe mkIf optionalAttrs;
|
||||
in {
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib)
|
||||
readFile
|
||||
getExe
|
||||
mkAfter
|
||||
mkIf
|
||||
optionalAttrs
|
||||
;
|
||||
in
|
||||
{
|
||||
# TODO: starship + change the zoxide src
|
||||
# TODO: Rust tooling
|
||||
environment = optionalAttrs config.onLinux {
|
||||
sessionVariables.SHELLS = [ (getExe pkgs.nushell) (getExe pkgs.zsh) ];
|
||||
} // {
|
||||
shells = mkIf (!config.onLinux) [ pkgs.nushell pkgs.zsh ];
|
||||
environment =
|
||||
optionalAttrs config.onLinux {
|
||||
sessionVariables.SHELLS = [
|
||||
(getExe pkgs.nushell)
|
||||
(getExe pkgs.zsh)
|
||||
];
|
||||
}
|
||||
// {
|
||||
shells = mkIf (!config.onLinux) [
|
||||
pkgs.nushell
|
||||
pkgs.zsh
|
||||
];
|
||||
|
||||
systemPackages = with pkgs; [
|
||||
nushell
|
||||
fish
|
||||
zoxide
|
||||
vivid
|
||||
ripgrep
|
||||
yazi
|
||||
jq
|
||||
yq-go
|
||||
eza
|
||||
fzf
|
||||
gh
|
||||
fastfetch
|
||||
carapace
|
||||
];
|
||||
systemPackages = with pkgs; [
|
||||
nushell
|
||||
fish
|
||||
zoxide
|
||||
vivid
|
||||
ripgrep
|
||||
yazi
|
||||
jq
|
||||
yq-go
|
||||
eza
|
||||
fzf
|
||||
gh
|
||||
fastfetch
|
||||
carapace
|
||||
bat
|
||||
bat-extras.core
|
||||
];
|
||||
|
||||
shellAliases = {
|
||||
v = "nvim .";
|
||||
ff = "fastfetch --load-config examples/10.jsonc";
|
||||
g = "glimpse --interactive -o both -f llm.md";
|
||||
gg = "open llm.md | save -r /dev/stdout | ^xclip -sel c";
|
||||
rn = "yazi";
|
||||
c = "clear";
|
||||
e = "exa";
|
||||
el = "exa -la";
|
||||
l = "ls -a";
|
||||
ll = "ls -la";
|
||||
cl = "c; l";
|
||||
ap = "cd ~/personal";
|
||||
ad = "cd ~/Downloads";
|
||||
ab = "cd ~/books";
|
||||
a = "cd ~";
|
||||
ah = "cd ~/dotfiles/hosts/thegeneralist";
|
||||
ai3 = "nvim /home/thegeneralist/dotfiles/hosts/thegeneralist/dotfiles/i3/config";
|
||||
rb = "nh os switch . -v -- --show-trace --verbose";
|
||||
shellAliases = {
|
||||
v = "nvim .";
|
||||
vi = "vim";
|
||||
vim = "nvim";
|
||||
|
||||
ff = "fastfetch --load-config examples/10.jsonc";
|
||||
|
||||
g = "glimpse --interactive -o both -f llm.md";
|
||||
gg = "open llm.md | save -r /dev/stdout | ^xclip -sel c";
|
||||
rn = "yazi";
|
||||
cat = "bat";
|
||||
c = "clear";
|
||||
e = "exa";
|
||||
ea = "exa -a";
|
||||
el = "exa -la";
|
||||
l = "ls -a";
|
||||
la = "ls -a";
|
||||
ll = "ls -la";
|
||||
cl = "c; l";
|
||||
ap = "cd ~/personal";
|
||||
ad = "cd ~/Downloads";
|
||||
ab = "cd ~/books";
|
||||
a = "cd ~";
|
||||
ah = "cd ~/dotfiles/hosts/thegeneralist";
|
||||
ai3 = "nvim /home/thegeneralist/dotfiles/hosts/thegeneralist/dotfiles/i3/config";
|
||||
rb = "nh os switch . -v -- --show-trace --verbose";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
home-manager.sharedModules = [
|
||||
({
|
||||
home.file = {
|
||||
".zshrc" = let
|
||||
configFile = ./config.nu;
|
||||
envFile = ./env.nu;
|
||||
in {
|
||||
text = "exec nu --env-config ${envFile} --config ${configFile}";
|
||||
force = true;
|
||||
{
|
||||
home = {
|
||||
sessionPath = [ "$HOME/.amp/bin" "$HOME/.npm-packages/bin" "/opt/homebrew/bin" ];
|
||||
file = {
|
||||
".zshrc" =
|
||||
let
|
||||
configFile = ./config.nu;
|
||||
envFile = ./env.nu;
|
||||
in
|
||||
{
|
||||
text = "exec nu --env-config ${envFile} --config ${configFile}";
|
||||
force = true;
|
||||
};
|
||||
|
||||
".config/nushell/zoxide.nu".source = pkgs.runCommand "zoxide.nu" { } ''
|
||||
${getExe pkgs.zoxide} init nushell --cmd cd > $out
|
||||
'';
|
||||
|
||||
".config/nushell/ls_colors.txt".source = pkgs.runCommand "ls_colors.txt" { } ''
|
||||
${getExe pkgs.vivid} generate gruvbox-dark-hard > $out
|
||||
'';
|
||||
};
|
||||
|
||||
".config/nushell/zoxide.nu".source = pkgs.runCommand "zoxide.nu" {} ''
|
||||
${getExe pkgs.zoxide} init nushell --cmd cd > $out
|
||||
'';
|
||||
|
||||
".config/nushell/ls_colors.txt".source = pkgs.runCommand "ls_colors.txt" {} ''
|
||||
${getExe pkgs.vivid} generate gruvbox-dark-hard > $out
|
||||
'';
|
||||
};
|
||||
})
|
||||
}
|
||||
(homeArgs: {
|
||||
programs.nushell = {
|
||||
enable = true;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ source ~/.config/nushell/zoxide.nu
|
|||
|
||||
# Extra PATHs
|
||||
# $env.PATH = [
|
||||
# # ($env.HOME | path join ".amp/bin")
|
||||
# # "/home/thegeneralist/AppImages"
|
||||
# # ($env.HOME | path join "personal/zen")
|
||||
# # ($env.HOME | path join ".local/scripts")
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
# stolen from https://github.com/RGBCube/ncc/blob/94c349aa767f04f40ff4165c70c15ed3c3996f82/modules/postgresql.nix
|
||||
{ config, lib, pkgs, ... }: let
|
||||
inherit (lib) flip mkForce mkOverride mkValue;
|
||||
inherit (lib) flip mkForce mkOverride mkOption;
|
||||
in {
|
||||
config.environment.systemPackages = [
|
||||
config.services.postgresql.package
|
||||
];
|
||||
|
||||
options.services.postgresql.ensure = mkValue [];
|
||||
options.services.postgresql.ensure = mkOption {
|
||||
default = [];
|
||||
};
|
||||
|
||||
config.services.postgresql = {
|
||||
enable = true;
|
||||
|
|
@ -41,4 +43,3 @@ in {
|
|||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue