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

{
  imports =
    [ 
      inputs.hardware.nixosModules.common-cpu-intel-cpu-only
      inputs.hardware.nixosModules.common-gpu-nvidia-nonprime
    
      (modulesPath + "/installer/scan/not-detected.nix")
    ];

  boot.initrd.availableKernelModules = [ "xhci_pci" "ehci_pci" "ahci" "usbhid" "usb_storage" "sd_mod" "sdhci_pci" ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ "kvm-intel" ];
  boot.extraModulePackages = [ ];
  
  boot.loader = {
    # use systemd-boot over grub
    grub.enable = lib.mkForce false;
    systemd-boot.enable = true;
    efi.canTouchEfiVariables = true;
  };

  # support power features such as suspend to ram
  powerManagement.enable = true;
  # tune power saving options on boot
  # todo: fix usb mice and keyboards from suspending
  #powerManagement.powertop.enable = true;
  # thermald proactively prevents overheating on intel CPUs and works well with other tools
  services.thermald.enable = true;
  # power-profile-daemon for power management
  services.power-profiles-daemon.enable = true;

  # nvidia driver
  services.xserver.videoDrivers = [ "nvidia" ];

  hardware.nvidia = {
    package = config.boot.kernelPackages.nvidiaPackages.beta;

    modesetting.enable = true;

    powerManagement.enable = true;
  };

  boot.kernelParams = [
    # use experimental nvidia supplied framebuffer
    "nvidia-drm.fbdev=1"
  ];

  # VA-API
  hardware.opengl = {
    extraPackages = with pkgs; [
      nvidia-vaapi-driver
    ];
  };

  environment.variables = {
    LIBVA_DRIVER_NAME= "nvidia";
    VDPAU_DRIVER = "nvidia";
    # TODO: remove this once nvidia gets their shit together
    # https://forums.developer.nvidia.com/t/cueglstreamproducerconnect-returns-error-801-on-525-53-driver/233610/20
    NVD_BACKEND = "direct";
    # VA-API on firefox
    MOZ_DISABLE_RDD_SANDBOX = "1";
  };

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/08cfbb11-5943-4627-a2fc-fd41ce578027";
      fsType = "ext4";
    };

  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/C321-2746";
      fsType = "vfat";
    };

  swapDevices =
    [ { device = "/dev/disk/by-uuid/04eddb76-4925-4192-a472-1c2c7e4ac9f7"; }
    ];

  # Enables DHCP on each ethernet and wireless interface. In case of scripted networking
  # (the default) this is the recommended approach. When using systemd-networkd it's
  # still possible to use this option, but it's recommended to use it in conjunction
  # with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
  networking.useDHCP = lib.mkDefault true;
  # networking.interfaces.end0.useDHCP = lib.mkDefault true;
  # networking.interfaces.wlan0.useDHCP = lib.mkDefault true;

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