Skip to content

Conversation

@danimalquackers
Copy link
Contributor

Closes #280. Please be aware I used Antigravity editor (Gemini-based) to generate the code and some tests, and made slight tweaks to the output.

This PR adds support for environment variables in the rewrite parameter of a rule, for example to specify $XDG_CACHE_HOME and similar XDG variables in the rewrite path. It also adds tests to mod.rs for standard/tilde paths and environment variables requiring expansion. It preserves tildes to maintain the same behavior as before by using shellexpand::env, which only expands environment variables on evaluation, instead of shellexpand::full.

The newly added tests all pass:

$ cargo test config
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.13s
     Running unittests src/main.rs (target/debug/deps/boxxy-b622425082ce7db5)

running 6 tests
test config::tests::test_simple_cli ... ok
test config::tests::test_expand_rewrite_cli ... ok
test config::tests::test_tilde_cli ... ok
test config::tests::test_tilde_file ... ok
test config::tests::test_expand_rewrite_file ... ok
test config::tests::test_simple_file ... ok

test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 4 filtered out; finished in 0.00s

And I have been able to run it successfully on my NixOS system using this home-manager configuration:

  # Redirect temp/config dirs for some apps
  programs.boxxy = {
    enable = true;

    # Use custom build with environment variable support
    package = pkgs.rustPlatform.buildRustPackage rec {
      pname = "boxxy";
      version = "0.8.5-env";
      src = pkgs.fetchFromGitHub {
        owner = "danimalquackers";
        repo = "boxxy";
        rev = "9dfa248d29efb973130ae4ee88df42261d9144b0";
        hash = "sha256-VtOtd0Cu8rJMQ3finWnWp/+ymCGmOkIA8tlA9EOWESM=";
      };
    
      # This handles the Cargo.lock dependencies
      cargoHash = "sha256-g6qSV/9UBr+UBiI1/rS3dgi0H1tbc/SDIHL3y3IVog4=";
      nativeBuildInputs = [ pkgs.pkg-config ];
    };

    rules = [
      {
        name = "Gemini CLI";
        target = "~/.gemini";
        rewrite = "$XDG_CONFIG_HOME/gemini";
      }
      {
        name = "Ansible";
        target = "~/.ansible";
        rewrite = "$XDG_DATA_HOME/ansible";
      }
      {
        name = "Terraform";
        target = "~/.terraform.d";
        rewrite = "$XDG_CACHE_HOME/terraform";
      }
    ];
  };

Copy link
Owner

@queer queer left a comment

Choose a reason for hiding this comment

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

Awesome stuff, thanks! I should really fix the CI configs someday...

@queer queer merged commit 4bd9377 into queer:mistress Jan 18, 2026
0 of 11 checks passed
@danimalquackers
Copy link
Contributor Author

I'm afraid one of them might be my fault, since I installed tempfile the Cargo.lock version was bumped and it looks like the Actions runner uses an older version that doesn't support that.

@queer
Copy link
Owner

queer commented Jan 18, 2026

It's not on you; I've not had the energy to update them for a long time.

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.

Can't use environment variables in rewrite

2 participants