#
# Per-system configuration for Komashi.
#
# vim: et:ts=2:sw=2:
#
{
  lib,
  pkgs,
  config,
  modulesPath,
  ...
}:
{
  system.stateVersion = "23.11";
  imports = [
    (modulesPath + "/installer/scan/not-detected.nix")
    ./cellular.nix
  ];

  # Bootloader.
  boot.loader.systemd-boot = {
    enable = true;

    # Include the UEFI shell.
    extraFiles = {
      "efi/shell/shell.efi" = "${pkgs.edk2-uefi-shell}/shell.efi";
    };
    extraEntries = {
      "shell.conf" = ''
        title UEFI Shell
        efi /efi/shell/shell.efi
        sort-key z_shell
      '';
    };
  };

  boot.loader.efi.canTouchEfiVariables = true;

  # Networking.
  networking.hostName = "komashi";
  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;

  # Support our Thunderbolt3 port.
  services.hardware.bolt.enable = true;

  # Support our fingerprint reader.
  services.fprintd.enable = true;

  # Support bluetooth.
  hardware.bluetooth = {
    enable = true;
    powerOnBoot = false;

    settings = {
      General = {

        # Support A2DP.
        Enable = "Source,Sink,Media,Socket";

        # Enable experimental featurees, like reading device battery levels.
        Experimental = true;
      };

    };
  };

  services.blueman.enable = true;

  # Override stylix font sizes.
  stylix.fonts.sizes.desktop = lib.mkForce 16;

  #
  # Hardware config.
  #
  boot.initrd.availableKernelModules = [
    "xhci_pci"
    "nvme"
    "usb_storage"
    "sd_mod"
    "rtsx_pci_sdmmc"
    "thunderbolt"
  ];
  boot.initrd.kernelModules = [ ];

  boot.kernelModules = [
    "kvm-intel"
    "thunderbolt"
    "acpi_call"
  ];
  boot.extraModulePackages = [ config.boot.kernelPackages.acpi_call ];

  fileSystems."/" = {
    device = "/dev/disk/by-uuid/d1b23c80-a9d3-4142-a26f-2318018d767d";
    fsType = "ext4";
  };

  fileSystems."/boot" = {
    device = "/dev/disk/by-uuid/0958-3417";
    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.docker0.useDHCP = lib.mkDefault true;
  # networking.interfaces.enp0s31f6.useDHCP = lib.mkDefault true;
  # networking.interfaces.tailscale0.useDHCP = lib.mkDefault true;
  # networking.interfaces.wlp0s20f3.useDHCP = lib.mkDefault true;

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