about summary refs log tree commit diff
path: root/home/profiles/git.nix
diff options
context:
space:
mode:
Diffstat (limited to 'home/profiles/git.nix')
-rw-r--r--home/profiles/git.nix73
1 files changed, 73 insertions, 0 deletions
diff --git a/home/profiles/git.nix b/home/profiles/git.nix
new file mode 100644
index 0000000..de2cbf6
--- /dev/null
+++ b/home/profiles/git.nix
@@ -0,0 +1,73 @@
+{ self, lib, pkgs, config, ... }:
+let
+  sshPub = builtins.fromTOML (
+    builtins.readFile "${self}/configs/ssh-pubkeys.toml"
+  );
+in
+{
+  home.file.".ssh/allowed_signers".text = lib.concatMapStrings (x: "franck@fcuny.net ${x}\n") (with sshPub; [ aptos work git ykey-laptop ]);
+
+  programs.git = {
+    enable = true;
+    userName = "Franck Cuny";
+    userEmail = "franck@fcuny.net";
+
+    signing = {
+      key = "key::${sshPub.ykey-laptop}";
+      signByDefault = true;
+    };
+
+    extraConfig = {
+      core.whitespace = "trailing-space,space-before-tab";
+      color.ui = "true";
+
+      diff.age.textconv = "${pkgs.age}/bin/age --identity ${config.home.homeDirectory}/.age/key.txt --decrypt";
+
+      gpg.format = "ssh";
+      gpg.ssh.allowedSignersFile = "~/.ssh/allowed_signers";
+
+      # abort if the remote branch does not match the local one
+      push.default = "simple";
+
+      init.defaultBranch = "main";
+
+      pull.rebase = true;
+      rebase = {
+        # Automatically create a temporary stash entry before the
+        # operation begins, and apply it after the operation ends.
+        autoStash = true;
+        # Print a warning if some commits are removed
+        missingCommitsCheck = "warn";
+      };
+
+      branch.autosetuprebase = "remote";
+      branch.sort = "authordate";
+
+      commit.template = "${config.xdg.dataHome}/git/commit.template";
+    };
+
+    ignores = [
+      "*~"
+      ".direnv"
+    ];
+  };
+
+  xdg.dataFile."git/commit.template".source = pkgs.writeText "commit.template" ''
+
+    # (If applied, this commit will...) <subject>
+
+    # Explain why this change is being made
+
+    # --- COMMIT END ---
+    # Remember to
+    #    Use the imperative mood, present tense: `change' not `changed' nor `changes'
+    #    Do not end the subject line with a period
+    #    Use the body to explain what and why vs. how
+    #    Can use multiple lines with "-" for bullet points in body
+'';
+
+  home.packages = with pkgs; [
+    tools.git-blame-stats
+    gitAndTools.pre-commit
+  ];
+}