ykoath-tools: init at 1
Two small shell wrappers around `ykman oath` to make access to OATH tokens on yubikeys easier. `ykoath` is just a shortcut for `ykman oath accounts code` `ykclip` copies the OTP to the clipboard. Set YKCLIP_SELECTION to the X/Wayland selection you want to use. (Defaults to clipboard)21.11
parent
65218d2d20
commit
8b781c57dd
|
@ -12,6 +12,8 @@ in rec {
|
|||
|
||||
snipe-it = callPackage ./pkgs/snipe-it { };
|
||||
|
||||
ykoath-tools = callPackage ./pkgs/ykoath-tools { };
|
||||
|
||||
} // optionalAttrs (pkgs.system == "x86_64-linux") rec {
|
||||
|
||||
ryzen_smu = callPackage ./pkgs/ryzen_smu { kernel = pkgs.linux; };
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
{ 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;
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue