yep, more dotfiles
1{ config 2, lib 3, pkgs 4, lpkgs 5, ... 6}: 7 8let 9 flags = config.local.flags; 10 cfg = config.local.fragment.git; 11in 12{ 13 options.local.fragment.git.enable = lib.mkEnableOption '' 14 Git related 15 16 Depends on: 17 - `agenix` fragment: Need for GPG key and GitGuardian API key 18 ''; 19 20 config = lib.mkIf cfg.enable { 21 assertions = [ 22 { assertion = config.local.fragment.agenix.enable; message = "`git` fragment depends on `agenix` fragment"; } 23 ]; 24 25 home.sessionVariables = { 26 # Disable annoying warning message 27 GIT_DISCOVERY_ACROSS_FILESYSTEM = 0; 28 }; 29 30 programs.git = { 31 enable = true; 32 lfs.enable = true; 33 34 userName = "Milo Moisson"; 35 # TODO: this email should be behind a secret or at least a config 36 userEmail = "milo@wiro.world"; 37 38 signing.signByDefault = true; 39 signing.key = "~/.ssh/id_ed25519.pub"; 40 41 # Ignore very specific stuff that is not common to much repos 42 ignores = [ 43 # Direnv cache 44 ".direnv/" 45 # Nix build result link 46 "result" 47 ]; 48 49 aliases = { 50 b = "branch --all"; 51 brm = "branch --delete"; 52 53 ll = "log --graph --oneline --pretty=custom"; 54 lla = "log --graph --oneline --pretty=custom --all"; 55 last = "log -1 HEAD --stat"; 56 57 st = "status --short --branch"; 58 59 cm = "commit --message"; 60 oups = "commit --amend"; 61 62 ui = "!lazygit"; 63 64 rv = "remote --verbose"; 65 66 ri = "rebase --interactive"; 67 ris = "!git ri $(git slc)"; 68 rc = "rebase --continue"; 69 rs = "rebase --skip"; 70 ra = "rebase --abort"; 71 72 # Select commit 73 slc = "!git log --oneline --pretty=custom | fzf | awk '{printf $1}'"; 74 75 a = "add"; 76 al = "add --all"; 77 ac = "add ."; 78 ap = "add --patch"; 79 80 pu = "push"; 81 put = "push --follow-tags"; 82 puf = "push --force-with-lease"; 83 pl = "pull"; 84 85 f = "fetch"; 86 87 s = "switch"; 88 sc = "switch --create"; 89 90 ck = "checkout"; 91 92 cp = "cherry-pick"; 93 94 df = "diff"; 95 dfs = "diff --staged"; 96 dfc = "diff --cached"; 97 98 m = "merge"; 99 100 rms = "restore --staged"; 101 res = "restore"; 102 103 sh = "stash"; 104 shl = "stash list"; 105 sha = "stash apply"; 106 shp = "stash pop"; 107 }; 108 109 hooks = { 110 git-guardian = pkgs.writeShellScript "git-guardian" '' 111 export GITGUARDIAN_API_KEY="$(cat ${config.age.secrets.api-gitguardian.path})" 112 ${lib.getExe' pkgs.ggshield "ggshield"} secret scan pre-commit "$@" 113 ''; 114 }; 115 116 extraConfig = { 117 fetch.prune = true; 118 color.ui = true; 119 init.defaultBranch = "main"; 120 121 rebase.autosquash = true; 122 push.autoSetupRemote = true; 123 pull.rebase = true; 124 125 diff.external = "difft --color=always --display=inline"; 126 127 pretty.custom = "format:%C(red)%h%C(reset) -%C(yellow)%d%C(reset) %s %C(green)(%cd) %C(bold blue)<%an>"; 128 log.date = "human"; 129 130 gpg.format = "ssh"; 131 132 advice = { 133 addEmptyPathspec = false; 134 forceDeleteBranch = false; 135 skippedCherryPicks = false; 136 }; 137 138 # TODO: connect to a SSOT 139 github.user = "mrnossiom"; 140 141 "credentials \"https://github.com\"".helper = "!${lib.getExe pkgs.gh} auth git-credential"; 142 143 # TODO: change to $PROJECTS env var? 144 leaveTool.defaultFolder = "~/Development"; 145 }; 146 }; 147 148 home.packages = (with pkgs; [ 149 glab 150 151 lazyjj 152 153 difftastic 154 ]) ++ lib.optionals (!flags.onlyCached) [ 155 lpkgs.git-leave 156 ]; 157 158 programs.gh.enable = true; 159 160 programs.gh-dash.enable = true; 161 162 programs.lazygit = { 163 enable = true; 164 settings = { 165 gui = { 166 showFileTree = false; 167 showRandomTip = false; 168 showCommandLog = false; 169 border = "single"; 170 }; 171 git = { 172 paging.externalDiffCommand = "difft --color=always"; 173 }; 174 175 # to be declarative or not to be declarative? 176 update.method = "never"; 177 }; 178 }; 179 }; 180}