this post was submitted on 23 May 2025
5 points (100.0% liked)

Nix / NixOS

2219 readers
7 users here now

Main links

Videos

founded 2 years ago
MODERATORS
 

Whenever I run any command line tools without sudo, they take the settings as in ~/.config and work fine. But whenever I run the same CLI tools with same parameters but with sudo, it falls back to default setting. How can I make this behavior consistent?

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 6 points 6 days ago* (last edited 6 days ago) (3 children)

It's because sudo runs as root, so it's looking for /root/.config You can use -E to keep your current users environment vars, but that doesn't do anything with ~/.config

You can try something like sudo -E HOME="$HOME" XDG_CONFIG_HOME="$XDG_CONFIG_HOME" command_to_run

Or see if you can manually set the config path via args for the command command_to_run --help or man command_to_run then if it does do sudo command_to_run --config_path /home/user/.config for example

Or copy ~/.config to /root (don't simlink because root could screw up permissions). Obviously copying is annoying especially if it changes often

(sudo could mess up the ~/.config permissions also if you do the HOME stuff above. )

[–] [email protected] 1 points 5 days ago* (last edited 5 days ago) (2 children)

Thanks for the heads up! I will try the given solutions.

but that doesn't do anything with ~/.config

What do you exactly mean by this?

[–] MadhuGururajan 2 points 5 days ago

The letter ~ (tilde) is relative to the current user. When you use sudo, you become root. So ~ points to /root. Whereas if you are not using sudo then ~ points to /home/yourname

load more comments (1 replies)
load more comments (1 replies)