|  | 
|  | 1 | +{ | 
|  | 2 | +  pkgs, | 
|  | 3 | +  lib, | 
|  | 4 | +  config, | 
|  | 5 | +  inputs', | 
|  | 6 | +  ... | 
|  | 7 | +}: | 
|  | 8 | +let | 
|  | 9 | +  message = lib.types.submodule { | 
|  | 10 | +    options = { | 
|  | 11 | +      style = lib.mkOption { | 
|  | 12 | +        type = lib.types.nullOr lib.types.str; | 
|  | 13 | +        default = "conventional"; | 
|  | 14 | +        description = "The Git commit message format style"; | 
|  | 15 | +        example = "conventional"; | 
|  | 16 | +      }; | 
|  | 17 | +      historyLength = lib.mkOption { | 
|  | 18 | +        type = lib.types.nullOr lib.types.number; | 
|  | 19 | +        default = null; | 
|  | 20 | +        description = "The length of the git history to be used for generating commit messages"; | 
|  | 21 | +        example = 5; | 
|  | 22 | +      }; | 
|  | 23 | +      modelType = lib.mkOption { | 
|  | 24 | +        type = lib.types.str; | 
|  | 25 | +        default = "deepseek-chat"; | 
|  | 26 | +        description = "The LLM model type to be used for generating commit messages"; | 
|  | 27 | +        example = "deepseek-chat"; # Or "deepseek-reasoner" | 
|  | 28 | +      }; | 
|  | 29 | +    }; | 
|  | 30 | +  }; | 
|  | 31 | + | 
|  | 32 | +  pkgsType = lib.types.submodule { | 
|  | 33 | +    options = { | 
|  | 34 | +      format = lib.mkOption { | 
|  | 35 | +        type = message; | 
|  | 36 | +        default = { }; | 
|  | 37 | +        description = "The format style of this pacakge"; | 
|  | 38 | +      }; | 
|  | 39 | + | 
|  | 40 | +      description = lib.mkOption { | 
|  | 41 | +        type = lib.types.str; | 
|  | 42 | +        default = ""; | 
|  | 43 | +        description = "Description of this packages"; | 
|  | 44 | +      }; | 
|  | 45 | +    }; | 
|  | 46 | +  }; | 
|  | 47 | +in | 
|  | 48 | +{ | 
|  | 49 | +  options = { | 
|  | 50 | +    git-msg-bin = lib.mkOption { | 
|  | 51 | +      type = lib.types.package; | 
|  | 52 | +      default = pkgs.callPackage ./../package/git-msg.nix { }; | 
|  | 53 | +      description = "The Git commit message generator"; | 
|  | 54 | +    }; | 
|  | 55 | + | 
|  | 56 | +    packagesSet = lib.mkOption { | 
|  | 57 | +      type = lib.types.attrsOf pkgsType; | 
|  | 58 | +      default = { }; | 
|  | 59 | +      description = "The available packages for this module"; | 
|  | 60 | +    }; | 
|  | 61 | + | 
|  | 62 | +    defaultPackage = lib.mkOption { | 
|  | 63 | +      type = lib.types.package; | 
|  | 64 | +      description = "The default package to be used for this module"; | 
|  | 65 | +    }; | 
|  | 66 | + | 
|  | 67 | +    mkGitMsgWrapper = lib.mkOption { | 
|  | 68 | +      type = lib.types.functionTo (lib.types.functionTo lib.types.package); | 
|  | 69 | +      description = "function to wrap different Git commit message generator in shell scripts"; | 
|  | 70 | +    }; | 
|  | 71 | +  }; | 
|  | 72 | + | 
|  | 73 | +  config = { | 
|  | 74 | +    packagesSet = { | 
|  | 75 | +      conventional = { | 
|  | 76 | +        format = { | 
|  | 77 | +          style = "conventional"; | 
|  | 78 | +          modelType = "deepseek-chat"; | 
|  | 79 | +          historyLength = 5; | 
|  | 80 | +        }; | 
|  | 81 | +        description = "Git commit message generator with conventional style"; | 
|  | 82 | +      }; | 
|  | 83 | + | 
|  | 84 | +      bracketed = { | 
|  | 85 | +        format = { | 
|  | 86 | +          style = "bracketed"; | 
|  | 87 | +          modelType = "deepseek-chat"; | 
|  | 88 | +          historyLength = 5; | 
|  | 89 | +        }; | 
|  | 90 | +        description = "Git commit message generator with bracketed style"; | 
|  | 91 | +      }; | 
|  | 92 | + | 
|  | 93 | +      plain = { | 
|  | 94 | +        format = { | 
|  | 95 | +          style = "plain"; | 
|  | 96 | +          modelType = "deepseek-chat"; | 
|  | 97 | +          historyLength = 5; | 
|  | 98 | +        }; | 
|  | 99 | +        description = "Git commit message generator with plain style"; | 
|  | 100 | +      }; | 
|  | 101 | +    }; | 
|  | 102 | + | 
|  | 103 | +    mkGitMsgWrapper = | 
|  | 104 | +      name: pkg: | 
|  | 105 | +      let | 
|  | 106 | +        formatConfig = pkg.format; | 
|  | 107 | +        scriptsParams = [ | 
|  | 108 | +          "--model=${formatConfig.modelType}" | 
|  | 109 | +          (lib.optionals (formatConfig.style != null) "--format=${formatConfig.style}") | 
|  | 110 | +          (lib.optionals ( | 
|  | 111 | +            formatConfig.historyLength != null | 
|  | 112 | +          ) "--git-history=${lib.toHexString formatConfig.historyLength}") | 
|  | 113 | +        ]; | 
|  | 114 | + | 
|  | 115 | +      in | 
|  | 116 | +      pkgs.writeShellApplication { | 
|  | 117 | +        name = "git-msg-${name}"; | 
|  | 118 | +        runtimeInputs = with pkgs; [ | 
|  | 119 | +          coreutils | 
|  | 120 | +          git | 
|  | 121 | +          config.git-msg-bin | 
|  | 122 | +        ]; | 
|  | 123 | +        text = '' | 
|  | 124 | +          echo "Welcome to Git Commit Generator Modules!" | 
|  | 125 | +          echo "Format: ${formatConfig.style}" | 
|  | 126 | +          echo "Git Commit Message Generator: ${config.git-msg-bin}" | 
|  | 127 | +          echo "Params: ${lib.concatStringsSep " " scriptsParams}" | 
|  | 128 | +          ${config.git-msg-bin}/bin/git-msg ${lib.concatStringsSep " " scriptsParams} | 
|  | 129 | +        ''; | 
|  | 130 | +      }; | 
|  | 131 | + | 
|  | 132 | +    defaultPackage = | 
|  | 133 | +      let | 
|  | 134 | +        formatName = "conventional"; | 
|  | 135 | +      in | 
|  | 136 | +      config.mkGitMsgWrapper formatName config.packagesSet.${formatName}; | 
|  | 137 | +  }; | 
|  | 138 | +} | 
0 commit comments