1
Fork 0
mirror of https://github.com/thegeneralist01/config.git synced 2026-03-07 10:59:55 +01:00

new stuff

This commit is contained in:
TheGeneralist 2026-01-08 21:15:12 +01:00
parent 6014ad7d7a
commit 01c8bfce80
Signed by: thegeneralist01
SSH key fingerprint: SHA256:pp9qddbCNmVNoSjevdvQvM5z0DHN7LTa8qBMbcMq/R4
18 changed files with 721 additions and 285 deletions

194
AGENTS.md Normal file
View 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.

View file

@ -1,2 +1,246 @@
# config # thegeneralist's Nix Configuration
My Nix flake and dotfiles
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
View file

@ -64,43 +64,6 @@
"type": "github" "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": { "flake-utils": {
"inputs": { "inputs": {
"systems": "systems_2" "systems": "systems_2"
@ -142,37 +105,6 @@
"type": "github" "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": { "home-manager": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
@ -193,28 +125,6 @@
"type": "github" "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": { "nix-darwin": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
@ -238,11 +148,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1747179050, "lastModified": 1755186698,
"narHash": "sha256-qhFMmDkeJX9KJwr5H32f1r7Prs7XbQWtO0h3V0a0rFY=", "narHash": "sha256-wNO3+Ks2jZJ4nTHMuks+cxAiVBGNuEBXsT29Bz6HASo=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "adaa24fbf46737f3f1b5497bf64bae750f82942e", "rev": "fbcf476f790d8a217c3eab4e12033dc4a0f6d23c",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -252,38 +162,6 @@
"type": "github" "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": { "nixpkgs-stable": {
"locked": { "locked": {
"lastModified": 1741992157, "lastModified": 1741992157,
@ -316,31 +194,14 @@
"type": "github" "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": { "root": {
"inputs": { "inputs": {
"agenix": "agenix", "agenix": "agenix",
"fenix": "fenix", "fenix": "fenix",
"ghostty": "ghostty", "ghostty": "ghostty",
"home-manager": "home-manager", "home-manager": "home-manager",
"nix": "nix",
"nix-darwin": "nix-darwin", "nix-darwin": "nix-darwin",
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs"
} }
}, },
"rust-analyzer-src": { "rust-analyzer-src": {

View file

@ -1,48 +1,65 @@
{ {
description = "thegeneralist's config flake"; description = "thegeneralist's config flake";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
home-manager = { home-manager = {
url = "github:nix-community/home-manager"; url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
nix-darwin = { nix-darwin = {
url = "github:nix-darwin/nix-darwin/master"; url = "github:nix-darwin/nix-darwin/master";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
agenix = { agenix = {
url = "github:ryantm/agenix"; url = "github:ryantm/agenix";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
inputs.home-manager.follows = "home-manager"; inputs.home-manager.follows = "home-manager";
inputs.darwin.follows = "nix-darwin"; inputs.darwin.follows = "nix-darwin";
}; };
ghostty = { ghostty = {
url = "github:ghostty-org/ghostty"; url = "github:ghostty-org/ghostty";
}; };
fenix = { fenix = {
url = "github:nix-community/fenix"; url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
#nix.url = "github:DeterminateSystems/nix-src";
}; };
outputs = inputs@{ self, nixpkgs, nix-darwin, nix, ... }: let outputs = inputs@{ self, nixpkgs, nix-darwin, ... }:
inherit (builtins) readDir; let
inherit (nixpkgs.lib) attrsToList const groupBy listToAttrs mapAttrs; # Extend nixpkgs lib with darwin and custom functions
#nix.enable = false; lib = nixpkgs.lib.extend (
_: _: nix-darwin.lib // (import ./lib inputs)
);
lib' = nixpkgs.lib.extend (_: _: nix-darwin.lib); # Import host configurations
lib = lib'.extend <| import ./lib inputs; hostConfigs = import ./hosts { inherit lib inputs self; };
in
targetHost = readDir ./hosts {
|> mapAttrs (name: const <| import ./hosts/${name} lib inputs self) # NixOS configurations for Linux hosts
|> attrsToList nixosConfigurations = hostConfigs.nixos or {};
|> groupBy (host:
if host.name == "thegeneralist" || host.name == "thegeneralist-central" then # Darwin configurations for macOS hosts
"nixosConfigurations" darwinConfigurations = hostConfigs.darwin or {};
else
"darwinConfigurations") # Development shells
|> mapAttrs (const listToAttrs); devShells = lib.genAttrs [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ] (system:
in targetHost; 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
View 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;
}

View file

@ -1 +1 @@
lib: inputs: self: lib.system "darwin" ./configuration.nix lib: inputs: self: lib.mkSystem "darwin" ./configuration.nix

View file

@ -1 +1 @@
lib: inputs: self: lib.system "linux" ./configuration.nix lib: inputs: self: lib.mkSystem "linux" ./configuration.nix

View file

@ -1 +1 @@
lib: inputs: self: lib.system "darwin" ./configuration.nix lib: inputs: self: lib.mkSystem "darwin" ./configuration.nix

View file

@ -1 +1 @@
lib: inputs: self: lib.system "linux" ./configuration.nix lib: inputs: self: lib.mkSystem "linux" ./configuration.nix

View file

@ -1,6 +1,21 @@
inputs: self: super: inputs:
let let
system = import ./system.nix inputs self super; inherit (inputs.nixpkgs.lib) makeExtensible;
option = import ./option.nix inputs self super;
in 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;
}
)

View file

@ -1,66 +1,64 @@
inputs: self: super: inputs: self:
let let
inherit (self) inherit (inputs.nixpkgs.lib)
hasSuffix hasSuffix filesystem attrValues filter getAttrFromPath
filesystem hasAttrByPath mapAttrsToList concatMap;
attrValues
filter # Helper to collect all .nix files recursively in a directory
getAttrFromPath collectModules = path:
hasAttrByPath if builtins.pathExists path
; then filter (hasSuffix ".nix") (filesystem.listFilesRecursive path)
else [];
collectModules = path: filesystem.listFilesRecursive path |> filter (hasSuffix ".nix"); # Collect modules from flake inputs with fallback handling
collectInputModules = packagePath:
collectInputModules = let
packagePath: getModule = input:
(attrValues inputs) |> filter (hasAttrByPath packagePath) |> map (getAttrFromPath packagePath); if hasAttrByPath packagePath input
then [ (getAttrFromPath packagePath input) ]
else [];
in
concatMap getModule (attrValues inputs);
# Shared arguments for all configurations
specialArgs = inputs // { specialArgs = inputs // {
inherit inputs; inherit inputs self;
inherit self;
}; };
# All modules # Collect platform-specific modules
modulesCommon = collectModules ../modules/common; modulesCommon = collectModules ../modules/common;
modulesLinux = collectModules ../modules/linux; modulesLinux = collectModules ../modules/linux;
modulesDarwin = collectModules ../modules/darwin; modulesDarwin = collectModules ../modules/darwin;
inputModulesNixos = collectInputModules [ # Collect input modules by platform
"nixosModules" inputModulesNixos = collectInputModules [ "nixosModules" "default" ];
"default" inputModulesDarwin = collectInputModules [ "darwinModules" "default" ];
];
inputModulesDarwin = collectInputModules [
"darwinModules"
"default"
];
# Overlays # Collect overlays from inputs
overlays = collectInputModules [ overlays = collectInputModules [ "overlays" "default" ];
"overlays"
"default" overlayModule = {
];
overlayModules = {
nixpkgs.overlays = overlays; nixpkgs.overlays = overlays;
}; };
in in
{ {
system = # Main system builder function
os: configFile: mkSystem = os: configFile:
(if os == "darwin" then let
super.darwinSystem systemBuilder = if os == "darwin"
else then inputs.nix-darwin.lib.darwinSystem
super.nixosSystem) { else inputs.nixpkgs.lib.nixosSystem;
inherit specialArgs;
platformModules = if os == "darwin"
modules = then modulesDarwin ++ inputModulesDarwin
[ else modulesLinux ++ inputModulesNixos;
overlayModules in
configFile systemBuilder {
] inherit specialArgs;
++ modulesCommon
++ ( modules = [
if os == "darwin" then modulesDarwin ++ inputModulesDarwin else modulesLinux ++ inputModulesNixos overlayModule
); configFile
}; ] ++ modulesCommon ++ platformModules;
};
} }

26
modules/common/amp.nix Normal file
View 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 ];
}

View file

@ -4,6 +4,7 @@ in {
options.dnsServers = mkOption { options.dnsServers = mkOption {
default = [ default = [
"100.100.100.100#shorthair-wall.ts.net" "100.100.100.100#shorthair-wall.ts.net"
"1.1.1.1#"
]; ];
}; };
} }

View file

@ -30,6 +30,8 @@ in {
builders-use-substitutes = true; builders-use-substitutes = true;
}; };
nix.package = pkgs.nixVersions.nix_2_30;
nix.distributedBuilds = true; nix.distributedBuilds = true;
nix.buildMachines = if (config.networking.hostName != "thegeneralist-central") then [{ nix.buildMachines = if (config.networking.hostName != "thegeneralist-central") then [{
hostName = "thegeneralist-central"; hostName = "thegeneralist-central";

View file

@ -71,6 +71,14 @@ alias rb = nh os switch . -v -- --show-trace --verbose
def greeting [] { def greeting [] {
let quotes = [ let quotes = [
"What is impossible for you is not impossible for me." "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. Theyll hate you for it, but thats 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))) echo ($quotes | get (random int 0..(($quotes | length) - 1)))
} }

View file

@ -1,71 +1,106 @@
{ config, pkgs, lib, ... }: let {
inherit (lib) readFile getExe mkIf optionalAttrs; config,
in { pkgs,
lib,
...
}:
let
inherit (lib)
readFile
getExe
mkAfter
mkIf
optionalAttrs
;
in
{
# TODO: starship + change the zoxide src # TODO: starship + change the zoxide src
# TODO: Rust tooling # TODO: Rust tooling
environment = optionalAttrs config.onLinux { environment =
sessionVariables.SHELLS = [ (getExe pkgs.nushell) (getExe pkgs.zsh) ]; optionalAttrs config.onLinux {
} // { sessionVariables.SHELLS = [
shells = mkIf (!config.onLinux) [ pkgs.nushell pkgs.zsh ]; (getExe pkgs.nushell)
(getExe pkgs.zsh)
];
}
// {
shells = mkIf (!config.onLinux) [
pkgs.nushell
pkgs.zsh
];
systemPackages = with pkgs; [ systemPackages = with pkgs; [
nushell nushell
fish fish
zoxide zoxide
vivid vivid
ripgrep ripgrep
yazi yazi
jq jq
yq-go yq-go
eza eza
fzf fzf
gh gh
fastfetch fastfetch
carapace carapace
]; bat
bat-extras.core
];
shellAliases = { shellAliases = {
v = "nvim ."; v = "nvim .";
ff = "fastfetch --load-config examples/10.jsonc"; vi = "vim";
g = "glimpse --interactive -o both -f llm.md"; vim = "nvim";
gg = "open llm.md | save -r /dev/stdout | ^xclip -sel c";
rn = "yazi"; ff = "fastfetch --load-config examples/10.jsonc";
c = "clear";
e = "exa"; g = "glimpse --interactive -o both -f llm.md";
el = "exa -la"; gg = "open llm.md | save -r /dev/stdout | ^xclip -sel c";
l = "ls -a"; rn = "yazi";
ll = "ls -la"; cat = "bat";
cl = "c; l"; c = "clear";
ap = "cd ~/personal"; e = "exa";
ad = "cd ~/Downloads"; ea = "exa -a";
ab = "cd ~/books"; el = "exa -la";
a = "cd ~"; l = "ls -a";
ah = "cd ~/dotfiles/hosts/thegeneralist"; la = "ls -a";
ai3 = "nvim /home/thegeneralist/dotfiles/hosts/thegeneralist/dotfiles/i3/config"; ll = "ls -la";
rb = "nh os switch . -v -- --show-trace --verbose"; 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-manager.sharedModules = [
({ {
home.file = { home = {
".zshrc" = let sessionPath = [ "$HOME/.amp/bin" "$HOME/.npm-packages/bin" "/opt/homebrew/bin" ];
configFile = ./config.nu; file = {
envFile = ./env.nu; ".zshrc" =
in { let
text = "exec nu --env-config ${envFile} --config ${configFile}"; configFile = ./config.nu;
force = true; 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: { (homeArgs: {
programs.nushell = { programs.nushell = {
enable = true; enable = true;

View file

@ -18,6 +18,7 @@ source ~/.config/nushell/zoxide.nu
# Extra PATHs # Extra PATHs
# $env.PATH = [ # $env.PATH = [
# # ($env.HOME | path join ".amp/bin")
# # "/home/thegeneralist/AppImages" # # "/home/thegeneralist/AppImages"
# # ($env.HOME | path join "personal/zen") # # ($env.HOME | path join "personal/zen")
# # ($env.HOME | path join ".local/scripts") # # ($env.HOME | path join ".local/scripts")

View file

@ -1,12 +1,14 @@
# stolen from https://github.com/RGBCube/ncc/blob/94c349aa767f04f40ff4165c70c15ed3c3996f82/modules/postgresql.nix # stolen from https://github.com/RGBCube/ncc/blob/94c349aa767f04f40ff4165c70c15ed3c3996f82/modules/postgresql.nix
{ config, lib, pkgs, ... }: let { config, lib, pkgs, ... }: let
inherit (lib) flip mkForce mkOverride mkValue; inherit (lib) flip mkForce mkOverride mkOption;
in { in {
config.environment.systemPackages = [ config.environment.systemPackages = [
config.services.postgresql.package config.services.postgresql.package
]; ];
options.services.postgresql.ensure = mkValue []; options.services.postgresql.ensure = mkOption {
default = [];
};
config.services.postgresql = { config.services.postgresql = {
enable = true; enable = true;
@ -41,4 +43,3 @@ in {
}); });
}; };
} }