Skip to content

WIP: feat(user-defaults): implement role-based application defaults#45

Draft
Bad3r wants to merge 11 commits intomainfrom
feat/user-defaults
Draft

WIP: feat(user-defaults): implement role-based application defaults#45
Bad3r wants to merge 11 commits intomainfrom
feat/user-defaults

Conversation

@Bad3r
Copy link
Owner

@Bad3r Bad3r commented Jan 12, 2026

Summary

Implements a centralized user defaults system for application role mapping, replacing hardcoded app references scattered across modules.

Status: 🚧 Work in Progress — Documentation complete, implementation pending

What's included

  • Implementation Plan: docs/drafts/user-defaults-implementation-plan.md

    • Problem statement and design goals
    • Data structure with Wayland support (appId) and multi-class matching (windowClassAliases)
    • Phase 1: Core infrastructure (data file, injection points, validation)
    • Phase 2: Consumer migration (i3-config.nix refactoring)
    • Resolved architectural questions (separation from module package options)
  • Implementation Checklist: docs/drafts/user-defaults-checklist.md

    • Pre-implementation verification tasks
    • Step-by-step implementation tasks with verification commands
    • Post-implementation validation
    • Rollback procedure

Design decisions

  • userDefaults is intentionally separate from programs.<name>.extended.package (different concerns)
  • Validation module with assertions (package path exists) and warnings (module alignment)
  • Follows existing metaOwner injection pattern

Test plan

  • Phase 1: Core infrastructure builds successfully
  • Phase 2: i3-config.nix migration complete
  • Firefox opens on workspace 2
  • Geany opens on workspace 1
  • Thunar opens on workspace 3
  • Terminal keybinding opens Kitty
  • Override mechanism (gui.i3.commands) still works

Remaining work

  • Implement Phase 1 (data file, injection, validation module)
  • Implement Phase 2 (i3-config.nix refactoring)
  • Runtime testing
  • Remove WIP status

Bad3r added 2 commits January 12, 2026 16:29
Companion to the implementation plan with actionable tasks:
- Pre-implementation verification (environment, dependencies, WM_CLASS)
- Phase 1: Core infrastructure (6 steps with subtasks)
- Phase 2: Consumer migration (i3-config.nix refactoring)
- Post-implementation validation (build, functional, regression)
- Rollback procedure
- Remove redundant mkdir (lib/ already exists)
- Fix Step 1.6 verify: use nix-instantiate --parse (import-tree auto-discovers)
- Add validation module execution check via build output grep
@claude
Copy link
Contributor

claude bot commented Jan 12, 2026

Claude finished @Bad3r's task —— View job


PR Review: User Defaults Implementation

I've completed a comprehensive review of this WIP pull request. This is a well-planned implementation with excellent documentation. Here's my detailed analysis:

Review Tasks

  • Read repository guidelines (CLAUDE.md)
  • Review implementation plan documentation
  • Review implementation checklist
  • Analyze design decisions and architecture
  • Check for potential security concerns
  • Evaluate test coverage approach
  • Provide recommendations for improvement

Strengths

Excellent Planning & Documentation:

  • Comprehensive implementation plan with clear problem statement and design goals
  • Well-structured checklist with verification commands for each step
  • Clear separation of concerns between Phase 1 (infrastructure) and Phase 2 (migration)
  • Thoughtful workflow documentation in the data file header

Solid Architecture:

  • Follows existing repository patterns (mirrors metaOwner injection)
  • Pure data structure without package dependencies (evaluation timing is correct)
  • Structured data with explicit fields rather than error-prone fallbacks
  • Clear separation between user defaults and module package options

Security & Safety:

  • Input validation through assertions module
  • Package path existence verification
  • Alignment warnings to catch configuration drift
  • No external dependencies or security risks

Repository Compliance:

  • Follows NixOS configuration dendritic pattern
  • Adheres to repository style guidelines
  • Consistent with existing module authoring patterns
  • Uses proper conventional commit format

⚠️ Areas for Improvement

1. Documentation Consistency (Minor)

  • Line 4 in checklist references non-existent plan document path
  • Some verification commands may need adjustment once implementation begins
  • Consider adding examples of windowClassAliases usage beyond Firefox

2. Test Coverage Gaps

  • Missing test for Wayland appId fallback behavior
  • No verification of windowClassAliases regex generation
  • Consider adding negative tests (invalid package paths)

3. Implementation Readiness

# These commands in the checklist should be verified:
grep -l "_module.args" flake.nix modules/configurations/nixos.nix modules/system76/imports.nix modules/home-manager/nixos.nix

🔍 Potential Issues

1. WM_CLASS Verification Dependencies
The checklist requires manual WM_CLASS verification using xprop, but this assumes:

  • X11 environment (not Wayland-only)
  • Applications are already installed and can be opened
  • User has access to GUI during implementation

Recommendation: Add fallback verification using desktop entry inspection or nixpkgs metadata where available.

2. Home Manager Integration Critical Path
The success heavily depends on correct injection into Home Manager modules. The plan identifies this correctly, but consider:

  • Adding intermediate verification after Step 1.5
  • Testing Home Manager module access before proceeding to Phase 2

3. Regex Generation Robustness

# Line 506 in plan - ensure special regex characters are escaped
{ class = "(?i)(?:${lib.concatStringsSep "|" allClasses})"; };

Recommendation: Add regex escaping for window class names containing special characters.


🎯 Performance Considerations

  • Pure data file approach is optimal for evaluation performance
  • Lazy evaluation through helpers minimizes overhead
  • No runtime performance impacts identified

📝 Recommendations

Before Implementation:

  1. Verify all injection points exist with the exact structure expected
  2. Test the helper functions independently before full integration
  3. Add regex escaping for window class patterns

During Implementation:

  1. Follow the checklist order strictly - dependencies are critical
  2. Commit after each phase for clean rollback points
  3. Test Home Manager integration thoroughly at each step

For Future Enhancement:

  1. Consider adding validation for desktop entry file existence
  2. Add support for per-application workspace preferences
  3. Consider integration with XDG portal defaults

🏆 Overall Assessment

This is a high-quality implementation plan that demonstrates:

  • Deep understanding of the NixOS module system
  • Careful consideration of evaluation timing and dependencies
  • Excellent documentation and testing strategy
  • Clean separation of concerns

The architecture is sound, follows repository patterns well, and the phased approach reduces implementation risk. The documentation quality exceeds typical standards and will be valuable for future maintainers.

Recommendation: Proceed with implementation following the checklist precisely. The plan is solid and ready for execution.


Bad3r added 9 commits January 12, 2026 16:45
Plan changes:
- Add escapeRegex helper to handle special characters in WM_CLASS names
- mkAssign now escapes regex metacharacters before concatenation

Checklist changes:
- Add Step 1.5.1: Intermediate HM verification (critical path)
- Add negative test for invalid package paths (validation module)
- Add windowClassAliases regex verification test
- Add regex escaping verification test
Replace custom escapeRegex helper with nixpkgs built-in lib.strings.escapeRegex.
More idiomatic and already tested/maintained upstream.
Architecture improvement: helpers are now in lib/user-defaults-helpers.nix
from the beginning, avoiding future duplication when adding sway/hyprland.

Plan changes:
- Add Step 1.2: Create helper functions library
- Renumber Steps 1.3-1.7 accordingly
- Step 2.1 now imports helpers instead of defining inline
- Update File Changes Summary with new file

Checklist changes:
- Add Step 1.2 for helpers file creation
- Renumber Steps 1.3-1.7
- Step 2.1.2 now imports helpers instead of adding them inline
Create TODO.md with phased task breakdown for user-defaults feature:
- Phase 0: Preparation and codebase analysis
- Phase 1: Module infrastructure (options, submodule, defaults)
- Phase 2: Helper functions library
- Phase 3: Wiring & propagation verification
- Phase 4: Validation logic (assertions, warnings, strictValidation)
- Phase 5: Consumer migration (i3-config.nix refactoring)
- Phase 6: Final validation with WM_CLASS reference
- Phase 7: Cleanup and documentation

Includes verification commands, rollback plan, and progress tracking.
The plan incorrectly claimed modules would be "auto-imported via dendritic
pattern" by exporting to flake.nixosModules.meta.userDefaults. Investigation
revealed:

- Dendritic pattern auto-discovers FILES, not auto-imports NixOS MODULES
- Host config (system76/imports.nix) explicitly imports specific modules
- 13+ modules contribute to flake.nixosModules.base (aggregator pattern)
- flake-parts merges contributions; host imports base once

Changes:
- Export to flake.nixosModules.base instead of meta.userDefaults
- Rewrite Step 1.3 with accurate aggregator pattern explanation
- Update data flow diagram, comments, and File Changes Summary
- Add base aggregator pattern to Dependencies section
- Update TODO.md section 1.5 with correct export task

This ensures the module options will actually be available in the host config.
1. Remove unused `name` parameter from appRoleModule
   - Submodules in `attrsOf` receive `name` automatically
   - Not needed since validation uses mapAttrsToList for role names
   - Added comment explaining the design choice

2. Fix misleading osConfig verification
   - Removed `useGlobalPkgs` test (contradicted by plan's own statement)
   - Documented that no reliable pre-verification exists
   - Added actual error message users will see if osConfig is missing

3. Fix incorrect documentation references
   - settings-options.section.md covers format generators (JSON/YAML)
   - option-types.section.md has the "Submodule types" section
   - Updated both references to point to correct section
Address three issues and five checklist gaps identified during critical
review against official NixOS documentation:

Issues fixed:
- Replace mkEnableOption // override with explicit mkOption (clearer)
- Redesign helpers as pure functions accepting app data directly
  instead of config + role lookup (improves testability, reduces coupling)
- Document that custom roles require all required fields

Checklist improvements:
- Add custom role test to Phase 6
- Add dendritic discovery verification to Phase 1.6
- Remove fragile hardcoded line numbers from Phase 0.1
- Add concrete strictValidation mismatch example to Phase 4.5
- Clarify that Phase 4 extends Phase 1's module file

Helper function changes:
- Renamed mkAssign -> mkAssignFromApp
- Changed signature from { lib, config } to { lib } (pure)
- Updated all consumer examples to pass app data directly
@Bad3r Bad3r force-pushed the main branch 3 times, most recently from d1081cc to c11b4d5 Compare January 16, 2026 19:59
@Bad3r Bad3r self-assigned this Jan 20, 2026
@Bad3r Bad3r added Backlog Not a priority Enhancement New feature or request labels Jan 20, 2026
@Bad3r Bad3r force-pushed the feat/user-defaults branch from 1b0dc9c to 6482506 Compare January 26, 2026 16:23
@github-project-automation github-project-automation bot moved this to Backlog in ❄️ NixOS Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backlog Not a priority Enhancement New feature or request

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant