aboutsummaryrefslogtreecommitdiffstats
path: root/modules/development/git/default.nix
blob: 8e27d3ba8fb42e47a2485a689c76493c7f568b6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Distributed version control system
{
  config,
  lib,
  pkgs,
  ...
}:
{
  imports = [
    ./assertions.nix
  ]
  ++ lib.optional (builtins.pathExists ../../private/git.nix) ../../private/git.nix;

  options.development.git = {
    enable = lib.mkEnableOption "Enables git.";

    package = lib.mkOption {
      type = lib.types.package;
      readOnly = true;
      default = config.programs.git.package;
      description = "The git package to use.";
    };

    username = lib.mkOption {
      type = lib.types.str;
      description = "Git username.";
    };

    email = lib.mkOption {
      type = lib.types.str;
      description = "Git email.";
    };

    useSSH = lib.mkEnableOption "Use SSH instead of HTTPS for common git platforms.";

    signing = {
      key = lib.mkOption {
        type = lib.types.nullOr lib.types.str;
        default = null;
        description = "GPG key ID used for signing commits.";
      };

      signByDefault = lib.mkEnableOption "Sign commits by default.";
    };
  };

  config = lib.mkIf config.development.git.enable {
    home.packages = with pkgs; [
      git-graph
      gawk
    ];

    xdg.configFile."git-graph/models/custom.toml".text = ''
      persistence = [
        '^(master|main|trunk)$',
        '^(develop|dev)$',
        '^feature.*$',
        '^release.*$',
        '^hotfix.*$',
        '^bugfix.*$',
      ]

      order = [
        '^(master|main|trunk)$',
        '^(hotfix|release).*$',
        '^(develop|dev)$',
      ]

      [terminal_colors]
      matches = [
        ['^(master|main|trunk)$', ['bright_blue']],
        ['^(develop|dev)$', ['bright_yellow']],
        ['^(feature|fork/).*$', ['bright_magenta', 'bright_cyan']],
        ['^release.*$', ['bright_green']],
        ['^(bugfix|hotfix).*$', ['bright_red']],
        ['^tags/.*$', ['bright_green']],
      ]
      unknown = ['bright_white', 'bright_red', 'bright_green', 'bright_yellow', 'bright_blue', 'bright_magenta', 'bright_cyan']

      [svg_colors]
      matches = [
        ['^(master|main|trunk)$', ['blue']],
        ['^(develop|dev)$', ['orange']],
        ['^(feature|fork/).*$', ['magenta', 'cyan']],
        ['^release.*$', ['green']],
        ['^(bugfix|hotfix).*$', ['red']],
        ['^tags/.*$', ['gray', 'purple', 'teal', 'brown']]
      ]
      unknown = ['gray', 'purple', 'teal', 'brown']
    '';

    programs.git = {
      enable = true;
      signing = {
        key = config.development.git.signing.key;
        signByDefault = config.development.git.signing.signByDefault;
      };
      settings =
        lib.recursiveUpdate
          {
            user = {
              name = config.development.git.username;
              email = config.development.git.email;
            };
            core.askPass = "";
            alias = {
              log-graph = "!git-log-graph";
              log-graph-embed = "!GIT_LOG_GRAPH_EMBED=1 git-log-graph";
            };
          }
          (
            lib.optionalAttrs config.development.git.useSSH {
              url."git@github.com:".insteadOf = "https://github.com/";
              url."git@gitlab.com:".insteadOf = "https://gitlab.com/";
              url."git@bitbucket.org:".insteadOf = "https://bitbucket.org/";
              url."git@codeberg.org:".insteadOf = "https://codeberg.org/";
              url."git@git.sr.ht:".insteadOf = "https://git.sr.ht/";
            }
          );
    };
  };
}