niksos/modules/cli/git.nix
2024-08-06 17:46:57 +02:00

74 lines
2.2 KiB
Nix

{
config,
lib,
pkgs,
...
}: let
cfg = config.poz.programs.git;
inherit (config.poz.other.system) username;
inherit (lib.meta) getExe;
inherit (lib.modules) mkIf;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) nullOr str;
delta = getExe pkgs.delta;
in {
options.poz.programs.git = {
enable = mkEnableOption "git";
userName = mkOption {
type = nullOr str;
default = null;
description = "git username";
};
userEmail = mkOption {
type = nullOr str;
default = null;
description = "git email";
};
signingKey = mkOption {
type = nullOr str;
default = null;
description = "git commit signing key";
};
editor = mkOption {
type = str;
default = "$EDITOR";
description = "commit message editor";
};
defaultBranch = mkOption {
type = str;
default = "main";
description = "default git branch";
};
};
config = mkIf cfg.enable {
home-manager.users.${username} = {
programs.git = {
enable = true;
inherit (cfg) userName userEmail;
extraConfig = {
core = {
inherit (cfg) editor;
pager = "${delta}";
};
init.defaultBranch = cfg.defaultBranch;
push.autoSetupRemote = true;
commit = {
verbose = true;
gpgsign = cfg.signingKey != null;
};
gpg.format = "ssh";
user.signingkey = mkIf (cfg.signingKey != null) "key::${cfg.signingKey}";
merge.conflictstyle = "zdiff3";
interactive.diffFilter = "${delta} --color-only";
diff.algorithm = "histogram";
transfer.fsckobjects = true;
fetch.fsckobjects = true;
receive.fsckobjects = true;
};
};
};
};
}