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

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

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

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

  #
  # Niri configuration for our monitors.
  #

  # Disabled until we replace the monitor on this.
  #home-manager.users.deprekated.programs.niri.settings = {
  #  outputs."eDP-1".scale = 2.0;
  #};

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

  # Save power!
  services.udev.extraRules = ''
    ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030000", ATTR{power/control}="auto"
  '';

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

  # Disallow nouveau so the NVIDIA device is available for VFIO.
  boot.blacklistedKernelModules = [ "nouveau" ];
  boot.extraModprobeConfig = ''
    options nouveau modeset=0
  '';

  fileSystems."/" = {
    device = "/dev/disk/by-uuid/8d5584ce-527a-471b-bbb9-d4c0de3eb579";
    fsType = "ext4";
  };

  fileSystems."/boot" = {
    device = "/dev/disk/by-uuid/5B5B-5C98";
    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.wlp2s0.useDHCP = lib.mkDefault true;

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