niksos/modules/cli/git.nix

80 lines
2.4 KiB
Nix
Raw Normal View History

2023-09-08 16:10:15 +02:00
{
2023-10-13 21:04:24 +02:00
config,
lib,
2024-02-17 17:43:17 +01:00
pkgs,
2023-09-08 16:10:15 +02:00
...
2024-05-05 12:38:40 +02:00
}: let
2024-07-15 23:18:25 +02:00
cfg = config.poz.programs.git;
inherit (config.poz.other.system) username;
2024-05-05 12:38:40 +02:00
2024-07-24 18:47:53 +02:00
inherit (lib.meta) getExe;
2024-07-25 11:45:44 +02:00
inherit (lib.modules) mkIf;
inherit (lib.options) mkEnableOption mkOption;
2024-08-28 21:50:56 +02:00
inherit (lib.types) attrs listOf nullOr str;
delta = getExe pkgs.delta;
2023-10-13 21:04:24 +02:00
in {
2024-07-15 23:18:25 +02:00
options.poz.programs.git = {
2023-10-13 21:04:24 +02:00
enable = mkEnableOption "git";
userName = mkOption {
2024-05-05 12:38:40 +02:00
type = nullOr str;
default = null;
2023-10-13 21:04:24 +02:00
description = "git username";
};
userEmail = mkOption {
2024-05-05 12:38:40 +02:00
type = nullOr str;
default = null;
2023-10-13 21:04:24 +02:00
description = "git email";
};
signingKey = mkOption {
2024-05-05 12:38:40 +02:00
type = nullOr str;
default = null;
2023-10-13 21:04:24 +02:00
description = "git commit signing key";
};
editor = mkOption {
2024-05-05 12:38:40 +02:00
type = str;
2024-02-15 10:50:45 +01:00
default = "$EDITOR";
2023-10-13 21:04:24 +02:00
description = "commit message editor";
};
defaultBranch = mkOption {
2024-05-05 12:38:40 +02:00
type = str;
default = "main";
2023-10-13 21:04:24 +02:00
description = "default git branch";
};
2024-08-28 21:50:56 +02:00
includes = mkOption {
type = listOf attrs;
default = [];
description = "passthrough to the hm module";
};
2023-10-13 21:04:24 +02:00
};
config = mkIf cfg.enable {
home-manager.users.${username} = {
2023-10-13 21:04:24 +02:00
programs.git = {
enable = true;
2024-08-28 21:50:56 +02:00
inherit (cfg) userName userEmail includes;
extraConfig = {
core = {
2024-04-14 18:49:29 +02:00
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;
};
2023-10-13 21:04:24 +02:00
};
2023-09-08 16:10:15 +02:00
};
};
}