1 { config, lib, pkgs, ... }:
4 cfg = config.programs.git;
10 enable = lib.mkEnableOption "git, a distributed version control system";
12 package = lib.mkPackageOption pkgs "git" {
16 config = lib.mkOption {
20 gitini = attrsOf (attrsOf anything);
22 either gitini (listOf gitini) // {
25 config = builtins.foldl'
26 (acc: { value, ... }@x: acc // (if builtins.isList value then {
27 ordered = acc.ordered ++ value;
29 unordered = acc.unordered ++ [ x ];
37 [ (gitini.merge loc config.unordered) ] ++ config.ordered;
41 init.defaultBranch = "main";
42 url."https://github.com/".insteadOf = [ "gh:" "github:" ];
45 Configuration to write to /etc/gitconfig. A list can also be
46 specified to keep the configuration in order. For example, setting
47 `config` to `[ { foo.x = 42; } { bar.y = 42; }]` will put the `foo`
48 section before the `bar` section unlike the default alphabetical
49 order, which can be helpful for sections such as `include` and
50 `includeIf`. See the CONFIGURATION FILE section of git-config(1) for
56 enable = lib.mkEnableOption "automatically sourcing git-prompt.sh. This does not change $PS1; it simply provides relevant utility functions";
60 enable = lib.mkEnableOption "git-lfs (Large File Storage)";
62 package = lib.mkPackageOption pkgs "git-lfs" { };
67 config = lib.mkMerge [
68 (lib.mkIf cfg.enable {
69 environment.systemPackages = [ cfg.package ];
70 environment.etc.gitconfig = lib.mkIf (cfg.config != [ ]) {
71 text = lib.concatMapStringsSep "\n" lib.generators.toGitINI cfg.config;
74 (lib.mkIf (cfg.enable && cfg.lfs.enable) {
75 environment.systemPackages = [ cfg.lfs.package ];
76 programs.git.config = {
78 clean = "git-lfs clean -- %f";
79 smudge = "git-lfs smudge -- %f";
80 process = "git-lfs filter-process";
85 (lib.mkIf (cfg.enable && cfg.prompt.enable) {
86 environment.interactiveShellInit = ''
87 source ${cfg.package}/share/bash-completion/completions/git-prompt.sh
92 meta.maintainers = with lib.maintainers; [ figsoda ];