{
  config,
  lib,
  pkgs,
  pkgs-unoptimized,
  ...
}:
{
  imports = [ ];

  config = lib.mkMerge [
    { }
    (lib.mkIf (!config.me.optimizations.enable) {
      boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux_6_14;
    })
    (lib.mkIf (config.me.optimizations.enable) {
      nixpkgs.hostPlatform = {
        gcc.arch = "znver5";
        gcc.tune = "znver5";
        system = "x86_64-linux";
      };

      nixpkgs.overlays = [
        (
          final: prev:
          let
            addConfig =
              additionalConfig: pkg:
              pkg.override (oldconfig: {
                structuredExtraConfig = pkg.structuredExtraConfig // additionalConfig;
              });
          in
          {
            linux_me = addConfig {
              # Full preemption
              PREEMPT = lib.mkOverride 60 lib.kernel.yes;
              PREEMPT_VOLUNTARY = lib.mkOverride 60 lib.kernel.no;

              # Google's BBRv3 TCP congestion Control
              TCP_CONG_BBR = lib.kernel.yes;
              DEFAULT_BBR = lib.kernel.yes;

              # Preemptive Full Tickless Kernel at 300Hz
              HZ = lib.kernel.freeform "300";
              HZ_300 = lib.kernel.yes;
              HZ_1000 = lib.kernel.no;
            } prev.linux_6_14;
          }
        )
        (final: prev: {
          haskellPackages = prev.haskellPackages.extend (
            final': prev': {
              inherit (pkgs-unoptimized.haskellPackages)
                crypton
                crypton-connection
                crypton-x509
                crypton-x509-store
                crypton-x509-system
                crypton-x509-validation
                hspec-wai
                http-client-tls
                http2
                pandoc
                pandoc-cli
                pandoc-lua-engine
                pandoc-server
                servant-server
                tls
                wai-app-static
                wai-extra
                warp
                ;
            }
          );
        })
        (final: prev: {
          inherit (pkgs-unoptimized)
            gsl
            redis
            valkey
            ;
        })
      ];

      boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux_me;
    })
    (lib.mkIf (!config.me.buildingIso) {
      nix.settings.system-features = lib.mkForce [
        "gccarch-znver4"
        "gccarch-znver5"
        "gccarch-skylake"
        # "gccarch-alderlake" missing WAITPKG
        "gccarch-x86-64-v3"
        "gccarch-x86-64-v4"
        "benchmark"
        "big-parallel"
        "kvm"
        "nixos-test"
      ];

      # Keep ALL dependencies so we can rebuild offline. This DRASTICALLY increase disk usage, but disk space is cheap.
      # system.includeBuildDependencies = true;

      # This also should enable building offline? TODO: test.
      nix.extraOptions = ''
        keep-outputs = true
        keep-derivations = true
      '';

      # # building ON
      # nixpkgs.localSystem = { system = "aarch64-linux"; };
      # # building FOR
      # nixpkgs.crossSystem = { system = "aarch64-linux"; };

      # nixpkgs.config = {
      #   replaceStdenv = ({ pkgs }: pkgs.clangStdenv);
      # };
      # or maybe an overlay
      # stdenv = prev.clangStdenv;

    })
    (lib.mkIf (config.me.buildingIso) {
      boot.supportedFilesystems.zfs = true;
    })
  ];
}