I assume you mean it says something like:
error: could not lock config file /home/tlater/.config/git/config: Read-only file system
That’s not “it requires root”, it’s just trying to edit a file on a read-only file system (which is prohibited, and not even root can do that). The difference is significant; nothing really “requires root”, and thinking that way is harmful.
Think instead about what it means to edit this file with
git config. It means modifying the file created by your nix config after the fact. Do you really want to do that? It breaks the reproducibility, and potentially breaks nix’ cache, because you would also change the file hash, yet nix’ cache would have a record of a different hash. I’d cautiously say that you probably don’t intend to break nix
I don’t want to mess with permissions or anything in there.
is the correct call, I just want to make this explicit - don’t think in “requiring root” terms, think in terms of what you want to do, why only the root user is allowed to do it, and whether forcing it by becoming the root user is appropriate. Often when there is a file permissions issue, there is a good reason for it, and using
sudo to circumvent it is bad practice that may bite you in the future.
All of that said, you can pretty easily translate
git config commands to
For example this command:
git config --global init.defaultBranch main
programs.git.extraConfig.init.defaultBranch = "main";
both of those translate to:
defaultBranch = "main"
The setting names just translate to attrsets, and then TOML-style dictionaries in the git config
For more complex settings, like
pushInsteadOf, where there is a parameter on the key (I have no idea how to use
git config to set these, frankly), you can use nested attrsets:
programs.git.extraConfig.url."ssh://git@".pushInsteadOf = "https://";
This translates to the following git config:
pushInsteadOf = "https://"
Hope that helps - in a nutshell, the
git config stuff is anyway just syntax around setting keys and values in a git config file, you can do this really easily with nix.
The alternative is not configuring git via nix, or instructing home-manager to install a hand-made git config file (which you could pre-make with
git config commands). I’d recommend the nix approach, though.