1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.programs.git;
7in
8
9{
10 options = {
11 programs.git = {
12 enable = mkEnableOption (lib.mdDoc "git");
13
14 package = mkOption {
15 type = types.package;
16 default = pkgs.git;
17 defaultText = literalExpression "pkgs.git";
18 example = literalExpression "pkgs.gitFull";
19 description = lib.mdDoc "The git package to use";
20 };
21
22 config = mkOption {
23 type = with types; attrsOf (attrsOf anything);
24 default = { };
25 example = {
26 init.defaultBranch = "main";
27 url."https://github.com/".insteadOf = [ "gh:" "github:" ];
28 };
29 description = lib.mdDoc ''
30 Configuration to write to /etc/gitconfig. See the CONFIGURATION FILE
31 section of git-config(1) for more information.
32 '';
33 };
34
35 lfs = {
36 enable = mkEnableOption (lib.mdDoc "git-lfs");
37
38 package = mkOption {
39 type = types.package;
40 default = pkgs.git-lfs;
41 defaultText = literalExpression "pkgs.git-lfs";
42 description = lib.mdDoc "The git-lfs package to use";
43 };
44 };
45 };
46 };
47
48 config = mkMerge [
49 (mkIf cfg.enable {
50 environment.systemPackages = [ cfg.package ];
51 environment.etc.gitconfig = mkIf (cfg.config != {}) {
52 text = generators.toGitINI cfg.config;
53 };
54 })
55 (mkIf (cfg.enable && cfg.lfs.enable) {
56 environment.systemPackages = [ cfg.lfs.package ];
57 programs.git.config = {
58 filter.lfs = {
59 clean = "git-lfs clean -- %f";
60 smudge = "git-lfs smudge -- %f";
61 process = "git-lfs filter-process";
62 required = true;
63 };
64 };
65 })
66 ];
67
68 meta.maintainers = with maintainers; [ figsoda ];
69}