Skip to content

feat(config): RLEDGER_CONFIG env var + macOS XDG config fallback (#1616) - #1650

Merged
robcohen merged 1 commit into
mainfrom
feat/rledger-config-env
Jun 30, 2026
Merged

robcohen merged 1 commit into
mainfrom
feat/rledger-config-env

Conversation

@robcohen

Copy link
Copy Markdown
Member

Addresses discussion #1616 — cross-platform config location for chezmoi/home-manager users.

Problem

rledger resolves its user config via dirs::config_dir() (platform-native): ~/.config on Linux but ~/Library/Application Support on macOS, and dirs ignores XDG_CONFIG_HOME on macOS. So a single ~/.config/rledger/config.toml couldn't work on both platforms, and there was no env-var override for the config location.

Fix

user_config_path() now resolves in precedence order:

  1. $RLEDGER_CONFIG — an explicit config file path (~ and $VAR expanded). Highest precedence; the clean answer for chezmoi/home-manager.
  2. The platform-native dirs::config_dir()/rledger/config.toml.
  3. macOS only: $XDG_CONFIG_HOME / ~/.config/rledger/config.toml when it exists — so an XDG-style dotfile "just works" on macOS too, with no env var.

The override logic is a pure, unit-tested helper (resolve_user_config_path) so it's testable without env mutation (edition 2024 makes set_var unsafe/flaky). config_cmd's env-var help documents RLEDGER_CONFIG.

Tests / verify

New unit tests cover the $RLEDGER_CONFIG override (absolute + ~-expansion) and the no-override native path. cargo build/test/clippy (-D warnings)/fmt clean.

🤖 Generated with Claude Code

Cross-platform config-location gap reported in discussion #1616: rledger resolves
its user config via dirs::config_dir() (platform-native), which is ~/.config on
Linux but ~/Library/Application Support on macOS — and dirs ignores
XDG_CONFIG_HOME on macOS. So a single ~/.config/rledger/config.toml managed by
chezmoi/home-manager couldn't work on both, and there was no env override.

user_config_path() now resolves in this order:
1. $RLEDGER_CONFIG — explicit config file path (~ and $VAR expanded); highest
   precedence, ideal for cross-platform dotfile managers.
2. The platform-native dirs::config_dir()/rledger/config.toml.
3. macOS only: $XDG_CONFIG_HOME / ~/.config/rledger/config.toml when present, so
   an XDG-style dotfile works on macOS too without any env var.

The override resolution is a pure, unit-tested helper (resolve_user_config_path);
the env-var help (config_cmd) documents RLEDGER_CONFIG.

Addresses discussion #1616.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner June 30, 2026 15:47
Copilot AI review requested due to automatic review settings June 30, 2026 15:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a cross-platform override and fallback strategy for locating rledger’s user config, addressing macOS’s non-XDG default config directory behavior and enabling a single canonical config path for dotfile managers.

Changes:

  • Add $RLEDGER_CONFIG as the highest-precedence override for the user config file path (with ~/ + $VAR expansion).
  • On macOS, add an XDG-style fallback ($XDG_CONFIG_HOME / ~/.config) when the platform-native config path doesn’t exist.
  • Document the new env var in config path output and add unit tests for the override/native behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
crates/rustledger/src/config.rs Implements config-path precedence logic (env override + macOS XDG fallback) and adds unit tests.
crates/rustledger/src/cmd/config_cmd.rs Documents RLEDGER_CONFIG in the config path command output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/rustledger/src/config.rs Resolved
Comment thread crates/rustledger/src/config.rs Resolved
Comment thread crates/rustledger/src/config.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 32.1ms ± 1.6ms 23.6 MB
beancount 868.7ms ± 6.7ms 50.7 MB
Comparison 27.1x faster 2.1x less

vs main branch (2026-06-30)

Metric main this PR Change
Time 42ms 32.1ms -23.6% 🟢
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 100%
Total Files 792
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger/src/cmd/config_cmd.rs 0.00% 3 Missing ⚠️
crates/rustledger/src/config.rs 96.55% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@robcohen
robcohen merged commit 565d57b into main Jun 30, 2026
42 checks passed
@robcohen
robcohen deleted the feat/rledger-config-env branch June 30, 2026 16:21
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.

2 participants