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

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

  boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "usb_storage" "usbhid" "sd_mod" ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ "kvm-intel" ];
  boot.extraModulePackages = [ config.boot.kernelPackages.broadcom_sta ];
  boot.blacklistedKernelModules = [ "b43" "bcma" "ssb" ];
  boot.kernelParams = [ "acpi_osi=" ];

  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  fileSystems."/" = {
    device = "/dev/disk/by-uuid/e295ac26-bf7e-4b93-bc97-74c3c01de0e3";
    fsType = "ext4";
  };

  fileSystems."/boot" = {
    device = "/dev/disk/by-uuid/F698-F2B7";
    fsType = "vfat";
    options = [ "fmask=0077" "dmask=0077" ];
  };

  swapDevices = [ ];

  nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
  hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
  networking.hostName = "FredOS-Macbook";
  hardware.enableRedistributableFirmware = true;
  hardware.facetimehd.enable = true;

  # wait_prepare/wait_finish were removed from struct vb2_ops in Linux 6.8
  nixpkgs.overlays = [
    (final: prev: {
      linuxPackages_latest = prev.linuxPackages_latest.extend (lpFinal: lpPrev: {
        facetimehd = lpPrev.facetimehd.overrideAttrs (old: {
          postPatch = (old.postPatch or "") + ''
            sed -i '/\.wait_prepare[[:space:]]*=.*vb2_ops_wait_prepare/d' fthd_v4l2.c
            sed -i '/\.wait_finish[[:space:]]*=.*vb2_ops_wait_finish/d' fthd_v4l2.c
          '';
        });
      });
    })
  ];

  nixpkgs.config.allowInsecurePredicate = pkg:
    (lib.hasPrefix "broadcom-sta" (lib.getName pkg));

  services.xserver.deviceSection = lib.mkDefault ''
      Option "TearFree" "true"
    '';

  hardware.bluetooth = {
    enable = true;
    powerOnBoot = true;
    settings = {
      General = {
        Enable = "Source,Sink,Media,Socket";
        Experimental = true;
      };
    };
  };

  system.stateVersion = "25.11";
}
