Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Overview

Nix-based dotfiles for macOS (nix-darwin + home-manager). Primary configs: Neovim (Lua), Tmux, Zsh, CLI tools.
Platform: aarch64-darwin (Apple Silicon only). Flake-based with custom modular structure using `lib.autoImport`.
Platform: aarch64-darwin (Apple Silicon only). Flake-based, using flake-parts + `import-tree` (the Dendritic pattern): every `.nix` file under `modules/` is auto-discovered as a flake-parts module.

## MANDATORY: Use td for Task Management

Expand Down Expand Up @@ -39,12 +39,12 @@ Use td usage -q after first read.

## Code Style - Nix

- **Module pattern:** `options` with `kriswill.<feature>.enable` + `config` with `lib.mkIf`. See `modules/darwin/core/programs/nh/default.nix` for reference.
- **Module pattern:** wrap in `flake.modules.{darwin,homeManager}.<name> = { ... }: { options … config … }`; `options` with `kriswill.<feature>.enable` + `config` with `lib.mkIf`. See `modules/darwin/nh.nix` for reference.
- **Imports:** Use `inherit` for cleaner destructuring
- **Package lists:** Use `builtins.attrValues { inherit (pkgs) ...; }` pattern
- **Options:** `lib.mkEnableOption`, `lib.mkProgramOption` (custom), `lib.mkDefault`
- **Symlinks:** Use `config.lib.file.mkOutOfStoreSymlink` (see neovim module)
- **Unfree packages:** Add to `allowUnfreePredicate` in `flake.nix`
- **Unfree packages:** Repo sets `nixpkgs.config.allowUnfree = false` in `modules/darwin/core.nix`; to permit a specific unfree package add a `nixpkgs.config.allowUnfreePredicate` there

## Code Style - Lua (Neovim)

Expand Down Expand Up @@ -72,47 +72,49 @@ Use td usage -q after first read.

- **Module options:** `kriswill.<feature>.enable` (e.g., `kriswill.neovim.enable`)
- **Packages:** kebab-case (e.g., `kitten`, `iv`, `tofu-ls`)
- **Nix functions:** camelCase (e.g., `mkDarwin`, `autoImport`, `mkProgramOption`)
- **Nix functions:** camelCase (e.g., `mkProgramOption`, `kanagawa`)
- **Files:** kebab-case for multi-word (e.g., `alias-en0.nix`, `update-opencode.sh`)
- **Hosts:** Descriptive names (e.g., `k`, `SOC-Kris-Williams`)

## File Organization

```
├── modules/
│ ├── darwin/ # nix-darwin system modules (uses lib.autoImport)
│ │ ├── core/ # Essential system configuration
│ │ └── mixins/ # Optional features (homebrew, aliases)
│ └── home-manager/ # User-level tool configs (neovim, tmux, zsh, git, etc.)
├── modules/ # Every .nix here is auto-imported as a flake-parts module
│ ├── flake-parts.nix # systems list + flake-parts plumbing
│ ├── darwin.nix # realises `configurations.darwin.<host>` → darwinConfigurations
│ ├── home.nix # wires home-manager into nix-darwin
│ ├── lib.nix, packages.nix, overlays.nix, dev.nix
│ ├── darwin/ # nix-darwin system feature modules (core, homebrew, ghostty, …)
│ ├── home-manager/ # User-level tool configs (neovim, tmux, zsh, git, …)
│ └── hosts/ # Per-host config (k, mini, SOC-Kris-Williams)
├── config/ # Actual config files (symlinked to XDG locations)
│ ├── nvim/ # Neovim Lua configuration
│ └── tmux/ # Tmux configuration
├── pkgs/ # Custom package definitions (*.nix files or subdirectories)
├── overlays/ # Nixpkgs overlays (makes custom packages available)
├── hosts/ # Host-specific configurations
├── lib/ # Custom library functions (autoImport, mkDarwin, etc.)
├── lib/ # Pure lib helpers (mkProgramOption, kanagawa) — outside modules/ so import-tree skips them
└── scripts/ # Helper scripts for package updates
```

## Custom Library Functions

Located in `lib/default.nix`: `autoImport` (directory-based module loading), `mkDarwin`, `mkHomeManager`, `mkProgramOption`. See file for API details.
Pure helpers live in `lib/default.nix`: `mkProgramOption` and `kanagawa`. They're merged onto `nixpkgs.lib` in `modules/lib.nix` (exposed as `config.kriswill.lib`) and handed to the darwin/home-manager evaluations via specialArgs, so modules reach them as `lib.mkProgramOption` / `lib.kanagawa`. Module auto-discovery and the old `mkDarwin`/`mkHomeManager`/`autoImport` builders are gone — flake-parts + `import-tree ./modules` (wired in `flake.nix`) handles discovery, and `modules/{darwin,home}.nix` realise the configurations.

## Common Patterns

**Adding a New Module:**

1. Create file in `modules/darwin/` or `modules/home-manager/`
2. Follow module pattern (see Code Style - Nix above)
3. File is auto-discovered via `lib.autoImport` in parent `default.nix`
1. Create a `.nix` file in `modules/darwin/` or `modules/home-manager/` (a bare `<name>.nix`; only use a directory when bundling adjacent config files)
2. Define `flake.modules.darwin.<name>` or `flake.modules.homeManager.<name>` following the module pattern (see Code Style - Nix above)
3. File is auto-discovered by `import-tree` — no manual import needed (prefix a path component with `_` to exclude it, e.g. `yazi/_themes/`)
4. **Must `git add` new files before `nix build`** — flakes only see git-tracked files

**Adding a Custom Package:**

1. Create `pkgs/<name>/package.nix`
2. Add to `packages.${system}` in `flake.nix`
3. Create overlay in `overlays/<name>.nix`
4. If unfree: add to `allowUnfreePredicate` in `flake.nix`
1. Create `pkgs/<name>.nix` (or `pkgs/<name>/package.nix`)
2. Add `<name> = pkgs.callPackage ../pkgs/<name>.nix { };` to `perSystem.packages` in `modules/packages.nix`
3. To make it available to hosts, create `overlays/<name>.nix` and register it in `modules/overlays.nix` (`flake.overlays.<name>`)
4. If unfree: add a `nixpkgs.config.allowUnfreePredicate` entry in `modules/darwin/core.nix`

**Symlinked Configs:**

Expand Down
62 changes: 56 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 3 additions & 58 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,67 +1,12 @@
{
description = "Kris' Apple Nix Configuration";

outputs =
inputs@{
self,
nixpkgs,
...
}:
let
inherit (self) outputs;
# All of my macs are Apple ARM
system = "aarch64-darwin";
pkgs = import nixpkgs {
inherit system;
};
lib = nixpkgs.lib.extend (
_: _:
import ./lib {
inherit self inputs outputs;
}
);
in
{
inherit lib;
packages.${system} = {
kitten = pkgs.callPackage ./pkgs/kitten.nix { };
iv = pkgs.callPackage ./pkgs/iv.nix { };
};
darwinConfigurations = {
k = lib.mkDarwin ./hosts/k "k";
mini = lib.mkDarwin ./hosts/mini "k";
SOC-Kris-Williams = lib.mkDarwin ./hosts/SOC-Kris-Williams "k";
};
devShells.${system}.default = pkgs.mkShell {
name = "dotfiles";
packages = builtins.attrValues {
inherit (pkgs)
deadnix
statix
nixfmt-tree
just
;
};
shellHook = ''
PATH_add "$PWD/bin"
'';
};
overlays = import ./overlays { inherit inputs; };
formatter.${system} = pkgs.nixfmt-tree;
darwinModules = rec {
kriswill = import ./modules/darwin {
inherit lib;
};
default = kriswill;
};
homeModules = rec {
kriswill = ./modules/home-manager;
default = kriswill;
};
};
outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules);

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
import-tree.url = "github:denful/import-tree";
darwin = {
url = "github:lnl7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
Expand Down
8 changes: 0 additions & 8 deletions hosts/SOC-Kris-Williams/default.nix

This file was deleted.

6 changes: 0 additions & 6 deletions hosts/k/default.nix

This file was deleted.

5 changes: 0 additions & 5 deletions hosts/mini/default.nix

This file was deleted.

70 changes: 3 additions & 67 deletions lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
{
self,
outputs,
inputs,
}:
# Pure helpers merged onto nixpkgs lib (see modules/lib.nix). Kept outside
# ./modules so import-tree does not treat it as a flake-parts module.
{ lib }:
let
inherit (outputs) lib;
inherit (inputs.darwin.lib) darwinSystem;
inherit (lib)
filter
forEach
mkEnableOption
mkPackageOption
optionalString
Expand All @@ -17,63 +11,6 @@ in
{
kanagawa = import ./kanagawa.nix;

mkHomeManager = username: {
home-manager = {
backupFileExtension = "hm.bak";
useUserPackages = true;
useGlobalPkgs = true;
users."${username}" = {
imports = [ outputs.homeModules.kriswill ];
kriswill.enable = true;
home.stateVersion = "26.05";
home.homeDirectory = lib.mkForce "/Users/${username}";
manual = {
html.enable = false;
json.enable = false;
manpages.enable = false;
};
};
# sharedModules = [ inputs.mac-app-util.homeManagerModules.default ];
extraSpecialArgs = { inherit inputs username; };
};
};

mkDarwin =
hostmodule: username:
darwinSystem {
specialArgs = {
inherit
self
inputs
outputs
lib
;
};
modules = [
hostmodule
inputs.home-manager.darwinModules.home-manager
outputs.darwinModules.kriswill
(lib.mkHomeManager username)
{
kriswill.enable = true;
nixpkgs = {
hostPlatform = "aarch64-darwin";
overlays = builtins.attrValues outputs.overlays;
};
}
];
};

# read a directory and return a list of all filenames inside except any default.nix
# ripped from: https://github.com/EarthGman/nix-library/blob/main/lib/default.nix#L15
autoImport =
dir:
let
fileNames = builtins.attrNames (builtins.readDir dir);
strippedFileNames = filter (name: name != "default.nix") fileNames;
in
forEach strippedFileNames (fileName: dir + /${fileName});

mkProgramOption =
{
pkgs,
Expand All @@ -86,5 +23,4 @@ in
enable = mkEnableOption (programName + " " + optionalString (description != null) description);
package = mkPackageOption pkgs packageName extraPackageArgs;
};

}
Loading