about summary refs log tree commit diff
path: root/modules/common/git.nix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/common/git.nix')
-rw-r--r--modules/common/git.nix117
1 files changed, 117 insertions, 0 deletions
diff --git a/modules/common/git.nix b/modules/common/git.nix
new file mode 100644
index 0000000..2c1dd1f
--- /dev/null
+++ b/modules/common/git.nix
@@ -0,0 +1,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
+          '';
+        };
+      };
+    };
+  };
+}

Consider giving Nix/NixOS a try! <3