{ config, lib, pkgs, ... }:

# Fingerprint scanner configuration
#
# Enable on laptops with a fingerprint reader:
#   hardware.fingerprint.enable = true;
#
# For some sensors (Goodix, Elan, Synaptics), you may also need to set
# the TOD driver:
#   hardware.fingerprint.todDriver = pkgs.libfprint-2-tod1-goodix;
#
# Reference: https://wiki.nixos.org/wiki/Fingerprint_scanner

let
  cfg = config.hardware.fingerprint;
in {
  options.hardware.fingerprint = {
    enable = lib.mkEnableOption "fingerprint scanner support (fprintd)";

    todDriver = lib.mkOption {
      description = "Touch OEM Drivers (TOD) package to use for the fingerprint sensor";
      type = lib.types.nullOr lib.types.package;
      default = null;
      example = lib.literalExpression "pkgs.libfprint-2-tod1-goodix";
    };
  };

  config = lib.mkIf cfg.enable {
    services.fprintd.enable = true;

    services.fprintd.tod = lib.mkIf (cfg.todDriver != null) {
      enable = true;
      driver = cfg.todDriver;
    };
  };
}
