summaryrefslogtreecommitdiff
path: root/modules/common/git.nix
blob: 2c1dd1f82cc96596f2b2bd82648d2c5b7f577388 (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
{
  config,
  lib,
  pkgs,
  ...
}:
with lib; let
  cfg = config.nixfiles.modules.git;
in {
  options.nixfiles.modules.git.client.enable =
    mkEnableOption "Git client";

  config = mkIf cfg.client.enable {
    hm = {
      home.packages = with pkgs; [glab hut];

      programs = {
        git = {
          enable = true;

          package = pkgs.git.override {
            doInstallCheck = false;
            pythonSupport = false;
            sendEmailSupport = true;
            withLibsecret = false;
            withSsh = true;
          };

          userName = my.fullname;
          userEmail = my.email;
          signing = {
            inherit (my.pgp) key;
            signByDefault = true;
          };

          extraConfig =
            {
              advice.detachedHead = false;
              color.ui = true;
              core.whitespace = "trailing-space";
              diff = {
                mnemonicPrefix = true;
                renames = "copies";
                submodule = "log";
              };
              init.defaultBranch = "master";
              status.submoduleSummary = true;
            }
            // mapAttrs'
            (n: v: nameValuePair ''url "git@${v}:"'' {insteadOf = "${n}:";}) {
              "alpine" = "gitlab.alpinelinux.org";
              "bitbucket" = "bitbucket.com";
              "codeberg" = "codeberg.org";
              "freedesktop" = "gitlab.freedesktop.org";
              "github" = "github.com";
              "gitlab" = "gitlab.com";
              "gnome" = "gitlab.gnome.org";
              "haskell" = "gitlab.haskell.org";
              "kde" = "invent.kde.org";
              "notabug" = "notabug.org";
              "opencode" = "opencode.net";
              "sourcehut" = "git.sr.ht";
              "videolan" = "code.videolan.org";
            };

          aliases = let
            git = "${config.hm.programs.git.package}/bin/git";
            curl = "${pkgs.curl}/bin/curl";
          in {
            fuck = "!${git} reset --hard && ${git} clean -fdx";
            gud = ''commit -m "git gud"'';
            wtc = "!${curl} -sq whatthecommit.com/index.txt | ${git} commit -F -";
          };

          # All helper tools/editor generated files should go here. This must
          # be kept relatively clean and void of any project-specific residual
          # files.
          ignores = [
            "*~"
            ".DS_Store"
            ".cache/clangd/"
            ".ccls-cache/"
            ".dir-locals.el"
            ".gdb_history"
            ".netrwhist"
            ".projectile"
            "[._]*.s[a-v][a-z]"
            "[._]*.sw[a-p]"
            "[._]s[a-rt-v][a-z]"
            "[._]ss[a-gi-z]"
            "[._]sw[a-p]"
            "\#*\#"
            "compile_commands*.json"
            "cscope.*"
            "vgcore.*"
          ];
        };

        gh = {
          enable = true;
          settings.git_protocol = "ssh";
        };

        bash = {
          shellAliases = {
            gl = "${pkgs.glab}/bin/glab";
            ht = "${pkgs.hut}/bin/hut";
          };
          initExtra = mkAfter ''
            _complete_alias gl __start_glab glab
            _complete_alias ht __start_hut hut
          '';
        };
      };
    };
  };
}