Skip to content

refactor: darwin modules and add explicit flake checks - #32

Merged
csamuel merged 11 commits into
mainfrom
nix-best-practices
Mar 15, 2026
Merged

refactor: darwin modules and add explicit flake checks#32
csamuel merged 11 commits into
mainfrom
nix-best-practices

Conversation

@csamuel

@csamuel csamuel commented Mar 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • make config evaluation and activation more declarative
  • add explicit flake check coverage for treefmt and deadnix
  • isolate the determinate nix trusted-users workaround into its own module
  • clean up wallpaper handling and make its option shape clearer
  • manage Zed settings via an out-of-store symlink so Zed can still write to them
  • remove nil and standardize on nixd
  • DRY shared Darwin host config with reusable media/gaming host snippets
  • centralize Nerd Font Homebrew casks in a dedicated module
  • update README and AGENTS.md to center nix flake check in the workflow

Summary by CodeRabbit

  • New Features

    • Starship prompt with runtime switching to Powerlevel10k; updated shell aliases
    • Determinate Nix option with activation support
    • Nerd Fonts provisioning and desktop wallpaper enablement
    • Multi-system dev/check support for builds and checks
  • Documentation

    • Added validation/validate section and targeted checks to README and workflow docs
  • Chores

    • Zed editor: new icon theme and updated AI model/settings
  • Refactor

    • Host configurations converted to reusable modular imports

@coderabbitai

coderabbitai Bot commented Mar 14, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 009c20e8-d3d9-4eb0-a70a-c41361a7f968

📥 Commits

Reviewing files that changed from the base of the PR and between 3eac957 and e5bac57.

📒 Files selected for processing (1)
  • flake.nix

📝 Walkthrough

Walkthrough

Adds Starship prompt config, updates Zed settings, refactors Darwin host/module configs (shared imports, new modules for determinate Nix and nerd fonts), changes wallpaper option/activation, restructures flake.nix for multi-system checks/formatters, and enables runtime switching between Powerlevel10k and Starship.

Changes

Cohort / File(s) Summary
Shell configs
.config/starship.toml, home-manager/default.nix, home-manager/p10k/p10k.zsh
Adds Starship config and includes it in home-manager; adds runtime prompt switching via PROMPT_THEME and helper functions; p10k now early-exits unless PROMPT_THEME == "p10k".
Editor settings
.config/zed/settings.json
Updates Zed settings: adds context server, changes icon theme, switches inline/ default assistant models to zed.dev (claude-sonnet-4 variants), lowers buffer font size, and adds an OpenCode agent_server entry.
Docs & CI
AGENTS.md, README.md
Adds "Validate" and testing workflow edits: new primary validation command (nix flake check --keep-going --print-build-logs) and suggestions for targeted checks (treefmt, deadnix).
Darwin top-level
darwin/darwin.nix, darwin/modules/...
Imports new modules nerd-fonts.nix and determinate-nix.nix; enables determinateNix.enable in base module; exposes config in defaults module signature.
New Darwin modules
darwin/modules/determinate-nix.nix, darwin/modules/nerd-fonts.nix
Adds determinate-nix.nix (options: enable, trustedUsers; activation script to write trusted-users into /etc/nix/nix.custom.conf) and nerd-fonts.nix (homebrew casks for Nerd Fonts).
Darwin module edits
darwin/modules/activation.nix, darwin/modules/homebrew.nix, darwin/modules/wallpaper.nix
Removes prior activation trusted-users mutation; adds desktoppr brew and removes three font brews; changes wallpaper option from path to { enable, image } with assertion and updated activation script.
Host modules / imports
darwin/hosts/*, darwin/hosts/shared/*
Replaces inline profiles flags with imports referencing ./shared/media.nix and ./shared/gaming.nix; several hosts loosen module arg patterns to { ... }; wallpaper declarations standardized; added shared/media.nix and shared/gaming.nix.
Flake restructure
flake.nix
Refactors flake to be multi-system: introduces systems/forAllSystems helpers, unifies formatter with forAllSystems, generates per-system devShells, and adds multi-system checks via mkCheck.
Zed dotfile handling
home-manager/default.nix
Switches zed settings to an out-of-store symlink to dotfiles; adds starship.toml to xdg config sources and starship to home.packages; removes p10k plugin entry from plugin list.

Sequence Diagram

sequenceDiagram
    participant User
    participant Shell as Zsh Shell
    participant ThemeCheck as PROMPT_THEME Check
    participant P10k as Powerlevel10k Init
    participant Starship as Starship Init
    participant P10kCfg as p10k.zsh

    User->>Shell: start shell
    Shell->>ThemeCheck: evaluate PROMPT_THEME
    alt PROMPT_THEME == "p10k"
        ThemeCheck->>P10k: load Powerlevel10k
        P10k->>P10kCfg: source p10k config (guarded)
        P10kCfg->>User: render p10k prompt
    else
        ThemeCheck->>Starship: initialize Starship
        Starship->>User: render Starship prompt
    end
    User->>Shell: run prompt-starship or prompt-p10k (runtime switch)
    Shell->>ThemeCheck: re-evaluate PROMPT_THEME and re-init chosen prompt
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Poem

🐰 I hopped through files both new and old,
Modules nested, configs bold,
Starship hums while p10k waits,
Prompts now switch at runtime gates,
A rabbit’s cheer for tidy states!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately reflects the main changes: refactoring Darwin modules and adding explicit flake checks, which are the core objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch nix-best-practices
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude

claude Bot commented Mar 14, 2026

Copy link
Copy Markdown

PR Review: refactor: darwin modules and add explicit flake checks

Overall this is a solid refactor — the changes move in the right direction. The DRY improvements, better option shapes, and explicit CI checks are all worthwhile. A few issues worth addressing:


Bugs / Issues

1. desktoppr always installed, regardless of wallpaper being enabled

In darwin/modules/homebrew.nix, desktoppr was moved unconditionally into the base Homebrew cask list. Previously it was installed only when wallpaper was configured. If wallpaper is disabled (the default), desktoppr will still be installed on every host. Consider keeping it inside the wallpaper module's config = lib.mkIf cfg.enable { ... } block:

# darwin/modules/wallpaper.nix
config = lib.mkIf cfg.enable {
  homebrew.casks = [ "desktoppr" ];
  ...
};

2. Hardcoded path in out-of-store Zed symlink

config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/src/dotfiles/.config/zed/settings.json"

This silently creates a dangling symlink if the repo isn't checked out at ~/src/dotfiles. Worth a comment documenting the expected checkout location, or consider making the path a home-manager option.

3. nil removed, nixd not added

The PR description says "remove nil and standardize on nixd" but nixd doesn't appear to be added anywhere in this diff. If it's already present elsewhere that's fine, but worth confirming nixd is actually available in the environment after this change.


Minor Issues

4. Non-atomic write to /etc/nix/nix.custom.conf

In darwin/modules/determinate-nix.nix:

cat "$tmp" > /etc/nix/nix.custom.conf
rm -f "$tmp"

If the system loses power between these two lines the file could be left empty. Since mktemp creates the file in /tmp (same filesystem on macOS), you can make this atomic:

mv "$tmp" /etc/nix/nix.custom.conf

5. devShells not using forAllSystems

formatter and checks now use forAllSystems, but devShells remains hardcoded per-system. Minor inconsistency, though functionally fine.


Positive notes

  • builtins.getEnv "HOME"config.users.users.${config.system.primaryUser}.home in defaults.nix is an excellent fix. The old form was impure and could silently produce wrong results.
  • assertions in wallpaper.nix — nice use of Nix assertions to surface misconfiguration at eval time rather than runtime.
  • determinate-nix.nix module — isolating this workaround is the right call. The idempotent grep/rewrite approach (removing the old line before appending) is much better than the original append-only pattern.
  • Shared host snippets (hosts/shared/media.nix, hosts/shared/gaming.nix) — clean DRY improvement, easy to read.
  • Explicit checks in flake.nix — making treefmt and deadnix first-class flake checks is a great addition for CI.
  • p10k/starship coexistence — the PROMPT_THEME variable approach with prompt-starship / prompt-p10k helpers and the early-return guard in p10k.zsh is a pragmatic way to migrate gradually.

🤖 Generated with Claude Code

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@darwin/hosts/dunston.nix`:
- Line 1: The module currently uses a catch-all signature "{ ... }:" which hides
expected inputs; update the function signature in dunston.nix to explicitly
destructure the standard host module attributes (e.g. use "{ pkgs, lib, config,
... }:"), ensuring pkgs/lib/config are available for use in the file and
preserving the rest via "...".

In `@darwin/hosts/mfourmax.nix`:
- Line 1: The file currently uses a generic anonymous argument signature "{ ...
}:"; update it to the repo's destructured attribute-set form by replacing that
with an explicit destructured signature such as "{ pkgs, lib, config, ... }:" so
callers and internal references clearly see the provided attributes; locate the
top-level function signature in mfourmax.nix and adjust it to the explicit
destructured form (e.g., include pkgs, lib, config) to match the repository
convention.

In `@darwin/hosts/shared/media.nix`:
- Line 1: Replace the generic module signature "{ ... }:" with an explicit
destructured attribute set (for example "{ pkgs, lib, config, ... }:"), updating
the function parameter list in this module's top-level signature so it follows
the repo convention and makes required inputs (pkgs, lib, config) explicit.

In `@darwin/hosts/spaceblack.nix`:
- Line 1: The module currently accepts a catch-all argument set "{ ... }:";
change it to explicit module arg destructuring like "{ pkgs, lib, config, ...
}:" so the host module exposes standard attributes (pkgs, lib, config) per repo
convention; update the function signature in the top-level of spaceblack.nix to
replace "{ ... }:" with the explicit destructured form and keep the trailing
"...": to preserve additional args.

In `@darwin/modules/determinate-nix.nix`:
- Around line 26-27: Update the line that filters out existing trusted-users
entries so it also ignores lines with leading whitespace: change the grep -v
invocation that currently matches '^trusted-users' to a pattern that allows
optional leading whitespace (for example using a POSIX whitespace class or
equivalent) so indented entries are removed; keep the subsequent echo that
writes "trusted-users = root ${trustedUsers}" to "$tmp" unchanged. This targets
the grep -v ... /etc/nix/nix.custom.conf > "$tmp" || true command and the echo
"trusted-users = root ${trustedUsers}" >> "$tmp" action.

In `@darwin/modules/wallpaper.nix`:
- Around line 30-31: The current invocation uses a hardcoded path
(/usr/local/bin/desktoppr) in the line "sudo -u ${config.system.primaryUser}
/usr/local/bin/desktoppr \"${cfg.image}\"", which breaks on aarch64-darwin;
replace it with a runtime-resolved binary path or the package-provided path. Fix
by changing the call to either use the package reference
${pkgs.desktoppr}/bin/desktoppr (preferred if you add desktoppr to pkgs) or
resolve at runtime with something like invoking sh -c "cmd=$(command -v
desktoppr) && \"$cmd\" \"${cfg.image}\"" under sudo -u
${config.system.primaryUser}; ensure the replacement still runs as the
primaryUser and passes "${cfg.image}" unchanged.

In `@home-manager/default.nix`:
- Around line 18-19: The zed settings symlink hard-codes the dotfiles path;
update xdg.configFile."zed/settings.json".source to use a repo-root variable
instead of "${config.home.homeDirectory}/src/dotfiles/...": accept the dotfiles
repo root as a module option (e.g. an attribute like dotfilesRepoRoot) or via
specialArgs, and pass that variable into the expression used by
config.lib.file.mkOutOfStoreSymlink so the symlink points to
"${dotfilesRepoRoot}/.config/zed/settings.json" rather than a fixed
~/src/dotfiles path.

In `@home-manager/p10k/p10k.zsh`:
- Line 2: The theme-skip guard currently uses a bare return which can propagate
a non-zero status; update the guard in p10k.zsh (the conditional using [[
${PROMPT_THEME:-p10k} == p10k ]] || return) to explicitly return success by
changing the bare return to return 0 so sourcing the file is a graceful no-op
when PROMPT_THEME != p10k.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2c56b1dd-f54d-4430-b8fc-ac8af3f3703a

📥 Commits

Reviewing files that changed from the base of the PR and between 2f2a383 and f6e5613.

📒 Files selected for processing (22)
  • .config/starship.toml
  • .config/zed/settings.json
  • AGENTS.md
  • README.md
  • darwin/darwin.nix
  • darwin/hosts/benson.nix
  • darwin/hosts/dunston.nix
  • darwin/hosts/higgins.nix
  • darwin/hosts/mfourmax.nix
  • darwin/hosts/shared/gaming.nix
  • darwin/hosts/shared/media.nix
  • darwin/hosts/spaceblack.nix
  • darwin/modules/activation.nix
  • darwin/modules/base.nix
  • darwin/modules/defaults.nix
  • darwin/modules/determinate-nix.nix
  • darwin/modules/homebrew.nix
  • darwin/modules/nerd-fonts.nix
  • darwin/modules/wallpaper.nix
  • flake.nix
  • home-manager/default.nix
  • home-manager/p10k/p10k.zsh
💤 Files with no reviewable changes (1)
  • darwin/modules/activation.nix

Comment thread darwin/hosts/dunston.nix
@@ -1,12 +1,13 @@
{ pkgs, lib, ... }:
{ ... }:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Keep host module signatures explicit.

Line 1 uses { ... }:; please use explicit destructuring per repo convention.

Suggested change
-{ ... }:
+{ pkgs, lib, config, ... }:

As per coding guidelines: Use attribute sets with destructuring in function signatures: { pkgs, lib, config, ... }:.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{ ... }:
{ pkgs, lib, config, ... }:
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@darwin/hosts/dunston.nix` at line 1, The module currently uses a catch-all
signature "{ ... }:" which hides expected inputs; update the function signature
in dunston.nix to explicitly destructure the standard host module attributes
(e.g. use "{ pkgs, lib, config, ... }:"), ensuring pkgs/lib/config are available
for use in the file and preserving the rest via "...".

Comment thread darwin/hosts/mfourmax.nix
@@ -1,9 +1,10 @@
{ pkgs, lib, ... }:
{ ... }:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Use the standard explicit signature form here too.

Line 1 should follow the repo’s destructured function signature convention.

Suggested change
-{ ... }:
+{ pkgs, lib, config, ... }:

As per coding guidelines: Use attribute sets with destructuring in function signatures: { pkgs, lib, config, ... }:.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{ ... }:
{ pkgs, lib, config, ... }:
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@darwin/hosts/mfourmax.nix` at line 1, The file currently uses a generic
anonymous argument signature "{ ... }:"; update it to the repo's destructured
attribute-set form by replacing that with an explicit destructured signature
such as "{ pkgs, lib, config, ... }:" so callers and internal references clearly
see the provided attributes; locate the top-level function signature in
mfourmax.nix and adjust it to the explicit destructured form (e.g., include
pkgs, lib, config) to match the repository convention.

@@ -0,0 +1,9 @@
{ ... }:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Align module signature with repo convention.

Line 1 should use explicit destructuring instead of { ... }:.

Suggested change
-{ ... }:
+{ pkgs, lib, config, ... }:

As per coding guidelines: Use attribute sets with destructuring in function signatures: { pkgs, lib, config, ... }:.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{ ... }:
{ pkgs, lib, config, ... }:
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@darwin/hosts/shared/media.nix` at line 1, Replace the generic module
signature "{ ... }:" with an explicit destructured attribute set (for example "{
pkgs, lib, config, ... }:"), updating the function parameter list in this
module's top-level signature so it follows the repo convention and makes
required inputs (pkgs, lib, config) explicit.

@@ -1,5 +1,3 @@
{ pkgs, lib, ... }:
{ ... }:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Use explicit module arg destructuring for host modules.

Line 1 currently uses { ... }:. Please switch to the repo-standard explicit destructuring form for consistency.

Suggested change
-{ ... }:
+{ pkgs, lib, config, ... }:

As per coding guidelines: Use attribute sets with destructuring in function signatures: { pkgs, lib, config, ... }:.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{ ... }:
{ pkgs, lib, config, ... }:
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@darwin/hosts/spaceblack.nix` at line 1, The module currently accepts a
catch-all argument set "{ ... }:"; change it to explicit module arg
destructuring like "{ pkgs, lib, config, ... }:" so the host module exposes
standard attributes (pkgs, lib, config) per repo convention; update the function
signature in the top-level of spaceblack.nix to replace "{ ... }:" with the
explicit destructured form and keep the trailing "...": to preserve additional
args.

Comment thread darwin/modules/determinate-nix.nix Outdated
Comment thread darwin/modules/wallpaper.nix
Comment thread home-manager/default.nix Outdated
Comment thread home-manager/p10k/p10k.zsh Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
flake.nix (1)

133-133: Update the CI runner comment to avoid drift.

Line 133 says “linux runners”, but current workflow context indicates macOS-only CI. Rewording this comment will prevent future confusion.

Based on learnings: In csamuel's dotfiles repository, the CI workflow (.github/workflows/ci.yml) uses exclusively macos-15 runners for all jobs, so only aarch64-darwin devShell packages are relevant for CI functionality.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@flake.nix` at line 133, Update the stale comment "# For CI lint on linux
runners" to reflect the actual CI platform used; replace it with a concise
macOS-specific note such as "# For CI lint on macOS runners (macos-15)" so the
comment next to the CI-related devShell/package declarations accurately
documents that the workflow uses macos-15 runners and only aarch64-darwin
packages are relevant for CI.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@flake.nix`:
- Line 133: Update the stale comment "# For CI lint on linux runners" to reflect
the actual CI platform used; replace it with a concise macOS-specific note such
as "# For CI lint on macOS runners (macos-15)" so the comment next to the
CI-related devShell/package declarations accurately documents that the workflow
uses macos-15 runners and only aarch64-darwin packages are relevant for CI.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 15181c5d-4643-43b8-b842-39b2b9739cbf

📥 Commits

Reviewing files that changed from the base of the PR and between f6e5613 and 3eac957.

📒 Files selected for processing (4)
  • darwin/modules/determinate-nix.nix
  • flake.nix
  • home-manager/default.nix
  • home-manager/p10k/p10k.zsh
🚧 Files skipped from review as they are similar to previous changes (1)
  • darwin/modules/determinate-nix.nix

@csamuel
csamuel merged commit 7876718 into main Mar 15, 2026
1 of 2 checks passed
@csamuel
csamuel deleted the nix-best-practices branch March 15, 2026 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant