141 lines
4.1 KiB
Nix
141 lines
4.1 KiB
Nix
# Git Files module
|
|
#
|
|
# This module manages project-specific gitconfig files using home.file.
|
|
# These files are referenced by includeIf directives in the main git configuration.
|
|
#
|
|
# Based on the chezmoi configuration from:
|
|
# - private_Projects/dot_gitconfig
|
|
# - private_Projects/private_private/dot_gitconfig
|
|
# - private_Projects/private_zeronorth/dot_gitconfig
|
|
{
|
|
config,
|
|
pkgs,
|
|
lib,
|
|
...
|
|
}:
|
|
with lib; let
|
|
cfg = config.modules.gitFiles;
|
|
|
|
# Helper function to generate gitconfig content
|
|
mkGitConfig = {
|
|
email,
|
|
signingKey,
|
|
urlRewrites ? {},
|
|
}: ''
|
|
[user]
|
|
email = ${email}
|
|
name = Morten Olsen
|
|
signingkey = ${signingKey}
|
|
|
|
[commit]
|
|
gpgsign = true
|
|
|
|
[gpg]
|
|
format = ssh
|
|
|
|
[gpg "ssh"]
|
|
program = "/Applications/1Password.app/Contents/MacOS/op-ssh-sign"
|
|
${optionalString (urlRewrites != {}) (concatStringsSep "\n" (mapAttrsToList (name: value: ''
|
|
|
|
[url "${name}"]
|
|
insteadOf = ${value}'') urlRewrites))}
|
|
'';
|
|
in {
|
|
options.modules.gitFiles = {
|
|
enable = mkEnableOption "Project-specific git configuration files";
|
|
|
|
# Personal profile settings (used for ~/Projects/.gitconfig on personal machine)
|
|
personal = {
|
|
enable = mkEnableOption "Personal Projects gitconfig";
|
|
|
|
email = mkOption {
|
|
type = types.str;
|
|
default = "alice@personal.example.com";
|
|
description = "Email for personal projects";
|
|
};
|
|
|
|
signingKey = mkOption {
|
|
type = types.str;
|
|
description = "SSH signing key for personal projects";
|
|
example = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI...";
|
|
};
|
|
};
|
|
|
|
# Private profile settings (used for ~/Projects/private/.gitconfig on work machine)
|
|
private = {
|
|
enable = mkEnableOption "Private Projects gitconfig";
|
|
|
|
email = mkOption {
|
|
type = types.str;
|
|
default = "alice@personal.example.com";
|
|
description = "Email for private projects";
|
|
};
|
|
|
|
signingKey = mkOption {
|
|
type = types.str;
|
|
description = "SSH signing key for private projects";
|
|
example = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI...";
|
|
};
|
|
};
|
|
|
|
# Zeronorth profile settings (used for ~/Projects/zeronorth/.gitconfig on work machine)
|
|
zeronorth = {
|
|
enable = mkEnableOption "Zeronorth Projects gitconfig";
|
|
|
|
email = mkOption {
|
|
type = types.str;
|
|
default = "alice@work.example.com";
|
|
description = "Email for zeronorth projects";
|
|
};
|
|
|
|
signingKey = mkOption {
|
|
type = types.str;
|
|
description = "SSH signing key for zeronorth projects";
|
|
example = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI...";
|
|
};
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
home.file = mkMerge [
|
|
# Personal Projects gitconfig (~/Projects/.gitconfig)
|
|
# Used on personal machine for all projects under ~/Projects/
|
|
(mkIf cfg.personal.enable {
|
|
"Projects/.gitconfig".text = mkGitConfig {
|
|
email = cfg.personal.email;
|
|
signingKey = cfg.personal.signingKey;
|
|
urlRewrites = {
|
|
"ssh://git@ssh-gitea.olsen.cloud:2205/" = "https://gitea.olsen.cloud/";
|
|
"git@github-private:" = "https://github.com/";
|
|
};
|
|
};
|
|
})
|
|
|
|
# Private Projects gitconfig (~/Projects/private/.gitconfig)
|
|
# Used on work machine for personal projects under ~/Projects/private/
|
|
(mkIf cfg.private.enable {
|
|
"Projects/private/.gitconfig".text = mkGitConfig {
|
|
email = cfg.private.email;
|
|
signingKey = cfg.private.signingKey;
|
|
urlRewrites = {
|
|
"ssh://git@ssh-gitea.olsen.cloud:2205/" = "https://gitea.olsen.cloud/";
|
|
"git@github-private:" = "https://github.com/";
|
|
};
|
|
};
|
|
})
|
|
|
|
# Zeronorth Projects gitconfig (~/Projects/zeronorth/.gitconfig)
|
|
# Used on work machine for work projects under ~/Projects/zeronorth/
|
|
(mkIf cfg.zeronorth.enable {
|
|
"Projects/zeronorth/.gitconfig".text = mkGitConfig {
|
|
email = cfg.zeronorth.email;
|
|
signingKey = cfg.zeronorth.signingKey;
|
|
urlRewrites = {
|
|
"git@github-zeronorth:" = "https://github.com/";
|
|
};
|
|
};
|
|
})
|
|
];
|
|
};
|
|
}
|