about summary refs log tree commit diff
path: root/home/git/default.nix
blob: 557485bc612d8808fa71c347193bfe92ff06c783 (plain) (blame)
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
{ lib, config, pkgs, ... }:

let
  cfg = config.my.home.git;
  sshPub = builtins.fromTOML (builtins.readFile ../../configs/ssh-pubkeys.toml);
in
{
  options.my.home.git = with lib; {
    enable = mkEnableOption "git configuration";
  };

  config = lib.mkIf cfg.enable {
    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;
      aliases = {
        s = "status --short --branch";
        amend = "commit --amend --no-edit";
      };
      signing = {
        key = "key::${sshPub.ykey-laptop}";
        signByDefault = true;
      };
      extraConfig = {
        core.whitespace = "trailing-space,space-before-tab";
        color.ui = "true";

        gpg = {
          format = "ssh";
          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";
      };
      userName = "Franck Cuny";
      userEmail = "franck@fcuny.net";
      extraConfig = {
        "credential \"https://github.com\"" = { username = "fcuny"; };
        "credential \"https://git.fcuny.net\"" = { username = "fcuny"; };
      };
      ignores = [
        "*.elc"
        "*.iml"
        "*.o"
        "*.pyc"
        "*.pyo"
        "*pyc"
        "*~"
        ".DS_Store"
        ".\\#"
        ".dir-locals.el"
        ".direnv/*"
        ".idea"
        ".projectile"
        ".pytest_cache/"
        "/env/*"
        "Icon"
        "TAGS"
        "\\#*\\#"
        "tags"
      ];
    };
    xdg.dataFile."git/commit.template" = { source = ./commit.template; };
    home.packages = with pkgs; [ tools.git-blame-stats gitAndTools.pre-commit ];
  };
}