-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit.nix
124 lines (100 loc) · 3.12 KB
/
git.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
{ pkgs, lib, config, osConfig, mkEnableOption, ... }:
let
inherit (lib)
findFirst
mapNullable
mkDefault
mkIf
mkMerge
mkOption
pipe
splitString
;
inherit (lib.types) functionTo str;
cfg = config.aquaris.git;
user = osConfig.aquaris.users.${config.home.username}.git;
##### ssh key stuff #####
allowedSigners = pkgs.writeText "allowedSigners" ''
${user.email} namespaces="git" ${user.key}
'';
sshKeyFile = pipe user.key [
(splitString " ")
builtins.head
(type: findFirst (x: x.type == type) null [
{ type = "ecdsa-sha2-nistp256"; name = "ecdsa"; }
{ type = "[email protected]"; name = "ecdsa_sk"; }
{ type = "[email protected]"; name = "ed25519_sk"; }
{ type = "ssh-ed25519"; name = "ed25519"; }
{ type = "ssh-rsa"; name = "rsa"; }
])
(mapNullable cfg.sshKeyFile)
];
in
{
options.aquaris.git = {
enable = mkEnableOption "Git with helpful aliases and features";
sshKeyFile = mkOption {
type = functionTo str;
description = ''
Function to locate the SSH private key.
{ name (string): Default file name of the SSH key (id_<name>)
, type (string): Type prefix of the passed public key
} -> string: Path to the SSH private key
'';
default = x: "~/.ssh/id_${x.name}";
};
};
config = mkIf cfg.enable {
home = {
packages = with pkgs; [ git-crypt ];
shellAliases = {
g = "git";
ga = "git add";
gan = "git add --intent-to-add";
gap = "git add --patch";
gc = "git commit";
gcm = "git commit --message";
gcam = "git commit --all --message";
gd = "git diff";
gds = "git diff --staged";
gl = "git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %aN%C(reset)%C(bold yellow)%d%C(reset)' --all";
gpl = "git pull";
gps = "git push";
gpsf = "git push --force-with-lease --force-if-includes";
gr = "git restore";
grs = "git restore --staged";
gs = "git show";
};
};
programs.git = {
enable = true;
lfs.enable = mkDefault true;
delta = {
enable = mkDefault true;
options = {
paging = mkDefault "always";
side-by-side = mkDefault true;
};
};
userName = mkDefault user.name;
userEmail = mkDefault user.email;
signing = mkIf (user.key != null) {
key = mkDefault (if sshKeyFile != null then sshKeyFile else user.key);
signByDefault = mkDefault true;
};
extraConfig = mkMerge [
{
merge.tool = mkDefault "vimdiff";
pull.rebase = mkDefault false;
push.autoSetupRemote = mkDefault true;
}
(mkIf (user.key != null) {
gpg.format = if sshKeyFile != null then "ssh" else "openpgp";
})
(mkIf (user.key != null && sshKeyFile != null) {
gpg.ssh.allowedSignersFile = mkDefault allowedSigners.outPath;
})
];
};
};
}