modularize git

This commit is contained in:
2025-07-03 11:04:42 +02:00
parent 1e8b8434f9
commit f45e2d61f4
12 changed files with 103 additions and 92 deletions

View File

@@ -14,6 +14,7 @@
./home/programs/foot
./home/programs/fuzzel
./home/programs/ghostty
./home/programs/git
./home/programs/helix
./home/programs/hyprlock
./home/programs/jujutsu

View File

@@ -0,0 +1,59 @@
{
config,
pkgs,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.home.programs.git;
in {
options = {
home.programs.git.enable = mkEnableOption "Enables git";
};
config = mkIf cfg.enable {
home.packages = [pkgs.gh];
programs.git = {
enable = true;
userName = config.accounts.username;
userEmail = config.accounts.mail;
delta = {
enable = true;
options.dark = true;
};
extraConfig = {
# user.signingkey = "${config.home.homeDirectory}/.ssh/id_ed25519.pub";
user.signingkey = "${config.home.homeDirectory}/.config/git/allowed_signers";
signing = {
format = lib.mkDefault "ssh";
key = "${config.home.homeDirectory}/.ssh/id_ed25519";
signByDefault = true;
};
gpg = {
# format = lib.mkDefault "ssh";
ssh.allowedSignersFile = config.home.homeDirectory + "/" + config.xdg.configFile."git/allowed_signers".target;
};
commit = {
verbose = true;
gpgSign = false;
};
init.defaultBranch = "main";
merge.conflictStyle = "diff3";
diff.algorithm = "histogram";
log.date = "iso";
column.ui = "auto";
branch.sort = "committerdate";
push.autoSetupRemote = true;
rerere.enabled = true;
};
lfs.enable = true;
ignores = [
".direnv"
"result"
".jj"
];
};
xdg.configFile."git/allowed_signers".text = ''
${config.accounts.mail} namespaces="git" ${config.accounts.sshKey}
'';
};
}

View File

@@ -4,6 +4,24 @@
...
}: let
inherit (lib) mkOption types;
sshKeys = {
cnixpad = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIXCjkKouZrsMoswMIeueO8X/c3kuY3Gb0E9emvkqwUv cnst@cnixpad";
cnixlab = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICiNcNex+/hrEQJYJJTj89uPXocSfChU38E5TujWdxaM cnstlab@cnixlab";
cnixtop = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEUub8vbzUn2f39ILhAJ2QeH8xxLSjiyUuo8xvHGx/VB adam@cnst.dev";
toothpc = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGu5vZbb5ExampleKeyHereGfDF9c5 toothpick@toothpc";
};
keyName = config.accounts.sshUser or null;
selectedKey =
if keyName != null
then
lib.attrByPath [keyName] (
builtins.abort "No SSH key defined for hostname/key '${toString keyName}'"
)
sshKeys
else builtins.abort "No accounts.sshUser provided, cannot select SSH key.";
in {
options.accounts = {
username = mkOption {
@@ -11,10 +29,21 @@ in {
default = "cnst";
description = "Set the desired username";
};
hostname = mkOption {
mail = mkOption {
type = types.str;
default = "cnix";
description = "Set the desired hostname";
default = "adam@cnst.dev";
description = "Set the desired email";
};
sshKey = lib.mkOption {
type = lib.types.str;
default = selectedKey;
description = "Host-specific SSH key";
readOnly = true;
};
sshUser = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "Optional override for selecting an SSH key by name";
};
};
}