at 24.11-pre 2.9 kB view raw
1{ config, lib, pkgs, ... }: 2 3let 4 cfg = config.programs.git; 5in 6 7{ 8 options = { 9 programs.git = { 10 enable = lib.mkEnableOption "git, a distributed version control system"; 11 12 package = lib.mkPackageOption pkgs "git" { 13 example = "gitFull"; 14 }; 15 16 config = lib.mkOption { 17 type = 18 with lib.types; 19 let 20 gitini = attrsOf (attrsOf anything); 21 in 22 either gitini (listOf gitini) // { 23 merge = loc: defs: 24 let 25 config = builtins.foldl' 26 (acc: { value, ... }@x: acc // (if builtins.isList value then { 27 ordered = acc.ordered ++ value; 28 } else { 29 unordered = acc.unordered ++ [ x ]; 30 })) 31 { 32 ordered = [ ]; 33 unordered = [ ]; 34 } 35 defs; 36 in 37 [ (gitini.merge loc config.unordered) ] ++ config.ordered; 38 }; 39 default = [ ]; 40 example = { 41 init.defaultBranch = "main"; 42 url."https://github.com/".insteadOf = [ "gh:" "github:" ]; 43 }; 44 description = '' 45 Configuration to write to /etc/gitconfig. A list can also be 46 specified to keep the configuration in order. For example, setting 47 `config` to `[ { foo.x = 42; } { bar.y = 42; }]` will put the `foo` 48 section before the `bar` section unlike the default alphabetical 49 order, which can be helpful for sections such as `include` and 50 `includeIf`. See the CONFIGURATION FILE section of git-config(1) for 51 more information. 52 ''; 53 }; 54 55 prompt = { 56 enable = lib.mkEnableOption "automatically sourcing git-prompt.sh. This does not change $PS1; it simply provides relevant utility functions"; 57 }; 58 59 lfs = { 60 enable = lib.mkEnableOption "git-lfs (Large File Storage)"; 61 62 package = lib.mkPackageOption pkgs "git-lfs" { }; 63 }; 64 }; 65 }; 66 67 config = lib.mkMerge [ 68 (lib.mkIf cfg.enable { 69 environment.systemPackages = [ cfg.package ]; 70 environment.etc.gitconfig = lib.mkIf (cfg.config != [ ]) { 71 text = lib.concatMapStringsSep "\n" lib.generators.toGitINI cfg.config; 72 }; 73 }) 74 (lib.mkIf (cfg.enable && cfg.lfs.enable) { 75 environment.systemPackages = [ cfg.lfs.package ]; 76 programs.git.config = { 77 filter.lfs = { 78 clean = "git-lfs clean -- %f"; 79 smudge = "git-lfs smudge -- %f"; 80 process = "git-lfs filter-process"; 81 required = true; 82 }; 83 }; 84 }) 85 (lib.mkIf (cfg.enable && cfg.prompt.enable) { 86 environment.interactiveShellInit = '' 87 source ${cfg.package}/share/bash-completion/completions/git-prompt.sh 88 ''; 89 }) 90 ]; 91 92 meta.maintainers = with lib.maintainers; [ figsoda ]; 93}