# Do not modify this file!  It was generated by ‘nixos-generate-config’

{ config, lib, pkgs, modulesPath, ... }:

with lib;

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

  boot = {
    initrd.availableKernelModules =
      [ 
        "ahci" 
        "nvme" 
        "sd_mod"
        "usb_storage" 
        "usbhid" 
        "xhci_pci" 
        
      ];
      
    initrd.kernelModules = [ ];
    kernelModules = [ "kvm-intel" "tcp_bbr" ];
    extraModulePackages = [ ];

    kernel.sysctl = {
      "net.ipv4.tcp_congestion_control" = "bbr";     # Tweak local networking
      "net.core.netdev_max_backlog" = 30000;
      "net.core.rmem_default" = 262144;
      "net.core.rmem_max" = 67108864;
      "net.core.wmem_default" = 262144;
      "net.core.wmem_max" = 67108864;
      "net.ipv4.ipfrag_high_threshold" = 5242880;
      "net.ipv4.tcp_keepalive_intvl" = 30;
      "net.ipv4.tcp_keepalive_probes" = 5;
      "net.ipv4.tcp_keepalive_time" = 300;
      "vm.dirty_background_bytes" = 583200768;      # 556 MB (128 MB + 450 MB)
      "vm.dirty_bytes" = 851968768;                 # 812 MB (384 MB + 450 MB)
      "vm.min_free_kbytes" = 65536;                 # Minimum free memory for safety (in KB)
      "vm.swappiness" = 0;
      "vm.vfs_cache_pressure" = 90;

      # Adjust dirty data management for NVMe drives
      "vm.dirty_background_ratio" = "5";            # Set the ratio of dirty memory at which background writeback starts (5%).
      "vm.dirty_expire_centisecs" = "3000";         # Set the time at which dirty data is old enough to be eligible for writeout (3000 centiseconds).
      "vm.dirty_ratio" = "10";                      # Set the ratio of dirty memory at which a process is forced to write out dirty data (10%).
      "vm.dirty_time" = "0";                        # Disable dirty time accounting.
      "vm.dirty_writeback_centisecs" = "300";       # Set the interval between two consecutive background writeback passes (300 centiseconds).

    };

    kernelParams = [
      "mitigations=off"
      "quiet"
      "video.allow_duplicates=1"

    ];

  };

  fileSystems."/" = {
    device = "/dev/disk/by-uuid/42538635-cc9e-40fd-aaee-15df49bd0305";
    fsType = "ext4";
    options = [

      # Optimised && suitable for SSDs and NVMe drives to ensure good performance and longevity.
      "commit=600"                  # nvme tweak?
      "data=ordered"                # Ensures data ordering, improving file system reliability and performance by writing data to disk in a specific order.
      "defaults"                    # Applies the default options for mounting, which usually include common settings for permissions, ownership, and read/write access.
      "discard=async"               # Enables the TRIM command, which allows the file system to notify the storage device of unused blocks, improving performance and longevity of solid-state drives (SSDs).
      "errors=remount-ro"           # Remounts the file system as read-only (ro) in case of errors to prevent further potential data corruption.
      "noatime"                     # Disables updating access times for files, improving file system performance by reducing write operations.
      "nodiratime"                  # Disables updating directory access time, improving file system performance by reducing unnecessary writes.
      "relatime"                    # Updates the access time of files relative to the modification time, minimizing the performance impact compared to atime

    ];

  };

  fileSystems."/boot" = {
    device = "/dev/disk/by-uuid/FBA2-6FFE";
    fsType = "vfat";
  };

  fileSystems."/mnt/DLNA" = {
    device = "/home/tolga/DLNA/";

    # "none" for bind mount
    fsType = "none";              
    options = ["rw" "bind"];
    # http://192.168.0.13:8200/
  };

 #---------------------------------------------------------------------
  # 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},rw,vers=${vers},${cacheOpts}"
      ];

    };


  swapDevices =
    [{ device = "/dev/disk/by-uuid/3d5fb72d-f37c-4ad8-b349-942a8e98bbc6"; }];

  networking.useDHCP = lib.mkDefault true;
  nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";  
  hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}
