dotfiles/defaults/user-configuration/fhauser/applications/scripts.nix

52 lines
1.3 KiB
Nix

{ pkgs, ... }:
let
passbemenu = pkgs.writeScriptBin "passbemenu" ''
#!${pkgs.stdenv.shell}
shopt -s nullglob globstar
typeit=0
if [[ $1 == "--type" ]]; then
typeit=1
shift
fi
export BEMENU_BACKEND=wayland
prefix=''${PASSWORD_STORE_DIR-~/.password-store}
password_files=( "$prefix"/**/*.gpg )
password_files=( "''${password_files[@]#"$prefix"/}" )
password_files=( "''${password_files[@]%.gpg}" )
password=$(printf '%s\n' "''${password_files[@]}" | \
${pkgs.bemenu}/bin/bemenu --list 20 --ignorecase --prompt 'Pass: ' "$@")
[[ -n $password ]] || exit
${pkgs.pass-wayland}/bin/pass show -c "$password" 2>/dev/null
'';
threema-vpn = pkgs.writeScriptBin "threema-vpn" ''
#!${pkgs.stdenv.shell}
set -eo pipefail
SERVICE=openvpn-threema.service
if [[ "$1" == "restart" ]]; then
ACTION=restart
elif [[ "$1" == "start" ]]; then
ACTION=start
elif [[ "$1" == "stop" ]]; then
ACTION=stop
elif [[ "$1" == "status" ]]; then
ACTION=status
elif [[ "$1" == "tail" ]]; then
sudo journalctl -f -u $SERVICE
exit 0
else
echo "Usage: vpn (start|stop|restart|status|tail)"
exit 254
fi
sudo systemctl $ACTION $SERVICE
'';
in { home-manager.users.fhauser.home.packages = [ passbemenu threema-vpn ]; }