63 lines
2.3 KiB
Nix
63 lines
2.3 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
let
|
|
gui = config.dotfiles.gui;
|
|
vault = if config.dotfiles.work then "work" else "personal";
|
|
mode = if gui then "desktop" else "headless";
|
|
credentialHelper = pkgs.buildGoModule {
|
|
pname = "git-credential-dotfiles";
|
|
version = "1.0.0";
|
|
src = ../tools/git-credential-dotfiles;
|
|
vendorHash = null;
|
|
nativeBuildInputs = [ pkgs.makeWrapper ];
|
|
postInstall = ''
|
|
wrapProgram $out/bin/git-credential-dotfiles \
|
|
--prefix PATH : ${lib.makeBinPath ([ pkgs.git-credential-manager pkgs.bitwarden-cli ] ++ lib.optional gui pkgs.git-credential-oauth)}
|
|
'';
|
|
};
|
|
vaultCLI = pkgs.writeShellScriptBin "git-vault" ''
|
|
exec ${credentialHelper}/bin/git-credential-dotfiles vault "$@"
|
|
'';
|
|
in
|
|
{
|
|
# Provide a Secret Service on desktops without relying on distro-specific
|
|
# keyring packages. It is a user service and does not alter system PAM/SSH.
|
|
services.gnome-keyring = lib.mkIf gui {
|
|
enable = true;
|
|
components = [ "secrets" ];
|
|
};
|
|
home.packages = [ credentialHelper vaultCLI pkgs.git-credential-manager ]
|
|
++ lib.optionals gui [ pkgs.sourcegit pkgs.git-credential-oauth pkgs.libsecret ];
|
|
programs.git = {
|
|
enable = true;
|
|
settings = {
|
|
user = {
|
|
name = "Ziad Arafat";
|
|
email = if config.dotfiles.work then "ziad.arafat@etvamerica.com"
|
|
else "anonymous0programmer@gmail.com";
|
|
};
|
|
init.defaultBranch = "main";
|
|
credential = {
|
|
# Empty helper clears inherited system helpers, including plaintext storage.
|
|
helper = [ "" "${credentialHelper}/bin/git-credential-dotfiles --mode=${mode} --vault=${vault}" ];
|
|
credentialStore = if gui then "secretservice" else "cache";
|
|
cacheOptions = "--timeout=3600";
|
|
guiPrompt = gui;
|
|
"https://github.com" = {
|
|
provider = if gui then "generic" else "github";
|
|
gitHubAuthModes = if gui then "browser" else "pat";
|
|
};
|
|
"https://gitea.godemperordoge.org".provider = "generic";
|
|
"https://gitea.etvamerica.com".provider = "generic";
|
|
};
|
|
http = {
|
|
lowSpeedLimit = 1000;
|
|
lowSpeedTime = 60;
|
|
postBuffer = 524288000;
|
|
};
|
|
safe.directory = "*";
|
|
};
|
|
ignores = [ ".direnv/" ".envrc.local" "*.swp" ".venv/" "__pycache__/" ];
|
|
};
|
|
programs.git.lfs.enable = true;
|
|
}
|