{ stdenv, lib, writeScript, xclip, wl-clipboard, yubikey-manager }: let ykoath = writeScript "ykoath" '' #!${stdenv.shell} ${lib.getBin yubikey-manager}/bin/ykman oath accounts code $@ ''; ykclip = writeScript "ykclip" '' #!${stdenv.shell} X_SELECTION=''${YKCLIP_SELECTION:-clipboard} if [ -n "$WAYLAND_DISPLAY" ]; then cmd="${lib.getBin wl-clipboard}/bin/wl-copy" if [ "$X_SELECTION" = primary ]; then cmd="$cmd --primary" fi elif [ -n "$DISPLAY" ]; then cmd="${lib.getBin xclip}/bin/xclip -selection '$X_SELECTION'" else echo "Error: No graphical session detected"; exit 1 fi otp=$(${lib.getBin yubikey-manager}/bin/ykman oath accounts code -s $@) rv=$? if [ "$rv" -eq 0 ] && [ -n "$otp" ]; then printf "%s" "$otp" | $cmd else echo "Error: Receiving OTP"; exit 1 fi ''; in stdenv.mkDerivation { pname = "ykoath-tools"; version = "1"; buildCommand = '' mkdir -p "$out/bin" ln -s ${ykoath} "$out/bin/ykoath" ln -s ${ykclip} "$out/bin/ykclip" ''; meta = with lib; { description = "Make using OATH with yubikeys from the command-line easier."; maintainers = [ maintainers.spacefrogg ]; license = licenses.gpl3; }; }