<commit_before>{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.programs.git;

  toINI = (import ../lib/generators.nix).toINI {};

  signModule = types.submodule (
    { ... }: {
      options = {
        key = mkOption {
          type = types.str;
          default = null;
          description = "The default GPG signing key fingerprint.";
        };

        signByDefault = mkOption {
          type = types.bool;
          default = false;
          description = "Whether commits should be signed by default.";
        };

        gpgPath = mkOption {
          type = types.str;
          default = "${pkgs.gnupg}/bin/gpg2";
          defaultText = "\${pkgs.gnupg}/bin/gpg2";
          description = "Path to GnuPG binary to use.";
        };
      };
    }
  );

in

{
  options = {
    programs.git = {
      enable = mkEnableOption "Git";

      package = mkOption {
        type = types.package;
        default = pkgs.git;
        defaultText = "pkgs.git";
        description = "Git package to install.";
      };

      userName = mkOption {
        type = types.str;
        description = "Default user name to use.";
      };

      userEmail = mkOption {
        type = types.str;
        description = "Default user email to use.";
      };

      aliases = mkOption {
        type = types.attrs;
        default = {};
        description = "Git aliases to define.";
      };

      signing = mkOption {
        type = types.nullOr signModule;
        default = null;
        description = "Options related to signing commits using GnuPG.";
      };

      extraConfig = mkOption {
        type = types.lines;
        default = null;
        description = "Additional configuration to add.";
      };
    };
  };

  config = mkIf cfg.enable (
    let
      ini = {
        user = {
          name = cfg.userName;
          email = cfg.userEmail;
        } // optionalAttrs (cfg.signing != null) {
          signingKey = cfg.signing.key;
        };
      } // optionalAttrs (cfg.signing != null) {
        commit.gpgSign = cfg.signing.signByDefault;
        gpg.program = cfg.signing.gpgPath;
      } // optionalAttrs (cfg.aliases != {}) {
        alias = cfg.aliases;
      };
    in
      {
        home.packages = [ cfg.package ];

        home.file.".gitconfig".text = toINI ini + "\n" + cfg.extraConfig;
      }
  );
}
<commit_msg>git: fix evaluation error on null `extraConfig`<commit_after>{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.programs.git;

  toINI = (import ../lib/generators.nix).toINI {};

  signModule = types.submodule (
    { ... }: {
      options = {
        key = mkOption {
          type = types.str;
          default = null;
          description = "The default GPG signing key fingerprint.";
        };

        signByDefault = mkOption {
          type = types.bool;
          default = false;
          description = "Whether commits should be signed by default.";
        };

        gpgPath = mkOption {
          type = types.str;
          default = "${pkgs.gnupg}/bin/gpg2";
          defaultText = "\${pkgs.gnupg}/bin/gpg2";
          description = "Path to GnuPG binary to use.";
        };
      };
    }
  );

in

{
  options = {
    programs.git = {
      enable = mkEnableOption "Git";

      package = mkOption {
        type = types.package;
        default = pkgs.git;
        defaultText = "pkgs.git";
        description = "Git package to install.";
      };

      userName = mkOption {
        type = types.str;
        description = "Default user name to use.";
      };

      userEmail = mkOption {
        type = types.str;
        description = "Default user email to use.";
      };

      aliases = mkOption {
        type = types.attrs;
        default = {};
        description = "Git aliases to define.";
      };

      signing = mkOption {
        type = types.nullOr signModule;
        default = null;
        description = "Options related to signing commits using GnuPG.";
      };

      extraConfig = mkOption {
        type = types.lines;
        default = "";
        description = "Additional configuration to add.";
      };
    };
  };

  config = mkIf cfg.enable (
    let
      ini = {
        user = {
          name = cfg.userName;
          email = cfg.userEmail;
        } // optionalAttrs (cfg.signing != null) {
          signingKey = cfg.signing.key;
        };
      } // optionalAttrs (cfg.signing != null) {
        commit.gpgSign = cfg.signing.signByDefault;
        gpg.program = cfg.signing.gpgPath;
      } // optionalAttrs (cfg.aliases != {}) {
        alias = cfg.aliases;
      };
    in
      {
        home.packages = [ cfg.package ];

        home.file.".gitconfig".text = toINI ini + "\n" + cfg.extraConfig;
      }
  );
}

{'fraction_non_alphanumeric': 0.12573467674223343, 'fraction_numerical': 0.0008396305625524769, 'mean_word_length': 1.593903102885139, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '888759', 'n_tokens_mistral': 1444, 'n_tokens_neox': 1397, 'n_words': 337}