Global cargo configuration

Open
#9,441 2 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
tooling

Research direction

Start in src/cargo/util/config/mod.rs, where Cargo searches for configuration files and the proposed system-wide path is shown. Read the existing configuration traversal and determine the expected Unix and Windows behavior before adding tests and documentation. Done means administrators can provide system-wide defaults through the supported location without disrupting existing configuration precedence.

Written by the indexing model from the issue text.

Description

A-configuration C-feature-request S-needs-design

Describe the problem you are trying to solve
I'm attempting to configure cargo (specifically, custom registries) on large, shared, many-user Linux servers. As far as I can tell, the best way to do that now is to create a file at /.cargo/config, which will be read by the logic that walks up the filesystem tree searching for a .cargo directory.

Describe the solution you'd like
Cargo should also read a config file from /etc/, similar to other Unix-y tools, allowing administrators to set system-wide defaults.

Notes
I believe that a diff such as the following accomplishes this, although it's obviously missing documentation, tests, and perhaps sane behavior on Windows:

diff --git a/src/cargo/util/config/mod.rs b/src/cargo/util/config/mod.rs
index b9921dfee..57862ffdc 100644
--- a/src/cargo/util/config/mod.rs
+++ b/src/cargo/util/config/mod.rs
@@ -1302,6 +1302,15 @@ impl Config {
             }
         }

+        if cfg!(unix) {
+            // Also check system-wide config
+            if let Some(path) = self.get_file_path(Path::new("/etc/cargo"), "config", true)? {
+                if !stash.contains(&path) {
+                    walk(&path)?;
+                }
+            }
+        }
+
         Ok(())
     }

If there's interest in such a feature, I'm glad to do the work to write tests & documentation; if there's not interest, I'd be interested in how other people are administering system-wide shared defaults.

NOTE: I initially asked about this at https://users.rust-lang.org/t/how-to-manage-system-wide-cargo-configuration-for-many-users/59160

Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rust-lang/cargo

All issues in rust-lang/cargo

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.