{ pkgs, config, ... }:
let
  cfg = config.my.cachyosKernel;
in
{
  nix = {
    settings = {
      download-buffer-size = 200000000;
      auto-optimise-store = true;

      substituters = [
        "https://hyprland.cachix.org"
        "https://attic.xuyh0120.win/lantian"
        "https://nix-community.cachix.org"
        "https://ezkea.cachix.org"
      ];
      trusted-substituters = [ "https://hyprland.cachix.org" ];
      trusted-public-keys = [
        "hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc="
        "lantian:EeAUQ+W+6r7EtwnmYjeVwx5kOGEBpjlBfPlzGlTNvHc="
        "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
        "ezkea.cachix.org-1:ioBmUbJTZIKsHmWWXPe1FSFbeVe+afhfgqgTSNd34eI="
      ];

      experimental-features = [ "nix-command" "flakes" "pipe-operators" ];
    };
  };

  # Boot/Kernel Stuff
  boot = {
    kernelPackages = 
      (
        if cfg.enable
        then pkgs.cachyosKernels.linuxPackages-cachyos-latest-zen4
        else pkgs.linuxPackages_latest
      );
    kernelModules = ["v4l2loopback" "kvm-amd"];
    extraModulePackages = [config.boot.kernelPackages.v4l2loopback];
    kernel.sysctl = {"vm.max_map_count" = 2147483642;};
    loader.systemd-boot.enable = true;
    loader.efi.canTouchEfiVariables = true;
    # Appimage Support
    binfmt.registrations.appimage = {
      wrapInterpreterInShell = false;
      interpreter = "${pkgs.appimage-run}/bin/appimage-run";
      recognitionType = "magic";
      offset = 0;
      mask = ''\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff'';
      magicOrExtension = ''\x7fELF....AI\x02'';
    };
    plymouth.enable = true;
  };
}