nixos-config/pkgs/otpmenu/default.nix
Ingolf Wagner 7a6510a4e6
Some checks are pending
Build all NixOS Configurations / nix build (push) Waiting to run
nix fmt
2024-08-29 08:26:04 +07:00

64 lines
1.3 KiB
Nix

{
lib,
symlinkJoin,
rofi,
gnused,
pass,
writeTextFile,
writeShellScriptBin,
xdotool,
}:
let
name = "otpmenu";
desktopFile = writeTextFile {
name = "${name}.desktop";
destination = "/share/applications/${name}.desktop";
text = ''
[Desktop Entry]
Categories=Application;Utility;
Comment=Enter MFA number with password otp plugins otp
Encoding=UTF-8
Exec=${bin}/bin/${name}
Icon=gnome-lockscreen
Name=${name}
Terminal=false
Type=Application
'';
};
bin =
writeShellScriptBin name # sh
''
set -efu
x=$(
${pass.withExtensions (ext: [ ext.pass-otp ])}/bin/pass git ls-files '*/otp.gpg' \
| ${gnused}/bin/sed 's:/otp\.gpg$::' \
| ${rofi}/bin/rofi -dmenu -f -p OTP
)
otp=$(${pass.withExtensions (ext: [ ext.pass-otp ])}/bin/pass otp code "$x/otp")
printf %s "$otp" | ${xdotool}/bin/xdotool type -f -
'';
in
symlinkJoin rec {
version = "1.0.0";
name = "otpMenu-${version}";
paths = [
bin
desktopFile
];
meta = with lib; {
description = "similar to passmenu shows and prints otp";
homepage = "https://your.mama";
license = licenses.gpl3;
platforms = platforms.linux;
maintainers = with maintainers; [ mrVanDalo ];
};
}