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

with lib;

let
  cfg = config.networking;

  emptyList = lst: if lst != [] then lst else ["empty"];
  quoteStrings = concatMapStringsSep " " (str: "'${str}'");

  setHostName = optionalString (cfg.hostName != null) ''
    scutil --set ComputerName '${cfg.hostName}'
    scutil --set LocalHostName '${cfg.hostName}'
    scutil --set HostName '${cfg.hostName}'
  '';

  setNetworkServices = optionalString (cfg.networkservices != []) ''
    networkservices=$(networksetup -listallnetworkservices)
    ${concatMapStringsSep "\n" (srv: ''
      case "$networkservices" in
        *'${srv}'*)
          networksetup -setdnsservers '${srv}' ${quoteStrings (emptyList cfg.dns)}
          networksetup -setsearchdomains '${srv}' ${quoteStrings (emptyList cfg.search)}
          ;;
      esac
    '') cfg.networkservices}
  '';
in

{
  options = {
    networking.hostName = mkOption {
      type = types.nullOr types.str;
      default = null;
      example = "myhostname";
      description = "Hostname for your machine.";
    };

    networking.networkservices = mkOption {
      type = types.listOf types.str;
      default = [];
      example = [ "Wi-Fi" "Ethernet Adaptor" "Thunderbolt Ethernet" ];
      description = ''
        List of networkservices that should be configured.

        To display a list of all the network services on the server's
        hardware ports, use <command>networksetup -listallnetworkservices</command>.
      '';
    };

    networking.dns = mkOption {
      type = types.listOf types.str;
      default = [];
      example = [ "8.8.8.8" "8.8.4.4" "fc00:db20:35b:7399::5" "fc00:db20:35b:7399::5" ];
      description = "The list of dns servers used when resolving domain names.";
    };

    networking.search = mkOption {
      type = types.listOf types.str;
      default = [];
      description = "The list of search paths used when resolving domain names.";
    };
  };

  config = {

    system.defaults.smb.NetBIOSName = cfg.hostName;
<commit_msg>networking: add warning when networkservices is empty<commit_after>{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.networking;

  emptyList = lst: if lst != [] then lst else ["empty"];
  quoteStrings = concatMapStringsSep " " (str: "'${str}'");

  setHostName = optionalString (cfg.hostName != null) ''
    scutil --set ComputerName '${cfg.hostName}'
    scutil --set LocalHostName '${cfg.hostName}'
    scutil --set HostName '${cfg.hostName}'
  '';

  setNetworkServices = optionalString (cfg.networkservices != []) ''
    networkservices=$(networksetup -listallnetworkservices)
    ${concatMapStringsSep "\n" (srv: ''
      case "$networkservices" in
        *'${srv}'*)
          networksetup -setdnsservers '${srv}' ${quoteStrings (emptyList cfg.dns)}
          networksetup -setsearchdomains '${srv}' ${quoteStrings (emptyList cfg.search)}
          ;;
      esac
    '') cfg.networkservices}
  '';
in

{
  options = {
    networking.hostName = mkOption {
      type = types.nullOr types.str;
      default = null;
      example = "myhostname";
      description = "Hostname for your machine.";
    };

    networking.networkservices = mkOption {
      type = types.listOf types.str;
      default = [];
      example = [ "Wi-Fi" "Ethernet Adaptor" "Thunderbolt Ethernet" ];
      description = ''
        List of networkservices that should be configured.

        To display a list of all the network services on the server's
        hardware ports, use <command>networksetup -listallnetworkservices</command>.
      '';
    };

    networking.dns = mkOption {
      type = types.listOf types.str;
      default = [];
      example = [ "8.8.8.8" "8.8.4.4" "fc00:db20:35b:7399::5" "fc00:db20:35b:7399::5" ];
      description = "The list of dns servers used when resolving domain names.";
    };

    networking.search = mkOption {
      type = types.listOf types.str;
      default = [];
      description = "The list of search paths used when resolving domain names.";
    };
  };

  config = {

    warnings = [
      (mkIf (cfg.networkservices == [] && cfg.dns != []) "networking.networkservices is empty, dns servers will not be configured.")
      (mkIf (cfg.networkservices == [] && cfg.search != []) "networking.networkservices is empty, dns searchdomains will not be configured.")
    ];

    system.defaults.smb.NetBIOSName = cfg.hostName;

{'fraction_non_alphanumeric': 0.1390532544378698, 'fraction_numerical': 0.013654984069185253, 'mean_word_length': 2.8350785340314135, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '752689', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1391, 'n_words': 347}