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

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

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

  # Networking.
  networking.hostName = "aigis";
  networking.firewall.enable = false;

  # Use kwin for sddm instead of westin, to account for multi-monitor.
  services.displayManager.sddm.wayland.compositor = "kwin";
  networking.networkmanager.enable = true;

	# Set up Apple Silicon features.
  hardware.asahi = {
    peripheralFirmwareDirectory = ../../apple-silicon-support/firmware;
		useExperimentalGPUDriver = true;
  };

  # Run an ssh-agent locally.
  programs.ssh.startAgent = true;

	# Make Niri work on this machine. :)
  home-manager.users.deprekated = {
    programs.niri.settings = {
			outputs."eDP-1".scale = 1.5;

      # Forcibly override the render-node detection, as it doesn't work on Apple Silicon.
      debug.render-drm-device = "/dev/dri/renderD128";
    };
  };

  systemd.services.display-manager = {
		after = [ "touchbar.service" ];
		requires = [ "touchbar.service" ];
  };

	# Provide touch bar support.
	systemd.services.touchbar = {
		before = [ "display-manager.service" ];
		wantedBy = [ "graphical-session.target" ];

		serviceConfig = {
			Type = "simple";
			ExecStart = "${pkgs.tiny-dfr}/bin/tiny-dfr";
		};
	};

  # Be able to run x64 binaries, because they're everywhere.
  boot.binfmt.emulatedSystems = [
		"x86_64-linux"
  ];

	# Set UI font sizes to work with this machine.
  stylix.fonts.sizes.desktop = lib.mkForce 16;


  #
  # Hardware config.
  #
  boot.initrd.availableKernelModules = [ "usb_storage" ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ ];
  boot.extraModulePackages = [ ];

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/b4dd01d3-28b8-4c58-af86-9c96afa33263";
      fsType = "ext4";
    };

  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/077A-1AFE";
      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.wlan0.useDHCP = lib.mkDefault true;

  nixpkgs.hostPlatform = lib.mkDefault "aarch64-linux";
}
