#
# Fixes an issue where pcsclite doesn't 
#
# vim: et:ts=2:sw=2:
#
{ lib, pkgs, ... }:
let

  overlay =
    final': prev':
    let
      depsPath =
        with prev';
        lib.makeBinPath [
          coreutils
          grim
          gawk
          jq
          swaylock
          imagemagick
          getopt
          fontconfig
          wmctrl
        ];

    in
    {
      nirilock-fancy = prev'.swaylock-fancy.overrideAttrs (
        final: prev: {

          # Patch this to use niri instead of swaylock, and to increase the blur.
          postPatch = ''
            substituteInPlace swaylock-fancy \
              --replace-fail \
                "poutputs=\$(swaymsg -t get_outputs | jq -r '.[] | select(.active != false) | .name')" \
                "poutputs=\$(niri msg -j outputs | jq -r '.[] | .name')" \
              --replace-fail \
                "filter:sigma=1.5" \
                "filter:sigma=2.5"
          '';

          # Create our Nirilock script.
          postInstall = ''
            mv $out/bin/swaylock-fancy $out/bin/nirilock-fancy
            wrapProgram $out/bin/nirilock-fancy \
              --prefix PATH : "${depsPath}"
          '';

        }
      );
    };
in
{
  nixpkgs.overlays = [ overlay ];
}
