Git module options in NixOS

I have this basic configuration. But I want to know the possible extensions over this.

programs.git = {
    enable = true;
    package = pkgs-unstable.git;
    config = {
      user.name = "somerandomname";
      user.email = "somerandommail@gmail.com";
      init.defaultBranch = "main";
      core.editor = "micro"
    };
  };

I could only see limited options in this:
https://search.nixos.org/options?channel=25.05&show=programs.git.config&from=0&size=50&sort=relevance&type=packages&query=programs.git

and the link in it:

I could only see very limited examples here. Any way or anywhere else to see all the options?

nix-shell -p git --command 'man git-config' should work if you don’t have git installed currently.

What the module here does is a bit obscured by the extra handling for ordering and lists.
The relevant parts are the type declaration and further down the usage of the config setting.

These two specify that “config” is a freeform value that is translated to the corresponding ini format verbatim.
This means that whatever you write in those sections are the exact values that git will use in its configuration format.
One comment further up points to the man page of git config which is where git documents its own options, which is the one relevant to you, since you are not dealing with NixOS specific options.

There are only slight differences in handlings of e.g. list ordering which shouldn’t matter for the most part, otherwise most things work as expected (such as booleans being correctly converted).
The NixOS manual section on this topic has more information (but feel free to ask in this thread if you have additional questions).

2 Likes

So it’s kind of like a RAW format just concatenated via the nixos git options. Am I right?

Also I see that nix options uses lower Camel case. So wonder if that affects anything with the actual options🤔

The convention for git options is also camel, but the point is you just bang in verbatim what you see in man git-config for instance

  extraConfig = {
    branch.sort = "-committerdate";
    column.ui = "auto";
    diff = {
      algorithm = "histogram";
      colorMoved = "plain";
      mnemonicPrefix = true;
      renames = true;
    };
    fetch.prune = true;
    gitlab.user = "bme";
    init.defaultBranch = "master";
    pull.rebase = true;
    rebase = {
      autoSquash = true;
      autoStash = true;
      updateRefs = true;
    };
    rerere = {
      enabled = true;
      rerere.autoupdate = true;
    };
  };
}

produces

[branch]
	sort = "-committerdate"

[column]
	ui = "auto"

[diff]
	algorithm = "histogram"
	colorMoved = "plain"
	mnemonicPrefix = true
	renames = true

[fetch]
	prune = true

[init]
	defaultBranch = "master"

[pull]
	rebase = true

[rebase]
	autoSquash = true
	autoStash = true
	updateRefs = true

[rerere]
	enabled = true

[rerere "rerere"]
	autoupdate = true
2 Likes

Thanks a lot. Got it. :handshake:

@ksvivek mark one of the comments here as a solution if solved

1 Like