{ config, pkgs, ... }:
{
  # Much quieter CPU fan on Tuxedo AMD Ryzen laptop.
  # https://github.com/AaronErhardt/tuxedo-rs?tab=readme-ov-file#nixos

  # Check if the configuration is still valid:
  #   systemctl status tailord.service
  #   #=> Starting Tuxedo Tailor hardware control service...
  #   #=> INFO start_runtime: tailord: Starting tailord
  #   #=> INFO start_runtime: tailord::profiles: Loaded profile at `/etc/tailord/active_profile.json`: ...
  #   #=> INFO ...
  # There should be no error messages!

  hardware.tuxedo-rs = {
    enable = true;
    # Whether to enable tailor-gui, an alternative to TUXEDO Control Center, written in Rust.
    # tailor-gui: Rust GUI for interacting with hardware from TUXEDO Computers.
    tailor-gui.enable = false;
  };

  environment.etc."tailord/active_profile.json".source = "/etc/tailord/profiles/custom.json";

  environment.etc."tailord/profiles/custom.json".text = ''
    {"fans":["custom"],"leds":[{"device_name":"platform:tuxedo_keyboard","function":"kbd_backlight","profile":"custom","mode":"Monochrome"}],"performance_profile":"power_save"}
  '';

  environment.etc."tailord/keyboard/custom.json".text = ''
    "None"
  '';

  # https://github.com/AaronErhardt/tuxedo-rs/blob/910e73794b80843faa49a630d7c2a114daef508c/tailord/src/fancontrol/profile.rs#L122
  environment.etc."tailord/fan/custom.json".text = ''
  [
    {"temp":50,"fan":0},
    {"temp":55,"fan":10},
    {"temp":60,"fan":20},
    {"temp":65,"fan":30},
    {"temp":70,"fan":40},
    {"temp":80,"fan":70},
    {"temp":90,"fan":100}
  ]
  '';
}