#
# Per-system configuration for Miko.
#
# vim: et:ts=2:sw=2:
#
{
  config,
  lib,
  pkgs,
  deprekages,
  modulesPath,
  ...
}:
{
  system.stateVersion = "23.11";

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

	# Use the more up-to-date touchBar option to enabel the touchbar.
  hardware.apple-t2.enableTinyDfr = false;
  hardware.apple.touchBar = {
    enable = true;
    settings = {};
  };

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

  # Networking.
  networking.hostName = "miko";
  networking.networkmanager.enable = true;
  networking.firewall.enable = false;

  # This is a local machine, rather than our typical network-accesed ones.
  # Run an ssh-agent locally.
  programs.ssh.startAgent = true;

  #
  # Hardware configuration.
  #
  boot.initrd.availableKernelModules = [ "xhci_pci" "nvme" "usbhid" "usb_storage" "sd_mod" "apple-bce" "appletbdrm" ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ "kvm-intel" ];
  boot.extraModulePackages = [ ];

  # Include firmware necessary for apple platforms.
  hardware.firmware = [
    (pkgs.stdenvNoCC.mkDerivation (final: {
      name = "brcm-firmware";
      src = ../../apple-t2-support/brcm;
      installPhase = ''
        mkdir -p $out/lib/firmware/brcm
        cp ${final.src}/* "$out/lib/firmware/brcm"
      '';
    }))
  ];

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/ba795284-58d4-4389-b5b6-8d60bcd557a2";
      fsType = "ext4";
    };

  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/5F66-17ED";
      fsType = "vfat";
      options = [ "fmask=0022" "dmask=0022" ];
    };

  swapDevices = [ ];

  # 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.enp230s0f1u1.useDHCP = lib.mkDefault true;
  # networking.interfaces.wlp229s0.useDHCP = lib.mkDefault true;

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