aboutsummaryrefslogtreecommitdiffstats
path: root/modules/development/git/default.nix
blob: 593c8a310ac7b539d2388aae15fa017b06b01ad2 (plain)
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
# Distributed version control system
{
  config,
  lib,
  pkgs,
  ...
}:
let
  cfg = config.development.git;
in
{
  imports = [
    ./assertions.nix
  ]
  ++ lib.optional (builtins.pathExists ../../private/git.nix) ../../private/git.nix;

  options.development.git = {
    enable = lib.mkEnableOption "Enables git.";

    package = lib.mkOption {
      type = lib.types.package;
      readOnly = true;
      default = config.programs.git.package;
      description = "The git package to use.";
    };

    username = lib.mkOption {
      type = lib.types.str;
      description = "Git username.";
    };

    email = lib.mkOption {
      type = lib.types.str;
      description = "Git email.";
    };

    signing = lib.mkOption {
      type = lib.types.submodule {
        options = {
          key = lib.mkOption {
            type = lib.types.nullOr lib.types.str;
            default = null;
            description = "GPG key ID used for signing commits.";
          };

          sign-by-default = lib.mkEnableOption "Sign commits by default.";
        };
      };
      default = { };
      description = "Git commit signing configuration.";
    };
  };

  config = lib.mkIf cfg.enable {
    programs.git = {
      enable = true;
      signing = {
        key = cfg.signing.key;
        sign-by-default = cfg.signing.sign-by-default;
      };
      settings = lib.mkMerge [
        {
          user = {
            name = cfg.username;
            email = cfg.email;
          };
          core = {
            askPass = "";
            logallrefupdates = true;
          };
          log.showSignature = true;
          pull.rebase = true;
          init.defaultBranch = "master";
          merge.ff = false;
        }

        (lib.optionalAttrs config.development.delta.enable {
          core.pager = "delta";
          interactive.diffFilter = "delta --color-only";
          delta.navigate = true;
        })
      ];
    };
  };
}