at 23.11-pre 2.8 kB view raw
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 = 24 with types; 25 let 26 gitini = attrsOf (attrsOf anything); 27 in 28 either gitini (listOf gitini) // { 29 merge = loc: defs: 30 let 31 config = foldl' 32 (acc: { value, ... }@x: acc // (if isList value then { 33 ordered = acc.ordered ++ value; 34 } else { 35 unordered = acc.unordered ++ [ x ]; 36 })) 37 { 38 ordered = [ ]; 39 unordered = [ ]; 40 } 41 defs; 42 in 43 [ (gitini.merge loc config.unordered) ] ++ config.ordered; 44 }; 45 default = [ ]; 46 example = { 47 init.defaultBranch = "main"; 48 url."https://github.com/".insteadOf = [ "gh:" "github:" ]; 49 }; 50 description = lib.mdDoc '' 51 Configuration to write to /etc/gitconfig. A list can also be 52 specified to keep the configuration in order. For example, setting 53 `config` to `[ { foo.x = 42; } { bar.y = 42; }]` will put the `foo` 54 section before the `bar` section unlike the default alphabetical 55 order, which can be helpful for sections such as `include` and 56 `includeIf`. See the CONFIGURATION FILE section of git-config(1) for 57 more information. 58 ''; 59 }; 60 61 lfs = { 62 enable = mkEnableOption (lib.mdDoc "git-lfs"); 63 64 package = mkOption { 65 type = types.package; 66 default = pkgs.git-lfs; 67 defaultText = literalExpression "pkgs.git-lfs"; 68 description = lib.mdDoc "The git-lfs package to use"; 69 }; 70 }; 71 }; 72 }; 73 74 config = mkMerge [ 75 (mkIf cfg.enable { 76 environment.systemPackages = [ cfg.package ]; 77 environment.etc.gitconfig = mkIf (cfg.config != [ ]) { 78 text = concatMapStringsSep "\n" generators.toGitINI cfg.config; 79 }; 80 }) 81 (mkIf (cfg.enable && cfg.lfs.enable) { 82 environment.systemPackages = [ cfg.lfs.package ]; 83 programs.git.config = { 84 filter.lfs = { 85 clean = "git-lfs clean -- %f"; 86 smudge = "git-lfs smudge -- %f"; 87 process = "git-lfs filter-process"; 88 required = true; 89 }; 90 }; 91 }) 92 ]; 93 94 meta.maintainers = with maintainers; [ figsoda ]; 95}