blob: 1e301665957e972637b75dc9fa64b2e39df48f86 [file] [log] [blame]
{
inputs,
system,
config,
lib,
pkgs,
...
}:
{
options.chimera.git = {
gitReview.enable = lib.mkEnableOption "Enable git review";
delta.enable = lib.mkEnableOption "Enable delta, an alternative pager for git diffs that highlights syntax";
stgit.enable = lib.mkEnableOption "Install StGit, a tool that makes working with stacked patches easier";
jj.enable = lib.mkEnableOption "Install jj, a git-compatible VCS, allowing powerful features, performance and stability improvements ontop of git";
radicle.enable = lib.mkEnableOption "Install Radicle, a peer-to-peer git forge";
auth = {
clicksUsername = lib.mkOption {
type = lib.types.str;
description = "Username for Clicks Gerrit";
};
};
gpg = {
enable = lib.mkEnableOption "Enable signing with gpg";
commit = lib.mkOption {
type = lib.types.bool;
description = "Enable gpg signing for commits by default";
default = true;
};
push = lib.mkOption {
type = lib.types.bool;
description = "Enable gpg signing for pushes by when asked by the server";
default = true;
};
};
};
config = let
urlReplacements = {
af = {
http = "https://git.auxolotl.org/";
ssh = "ssh://forgejo@git.auxolotl.org/";
};
aur = {
http = "https://aur.archlinux.org/";
ssh = "ssh://aur@aur.archlinux.org/";
};
aux = {
http = "https://git.auxolotl.org/auxolotl/";
ssh = "ssh://forgejo@git.auxolotl.org/auxolotl/";
};
cb = {
http = "https://codeberg.org/";
ssh = "ssh://git@codeberg.org/";
};
clicks = {
http = "https://git.clicks.codes/";
ssh = "ssh://${config.chimera.git.auth.clicksUsername}@ssh.clicks.codes:29418/";
};
fdo = {
http = "https://gitlab.freedesktop.org/";
ssh = "ssh://git@gitlab.freedesktop.org/";
};
gh = {
http = "https://github.com/";
ssh = "ssh://git@github.com/";
};
gl = {
http = "https://gitlab.com/";
ssh = "ssh://git@gitlab.com/";
};
kde = {
http = "https://invent.kde.org/";
ssh = "ssh://git@invent.kde.org/";
};
lix = {
http = "https://git.lix.systems/";
ssh = "ssh://git@git.lix.systems/";
};
srht = {
http = "https://git.sr.ht/";
ssh = "git@git.sr.ht:";
};
};
replacementToHTTPInsteadOf = name: urls: {
name = urls.http;
value.insteadOf = "${name}:";
};
replacementToSSHInsteadOf = name: urls: {
name = urls.ssh;
value = {
insteadOf = "p:${name}:";
pushInsteadOf = [ urls.http "${name}:" ];
};
};
replacementURLList =
(lib.mapAttrsToList replacementToHTTPInsteadOf urlReplacements)
++ (lib.mapAttrsToList replacementToSSHInsteadOf urlReplacements);
replacementURLs = builtins.listToAttrs replacementURLList;
in {
chimera.gpg.enable = lib.mkIf config.chimera.git.gpg.enable true;
home.packages =
(if config.chimera.git.gitReview.enable then [ pkgs.git-review ] else [ ])
++ (if config.chimera.git.stgit.enable then [ pkgs.stgit ] else [ ])
++ (if config.chimera.git.jj.enable then [ inputs.jujutsu.packages.${system}.jujutsu ] else [ ])
++ (if config.chimera.git.radicle.enable then [ pkgs.radicle-node ] else [ ]);
programs.zsh.shellAliases =
if config.chimera.git.gitReview.enable then { "gr!" = "git review"; } else { };
programs.bash.shellAliases =
if config.chimera.git.gitReview.enable then { "gr!" = "git review"; } else { };
programs.git = {
enable = true;
delta = {
enable = config.chimera.git.delta.enable;
options.light = lib.mkIf config.chimera.theme.catppuccin.enable (
config.chimera.theme.catppuccin.style == "Latte"
);
};
extraConfig = {
init.defaultBranch = "main";
advice.skippedcherrypicks = false;
commit.gpgsign = lib.mkIf config.chimera.git.gpg.enable config.chimera.git.gpg.commit;
credential.helper = "cache";
core = {
repositoryformatversion = 0;
filemode = true;
# TODO: from git docs, should we provide an option for this?: NOTE: this is a possibly dangerous operation; do not use it unless you understand the implications (see git-rebase[1] for details).
};
push = {
autoSetupRemote = true;
gpgSign = lib.mkIf config.chimera.git.gpg.enable (
if config.chimera.git.gpg.push then "if-asked" else false
);
};
pull.rebase = "merges";
rebase.updateRefs = true;
url = replacementURLs;
merge.conflictstyle = "diff3";
trailer.ifexists = "addIfDifferent";
};
};
};
}