# Do not modify this file!  It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations.  Please make changes
# to /etc/nixos/configuration.nix instead.

#---------------------------------------------------------------------
# Imports and basic configuration
#---------------------------------------------------------------------
{ config, lib, pkgs, modulesPath, ... }:
let
  defaultXfsOpts = [ "defaults" "relatime" "nodiratime" ];

in
{
  #---------------------------------------------------------------------
  # Module imports
  #---------------------------------------------------------------------
  imports = [ (modulesPath + "/installer/scan/not-detected.nix") ];

  #---------------------------------------------------------------------
  # Boot configuration
  #---------------------------------------------------------------------
  boot = {

    extraModulePackages = [ ];
    initrd.kernelModules = [ ];
    kernelModules = [ 
      "kvm-intel" 
      "tcp_bbr"       # Dynamically optimize how data is sent over a network (not internet), aiming to achieve higher throughput and reduced latency

      ]; 

    # Enable BBR congestion control algorithm for TCP, , which can lead to improved network throughput and reduced latency.
    kernel.sysctl = {
      "net.ipv4.tcp_congestion_control" = "bbr";

    };

    kernelParams = [
      # "intel_pstate=ondemand" # Enables the "ondemand" CPU frequency scaling governor for Intel processors, optimizing performance and power efficiency.
      "intel_pstate=disable"    # You may have more control over the CPU's performance and power management.
      "mitigations=off"         # Disables certain security mitigations, potentially improving performance but reducing security.
      "quiet"                   # Suppresses verbose kernel messages during boot, providing a quieter boot process.

    ];

    initrd.availableKernelModules = [
      "ahci"        # Enables the Advanced Host Controller Interface (AHCI) driver, typically used for SATA (Serial ATA) controllers.
      "ehci_pci"    # Enables the Enhanced Host Controller Interface (EHCI) driver for PCI-based USB controllers, providing support for USB 2.0.
      "sd_mod"      # Enables the SCSI disk module (sd_mod), which allows the system to recognize and interact with SCSI-based storage devices.
      "sr_mod"      # Loads the SCSI (Small Computer System Interface) CD/DVD-ROM driver, allowing the system to recognize and use optical drives.
      "sdhci_pci"   # Enables the Secure Digital Host Controller Interface (SDHCI) driver for PCI-based SD card readers.
      "uas"         # Enables the USB Attached SCSI (UAS) driver, which provides a faster and more efficient way to access USB storage devices.
      "usb_storage" # Enables the USB Mass Storage driver, allowing the system to recognize and use USB storage devices like USB flash drives and external hard drives.
      "usbhid"      # Enables the USB Human Interface Device (HID) driver, which provides support for USB input devices such as keyboards and mice.
      "xhci_pci"    # Enables the eXtensible Host Controller Interface (xHCI) driver for PCI-based USB controllers, providing support for USB 3.0 and later standards.

    ];
  };

  #---------------------------------------------------------------------
  # File system configurations
  #---------------------------------------------------------------------
  fileSystems."/" = {
    device = "/dev/disk/by-uuid/2251e0b4-fe3b-4cfd-b0c6-3b0e5a9bc96b";
    fsType = "ext4";

    # Optimize SSD
    # ---------------------------------------------
    # mountOptions = defaultXfsOpts;
    options = [
      "data=ordered"        # Ensures data is written to the journal before being committed to the file system.
      "defaults"            # Standard mount options for read-write access, program execution, device interpretation, automatic mounting, and more.
      "discard"             # Enables automatic trimming of unused blocks on SSDs.
      "errors=remount-ro"   # Remounts the file system as read-only upon encountering errors to protect data.
      "noatime"             # Disables access time updates for all files, significantly improving performance.
      "nodiratime"          # Disables access time updates for directories, improving performance.
      "relatime"            # Updates access time only if needed, balancing performance and access time tracking.
    ];

  };

  fileSystems."/boot" = {
    device = "/dev/disk/by-uuid/E73E-5FCA";
    fsType = "vfat";
  };

  # Add a file system entry for the "Public" directory bind mount
  #fileSystems."/home/tolga/Public" = {
  #  device = "/home/tolga/Public";
  #  fsType = "none";
  #  options = [ "bind" "rw" ];  # Read-write access
  #};

  # Add a file system entry for the "Public" directory bind mount
  fileSystems."/mnt/public_access" = {
    device = "/home/tolga/Public";
    fsType = "none";
    options = [ "bind" "rw" ];  # Read-write access
};

  #---------------------------------------------------------------------
  # Mounting options for samba
  #---------------------------------------------------------------------
  fileSystems."/mnt/sambashare" =

    {
      device = "//192.168.0.20/LinuxData/HOME/PROFILES/NIXOS-23-05/TOLGA/";
      fsType = "cifs";
      options = let
        automountOpts =
          "x-systemd.automount,noauto,x-systemd.idle-timeout=60,x-systemd.device-timeout=5s,x-systemd.mount-timeout=5s,x-systemd.requires=network.target";
        uid =
          "1000"; # Replace with your actual user ID, use `id -u <YOUR USERNAME>` to get your user ID
        gid =
          "100"; # Replace with your actual group ID, use `id -g <YOUR USERNAME>` to get your group ID
        vers = "3.1.1";
        cacheOpts = "cache=loose";
        credentialsPath = "/etc/nixos/core/system/network/smb-secrets";

      in [
        "${automountOpts},credentials=${credentialsPath},uid=${uid},gid=${gid},vers=${vers},${cacheOpts}"
      ];

    };

  #---------------------------------------------------------------------
  # Swap device configuration
  #---------------------------------------------------------------------
  swapDevices =
    [{ device = "/dev/disk/by-uuid/60d7ba76-84fb-4252-9ec9-abd5fbe25db7"; }];

  #---------------------------------------------------------------------
  # Networking configurations
  #---------------------------------------------------------------------
  networking.useDHCP = lib.mkDefault true;

  #---------------------------------------------------------------------
  # Host platform and hardware configurations
  #---------------------------------------------------------------------
  nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
  hardware.cpu.intel.updateMicrocode =
    lib.mkDefault config.hardware.enableRedistributableFirmware;
}
