2021-09-18 10:52:07 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.git;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
programs.git = {
|
2024-05-15 15:35:15 +00:00
|
|
|
enable = lib.mkEnableOption "git, a distributed version control system";
|
2021-09-18 10:52:07 +00:00
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
package = lib.mkPackageOption pkgs "git" {
|
2024-01-02 11:29:13 +00:00
|
|
|
example = "gitFull";
|
2021-09-18 10:52:07 +00:00
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
config = lib.mkOption {
|
2022-12-28 21:21:41 +00:00
|
|
|
type =
|
2024-05-15 15:35:15 +00:00
|
|
|
with lib.types;
|
2022-12-28 21:21:41 +00:00
|
|
|
let
|
|
|
|
gitini = attrsOf (attrsOf anything);
|
|
|
|
in
|
|
|
|
either gitini (listOf gitini) // {
|
|
|
|
merge = loc: defs:
|
|
|
|
let
|
2024-05-15 15:35:15 +00:00
|
|
|
config = builtins.foldl'
|
|
|
|
(acc: { value, ... }@x: acc // (if builtins.isList value then {
|
2022-12-28 21:21:41 +00:00
|
|
|
ordered = acc.ordered ++ value;
|
|
|
|
} else {
|
|
|
|
unordered = acc.unordered ++ [ x ];
|
|
|
|
}))
|
|
|
|
{
|
|
|
|
ordered = [ ];
|
|
|
|
unordered = [ ];
|
|
|
|
}
|
|
|
|
defs;
|
|
|
|
in
|
|
|
|
[ (gitini.merge loc config.unordered) ] ++ config.ordered;
|
|
|
|
};
|
|
|
|
default = [ ];
|
2021-09-18 10:52:07 +00:00
|
|
|
example = {
|
|
|
|
init.defaultBranch = "main";
|
|
|
|
url."https://github.com/".insteadOf = [ "gh:" "github:" ];
|
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-12-28 21:21:41 +00:00
|
|
|
Configuration to write to /etc/gitconfig. A list can also be
|
|
|
|
specified to keep the configuration in order. For example, setting
|
|
|
|
`config` to `[ { foo.x = 42; } { bar.y = 42; }]` will put the `foo`
|
|
|
|
section before the `bar` section unlike the default alphabetical
|
|
|
|
order, which can be helpful for sections such as `include` and
|
|
|
|
`includeIf`. See the CONFIGURATION FILE section of git-config(1) for
|
|
|
|
more information.
|
2021-09-18 10:52:07 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
prompt = {
|
2024-05-15 15:35:15 +00:00
|
|
|
enable = lib.mkEnableOption "automatically sourcing git-prompt.sh. This does not change $PS1; it simply provides relevant utility functions";
|
2024-01-02 11:29:13 +00:00
|
|
|
};
|
|
|
|
|
2021-10-11 16:52:03 +00:00
|
|
|
lfs = {
|
2024-05-15 15:35:15 +00:00
|
|
|
enable = lib.mkEnableOption "git-lfs (Large File Storage)";
|
2021-10-11 16:52:03 +00:00
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
package = lib.mkPackageOption pkgs "git-lfs" { };
|
2021-10-11 16:52:03 +00:00
|
|
|
};
|
2021-09-18 10:52:07 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
config = lib.mkMerge [
|
|
|
|
(lib.mkIf cfg.enable {
|
2021-10-11 16:52:03 +00:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2024-05-15 15:35:15 +00:00
|
|
|
environment.etc.gitconfig = lib.mkIf (cfg.config != [ ]) {
|
|
|
|
text = lib.concatMapStringsSep "\n" lib.generators.toGitINI cfg.config;
|
2021-10-11 16:52:03 +00:00
|
|
|
};
|
|
|
|
})
|
2024-05-15 15:35:15 +00:00
|
|
|
(lib.mkIf (cfg.enable && cfg.lfs.enable) {
|
2021-10-11 16:52:03 +00:00
|
|
|
environment.systemPackages = [ cfg.lfs.package ];
|
|
|
|
programs.git.config = {
|
|
|
|
filter.lfs = {
|
|
|
|
clean = "git-lfs clean -- %f";
|
|
|
|
smudge = "git-lfs smudge -- %f";
|
|
|
|
process = "git-lfs filter-process";
|
|
|
|
required = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|
2024-05-15 15:35:15 +00:00
|
|
|
(lib.mkIf (cfg.enable && cfg.prompt.enable) {
|
2024-01-02 11:29:13 +00:00
|
|
|
environment.interactiveShellInit = ''
|
|
|
|
source ${cfg.package}/share/bash-completion/completions/git-prompt.sh
|
|
|
|
'';
|
|
|
|
})
|
2021-10-11 16:52:03 +00:00
|
|
|
];
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
meta.maintainers = with lib.maintainers; [ figsoda ];
|
2021-09-18 10:52:07 +00:00
|
|
|
}
|