#
# Per-system configuration for Utol
#
# vim: et:ts=2:sw=2:
#
{
  lib,
  pkgs,
  config,
  modulesPath,
  ...
}:
{
  system.stateVersion = "23.11";
  imports = [
    (modulesPath + "/installer/scan/not-detected.nix")
    ./cellular.nix
    ./power-saving.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 = "utol";
  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 fingerprint reader.
  services.fprintd.enable = true;

  # Support finer Ryzen control.
  hardware.cpu.amd.ryzen-smu.enable = true;
  programs.ryzen-monitor-ng.enable = true;
  environment.systemPackages = [
    pkgs.ryzenadj
  ];

  # 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 18;

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

  fileSystems."/" = {
    device = "/dev/disk/by-uuid/f71b83c9-c375-4684-8671-7770dfe3db89";
    fsType = "ext4";
  };

  fileSystems."/boot" = {
    device = "/dev/disk/by-uuid/5295-6CD7";
    fsType = "vfat";
    options = [
      "fmask=0022"
      "dmask=0022"
    ];
  };

  swapDevices = [
    { device = "/dev/disk/by-uuid/18677338-4b9c-4241-9a2e-2ecb53163968"; }
  ];

  # 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.enp2s0f0.useDHCP = lib.mkDefault true;
  # networking.interfaces.enp5s0.useDHCP = lib.mkDefault true;
  # networking.interfaces.wlp3s0.useDHCP = lib.mkDefault true;

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