/ modules / git.nix
git.nix
  1  { pkgs, config, ... }:
  2  let
  3    email = "git@elianiva.my.id";
  4    name = "elianiva";
  5  in
  6  {
  7    programs.gh.enable = true;
  8    programs.lazygit = {
  9      enable = true;
 10      settings = {
 11        gui.theme = {
 12          lightTheme = true;
 13        };
 14        git.pagers = [
 15          {
 16            colorArg = "always";
 17            useConfig = true;
 18            externalDiffCommand = "difft";
 19          }
 20        ];
 21        git.log.order = "default";
 22      };
 23    };
 24    programs.git = {
 25      enable = true;
 26      settings = {
 27        user = {
 28          name = "${name}";
 29          email = "${email}";
 30        };
 31        credential.helper = "cache --timeout 86400";
 32        core = {
 33          compression = 9;
 34          editor = "nvim";
 35        };
 36        diff.external = "difft";
 37        pull.rebase = false;
 38        commit.gpgsign = true;
 39        gpg.format = "ssh";
 40        # use this command to generate the file
 41        # echo "$(git config --get user.email) namespaces=\"git\" $(cat ~/.ssh/<MY_KEY>.pub)" >> ~/.ssh/allowed_signers
 42        gpg.ssh.allowedSignersFile = "${config.home.homeDirectory}/.ssh/allowed_signers";
 43        user.signingkey = "~/.ssh/id_ed25519.pub";
 44        alias = {
 45          lg = "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative";
 46          c = "commit -S -m";
 47          ca = "commit -S --amend";
 48        };
 49        # Why?
 50        # - ghq default is https, this omit -p option for the ssh push
 51        # - https://blog.n-z.jp/blog/2013-11-28-git-insteadof.html
 52        url = {
 53          "git@github.com:" = {
 54            pushInsteadOf = [
 55              "git://github.com/"
 56              "https://github.com/"
 57            ];
 58          };
 59        };
 60        # delta = {
 61        #   line-numbers = true;
 62        #   syntax-theme = "base16";
 63        #   side-by-side = false;
 64        #   file-modified-label = "modified:";
 65        #   light = true;
 66        # };
 67        difftastic = {
 68          background = "light";
 69        };
 70        init.defaultBranch = "master";
 71      };
 72    };
 73  
 74    programs.jjui = {
 75      enable = true;
 76    };
 77  
 78    programs.jujutsu = {
 79      enable = true;
 80      settings = {
 81        user = {
 82          email = "${email}";
 83          name = "${name}";
 84        };
 85        signing = {
 86          behavior = "own";
 87          backend = "ssh";
 88          key = "~/.ssh/id_ed25519";
 89          backends.ssh.allowed-signers = "${config.home.homeDirectory}/.ssh/allowed_signers";
 90        };
 91        revsets = {
 92          log = "::"; # show all commits by default
 93        };
 94        aliases ={
 95          # Bring nearest bookmark up to recent commit
 96          tug = ["bookmark" "move" "--from" "heads(::@- & bookmarks())" "--to" "@-"];
 97          # Retrunk:
 98          # `jj rebase -d 'trunk()' is shorthand for `jj rebase -b @ -d 'trunk()'`
 99          # What it does:
100          # `-b @` rebases the entire branch that the current @ is on relative to the destination
101          # `-d trunk()` sets the destination. trunk() finds the most recent `main | master | whatever main branch`
102          retrunk = ["rebase" "-b" "@" "-d" "trunk()"];
103          # Logs last 10 revisions
104          lg = ["log" "-r" "all()" "-n" "10"];
105          # Compare current revision with the previous one
106          compare = ["diff" "--from" "@-" "--to" "@" "--git"];
107        };
108        ui = {
109          paginate = "never";
110          conflict-marker-style = "git";
111          default-command = "log";
112          diff-formatter = [
113            "difft"
114            # it's bad, better to disable it since it causes confusion
115            # see: https://github.com/Wilfred/difftastic/issues/275
116            "--syntax-highlight=off"
117            "--color=always"
118            "--display=side-by-side-show-both"
119            "$left"
120            "$right"
121          ];
122        };
123      };
124    };
125  }