2021-09-10 23:46:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.git;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
programs.git = {
|
2024-04-17 12:37:58 +01:00
|
|
|
enable = lib.mkEnableOption "git, a distributed version control system";
|
2021-09-10 23:46:48 +01:00
|
|
|
|
2024-04-17 12:37:58 +01:00
|
|
|
package = lib.mkPackageOption pkgs "git" {
|
2023-11-27 00:19:27 +00:00
|
|
|
example = "gitFull";
|
2021-09-10 23:46:48 +01:00
|
|
|
};
|
|
|
|
|
2024-04-17 12:37:58 +01:00
|
|
|
config = lib.mkOption {
|
2022-12-21 01:43:56 +00:00
|
|
|
type =
|
2024-04-17 12:37:58 +01:00
|
|
|
with lib.types;
|
2022-12-21 01:43:56 +00:00
|
|
|
let
|
|
|
|
gitini = attrsOf (attrsOf anything);
|
|
|
|
in
|
|
|
|
either gitini (listOf gitini) // {
|
|
|
|
merge = loc: defs:
|
|
|
|
let
|
2024-04-17 12:37:58 +01:00
|
|
|
config = builtins.foldl'
|
|
|
|
(acc: { value, ... }@x: acc // (if builtins.isList value then {
|
2022-12-21 01:43:56 +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-10 23:46:48 +01:00
|
|
|
example = {
|
|
|
|
init.defaultBranch = "main";
|
|
|
|
url."https://github.com/".insteadOf = [ "gh:" "github:" ];
|
|
|
|
};
|
|
|
|
description = ''
|
2022-12-21 01:43:56 +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-10 23:46:48 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-11-07 14:14:11 +00:00
|
|
|
prompt = {
|
2024-04-17 12:37:58 +01:00
|
|
|
enable = lib.mkEnableOption "automatically sourcing git-prompt.sh. This does not change $PS1; it simply provides relevant utility functions";
|
2023-11-07 14:14:11 +00:00
|
|
|
};
|
|
|
|
|
2021-10-11 14:03:03 +01:00
|
|
|
lfs = {
|
2024-04-17 12:37:58 +01:00
|
|
|
enable = lib.mkEnableOption "git-lfs (Large File Storage)";
|
2021-10-11 14:03:03 +01:00
|
|
|
|
2024-04-17 12:37:58 +01:00
|
|
|
package = lib.mkPackageOption pkgs "git-lfs" { };
|
2021-10-11 14:03:03 +01:00
|
|
|
};
|
2021-09-10 23:46:48 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-04-17 12:37:58 +01:00
|
|
|
config = lib.mkMerge [
|
|
|
|
(lib.mkIf cfg.enable {
|
2021-10-11 14:03:03 +01:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2024-04-17 12:37:58 +01:00
|
|
|
environment.etc.gitconfig = lib.mkIf (cfg.config != [ ]) {
|
|
|
|
text = lib.concatMapStringsSep "\n" lib.generators.toGitINI cfg.config;
|
2021-10-11 14:03:03 +01:00
|
|
|
};
|
|
|
|
})
|
2024-04-17 12:37:58 +01:00
|
|
|
(lib.mkIf (cfg.enable && cfg.lfs.enable) {
|
2021-10-11 14:03:03 +01: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-04-17 12:37:58 +01:00
|
|
|
(lib.mkIf (cfg.enable && cfg.prompt.enable) {
|
2023-11-07 14:14:11 +00:00
|
|
|
environment.interactiveShellInit = ''
|
|
|
|
source ${cfg.package}/share/bash-completion/completions/git-prompt.sh
|
|
|
|
'';
|
|
|
|
})
|
2021-10-11 14:03:03 +01:00
|
|
|
];
|
|
|
|
|
2024-04-17 12:37:58 +01:00
|
|
|
meta.maintainers = with lib.maintainers; [ figsoda ];
|
2021-09-10 23:46:48 +01:00
|
|
|
}
|