vm.sh: refactor into remote.sh with argc
Signed-off-by: Myned <dev@bjork.tech>
This commit is contained in:
parent
8452222017
commit
3237b034b9
7 changed files with 667 additions and 613 deletions
|
@ -7,6 +7,7 @@
|
|||
}:
|
||||
with lib; let
|
||||
audio = "~/.local/bin/audio";
|
||||
cat = "${pkgs.coreutils}/bin/cat";
|
||||
clipse = "${pkgs.clipse}/bin/clipse";
|
||||
codium = "${config.home-manager.users.${config.custom.username}.programs.vscode.package}/bin/codium";
|
||||
firefox-esr = "${config.home-manager.users.${config.custom.username}.programs.firefox.finalPackage}/bin/firefox-esr";
|
||||
|
@ -28,6 +29,7 @@ with lib; let
|
|||
onlyoffice = "${pkgs.onlyoffice-bin}/bin/onlyoffice-desktopeditors --system-title-bar --xdg-desktop-portal";
|
||||
pkill = "${pkgs.procps}/bin/pkill";
|
||||
playerctl = "${pkgs.playerctl}/bin/playerctl";
|
||||
remote = config.home-manager.users.${config.custom.username}.home.file.".local/bin/remote".source;
|
||||
rofi-rbw = "${pkgs.rofi-rbw}/bin/rofi-rbw";
|
||||
rm = "${pkgs.coreutils}/bin/rm";
|
||||
screenshot = "~/.local/bin/screenshot";
|
||||
|
@ -38,7 +40,6 @@ with lib; let
|
|||
systemctl = "${pkgs.systemd}/bin/systemctl";
|
||||
toggle = "~/.local/bin/toggle";
|
||||
virt-manager = "${config.programs.virt-manager.package}/bin/virt-manager";
|
||||
vm = config.home-manager.users.${config.custom.username}.home.file.".local/bin/vm".source;
|
||||
vrr = config.home-manager.users.${config.custom.username}.home.file.".local/bin/vrr".source;
|
||||
walker = "${config.home-manager.users.${config.custom.username}.programs.walker.package}/bin/walker";
|
||||
waydroid = "${pkgs.waydroid}/bin/waydroid";
|
||||
|
@ -50,7 +51,18 @@ with lib; let
|
|||
in {
|
||||
options.custom.desktops.hyprland.binds.enable = mkOption {default = false;};
|
||||
|
||||
config.home-manager.users.${config.custom.username} = mkIf cfg.enable {
|
||||
config = mkIf cfg.enable {
|
||||
age.secrets = let
|
||||
secret = filename: {
|
||||
file = "${inputs.self}/secrets/${filename}";
|
||||
owner = config.custom.username;
|
||||
group = "users";
|
||||
};
|
||||
in {
|
||||
"desktop/vm/myndows.pass" = secret "desktop/vm/myndows.pass";
|
||||
};
|
||||
|
||||
home-manager.users.${config.custom.username} = {
|
||||
wayland.windowManager.hyprland.settings = let
|
||||
# Reverse mods and key for alphabetical sorting
|
||||
#?? key <"KEY"> <"MODS"|null> <"DISPATCHER"> <"PARAMS"|null>
|
||||
|
@ -254,12 +266,11 @@ in {
|
|||
(key "V" "Super" "exec" "${kitty} --app-id clipboard --override font_size=12 ${clipse}")
|
||||
(key "V" "Super+Shift" "exec" "${clipse} --clear && ${notify-send} clipse 'Clipboard cleared' --urgency low")
|
||||
(key "W" "Super" "togglespecialworkspace" "vm")
|
||||
(key "W" "Super+Ctrl" "exec" "${vm} -x ${
|
||||
(key "W" "Super+Ctrl" "exec" ''${remote} --vm --username Myned --password "$(${cat} ${config.age.secrets."desktop/vm/myndows.pass".path})" ${
|
||||
if config.custom.hidpi
|
||||
then "/scale:140 +f"
|
||||
then "--scale 140"
|
||||
else ""
|
||||
}")
|
||||
(key "W" "Super+Ctrl+Shift" "exec" "${vm} ${virt-manager} --show-domain-console myndows")
|
||||
} myndows'')
|
||||
(key "W" "Super+Shift" "movetoworkspacesilent" "special:vm")
|
||||
(key "X" "Super" "workspace" "+1")
|
||||
(key "X" "Super+Shift" "movetoworkspacesilent" "+1")
|
||||
|
@ -268,4 +279,5 @@ in {
|
|||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
config,
|
||||
inputs,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
|
@ -24,6 +25,7 @@ with lib; let
|
|||
pkill = "${pkgs.procps}/bin/pkill";
|
||||
playerctl = "${pkgs.playerctl}/bin/playerctl";
|
||||
power = config.home-manager.users.${config.custom.username}.home.file.".local/bin/power".source;
|
||||
remote = config.home-manager.users.${config.custom.username}.home.file.".local/bin/remote".source;
|
||||
rfkill = "${pkgs.util-linux}/bin/rfkill";
|
||||
sleep = "${pkgs.coreutils}/bin/sleep";
|
||||
swaync-client = "${config.home-manager.users.${config.custom.username}.services.swaync.package}/bin/swaync-client";
|
||||
|
@ -32,7 +34,6 @@ with lib; let
|
|||
systemd-inhibit = "${pkgs.systemd}/bin/systemd-inhibit";
|
||||
tailscale = "${pkgs.tailscale}/bin/tailscale";
|
||||
tr = "${pkgs.coreutils}/bin/tr";
|
||||
vm = config.home-manager.users.${config.custom.username}.home.file.".local/bin/vm".source;
|
||||
vpn = config.home-manager.users.${config.custom.username}.home.file.".local/bin/vpn".source;
|
||||
wttrbar = "${pkgs.wttrbar}/bin/wttrbar";
|
||||
|
||||
|
@ -40,7 +41,18 @@ with lib; let
|
|||
in {
|
||||
options.custom.programs.waybar.enable = mkOption {default = false;};
|
||||
|
||||
config.home-manager.users.${config.custom.username} = mkIf cfg.enable {
|
||||
config = mkIf cfg.enable {
|
||||
age.secrets = let
|
||||
secret = filename: {
|
||||
file = "${inputs.self}/secrets/${filename}";
|
||||
owner = config.custom.username;
|
||||
group = "users";
|
||||
};
|
||||
in {
|
||||
"desktop/vm/myndows.pass" = secret "desktop/vm/myndows.pass";
|
||||
};
|
||||
|
||||
home-manager.users.${config.custom.username} = {
|
||||
# https://github.com/Alexays/Waybar
|
||||
# https://www.nerdfonts.com/cheat-sheet
|
||||
programs.waybar = {
|
||||
|
@ -148,11 +160,11 @@ in {
|
|||
"custom/vm" = {
|
||||
interval = 5;
|
||||
exec = "~/.config/waybar/scripts/vm.sh";
|
||||
on-click = "${vm} -x ${
|
||||
on-click = ''${remote} --vm --username Myned --password "$(${cat} ${config.age.secrets."desktop/vm/myndows.pass".path})" ${
|
||||
if config.custom.hidpi
|
||||
then "/scale:140"
|
||||
then "--scale 140"
|
||||
else ""
|
||||
}";
|
||||
} myndows'';
|
||||
};
|
||||
|
||||
"custom/vpn" = {
|
||||
|
@ -410,4 +422,5 @@ in {
|
|||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -143,6 +143,15 @@ in {
|
|||
libnotify
|
||||
power-profiles-daemon
|
||||
])
|
||||
(bash "remote" [
|
||||
argc
|
||||
coreutils
|
||||
freerdp3
|
||||
iputils
|
||||
libnotify
|
||||
libvirt
|
||||
remmina
|
||||
])
|
||||
(bash "scratchpad" [
|
||||
coreutils
|
||||
libnotify
|
||||
|
@ -166,14 +175,6 @@ in {
|
|||
jq
|
||||
libnotify
|
||||
])
|
||||
(bash "vm" [
|
||||
coreutils
|
||||
freerdp3
|
||||
iputils
|
||||
libnotify
|
||||
libvirt
|
||||
remmina
|
||||
])
|
||||
(bash "vpn" [
|
||||
gnused
|
||||
jq
|
||||
|
|
73
options/custom/scripts/remote.sh
Normal file
73
options/custom/scripts/remote.sh
Normal file
|
@ -0,0 +1,73 @@
|
|||
#! /usr/bin/env bash
|
||||
|
||||
# @describe Wrapper for connecting to remote desktops
|
||||
#
|
||||
# https://github.com/sigoden/argc
|
||||
|
||||
# @meta combine-shorts
|
||||
# @option -C --client=remmina Remote desktop client to connect with (remmina or <x|w|sdl>-freerdp)
|
||||
# @option -P --password Password to connect with
|
||||
# @option -S --scale=100 Set FreeRDP resolution scale
|
||||
# @option -U --username! Username to connect with
|
||||
# @flag -v --vm Handle libvirt VM domain state for connection
|
||||
# @arg host! Remote host/VM to connect to
|
||||
|
||||
eval "$(argc --argc-eval "$0" "$@")"
|
||||
|
||||
# Handle VM state
|
||||
#!! Requires libvirt networking with hostname resolution
|
||||
if [[ "${argc_vm:-}" ]]; then
|
||||
state="$(virsh domstate "${argc_host:-}")"
|
||||
|
||||
if [[ "$state" == "paused" ]]; then
|
||||
virsh resume "${argc_host:-}"
|
||||
notify-send "> remote" "${argc_host:-} resumed" --urgency low
|
||||
elif [[ "$state" == "shut off" ]]; then
|
||||
virsh start "${argc_host:-}"
|
||||
notify-send "> remote" "${argc_host:-} starting..." --urgency low
|
||||
|
||||
# Wait for guest to become available
|
||||
#!! Requires ICMP firewall access on guest
|
||||
c=0
|
||||
while ! ping -c 1 "${argc_host:-}"; do
|
||||
if ((c > 60)); then
|
||||
notify-send "> remote" "${argc_host:-} timed out" --urgency critical
|
||||
exit 1
|
||||
fi
|
||||
((c += 1))
|
||||
sleep 1
|
||||
done
|
||||
else
|
||||
notify-send "> remote" "${argc_host:-} online" --urgency low
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${argc_client:-}" == "remmina" ]]; then
|
||||
remmina --connect "rdp://${argc_username:-}:${argc_password:-}@${argc_host:-}"
|
||||
elif [[ "${argc_client:-}" =~ ^.+freerdp$ ]]; then
|
||||
export SDL_VIDEODRIVER=wayland
|
||||
|
||||
flags=(
|
||||
"/cert:ignore"
|
||||
"/v:${argc_host:-}"
|
||||
"/u:${argc_username:-}"
|
||||
"/p:${argc_password:-}"
|
||||
"/kbd:remap:015b=0154" # VK_LWIN=<00> #?? xfreerdp /list:kbd-scancode
|
||||
"/scale:${argc_scale:-}"
|
||||
"/dynamic-resolution"
|
||||
"/sound"
|
||||
"+auto-reconnect"
|
||||
"+clipboard"
|
||||
"+menu-anims"
|
||||
"-grab-keyboard"
|
||||
"-grab-mouse"
|
||||
)
|
||||
|
||||
"${argc_client:-}" "${flags[@]}"
|
||||
fi
|
||||
|
||||
# Suspend VM after connection ends
|
||||
if [[ "${argc_vm:-}" ]]; then
|
||||
virsh suspend "${argc_host:-}"
|
||||
notify-send "> remote" "${argc_host:-} paused" --urgency low
|
||||
fi
|
|
@ -1,57 +0,0 @@
|
|||
#! /usr/bin/env bash
|
||||
|
||||
# Start/resume VM if needed and launch viewer
|
||||
#?? man xfreerdp
|
||||
|
||||
state="$(virsh domstate myndows)"
|
||||
|
||||
if [[ "$state" == 'paused' ]]; then
|
||||
virsh resume myndows
|
||||
notify-send '> vm' 'Resumed' --urgency low
|
||||
elif [[ "$state" == 'shut off' ]]; then
|
||||
virsh start myndows
|
||||
notify-send '> vm' 'Starting...' --urgency low
|
||||
|
||||
# Wait for guest to become available
|
||||
#!! Requires ICMP firewall access on guest
|
||||
while ! ping -c 1 myndows; do
|
||||
sleep 1
|
||||
done
|
||||
else
|
||||
notify-send '> vm' 'Online' --urgency low
|
||||
fi
|
||||
|
||||
flags=(
|
||||
'/cert:ignore'
|
||||
'/v:myndows'
|
||||
'/u:Myned'
|
||||
'/p:'
|
||||
'/kbd:remap:015b=0154' # VK_LWIN=<00> #?? xfreerdp /list:kbd-scancode
|
||||
'/dynamic-resolution'
|
||||
'/sound'
|
||||
'+auto-reconnect'
|
||||
'+clipboard'
|
||||
'+menu-anims'
|
||||
'-grab-keyboard'
|
||||
'-grab-mouse'
|
||||
)
|
||||
|
||||
if [[ "${1-}" == '-s' ]]; then
|
||||
SDL_VIDEODRIVER=wayland sdl-freerdp "${flags[@]}" "${@:2}"
|
||||
virsh suspend myndows
|
||||
notify-send '> vm' 'Paused' --urgency low
|
||||
elif [[ "${1-}" == '-w' ]]; then
|
||||
wlfreerdp "${flags[@]}" "${@:2}"
|
||||
virsh suspend myndows
|
||||
notify-send '> vm' 'Paused' --urgency low
|
||||
elif [[ "${1-}" == '-x' ]]; then
|
||||
xfreerdp "${flags[@]}" "${@:2}"
|
||||
virsh suspend myndows
|
||||
notify-send '> vm' 'Paused' --urgency low
|
||||
elif [[ "${1-}" == '-e' ]]; then
|
||||
"$@"
|
||||
virsh suspend myndows
|
||||
notify-send '> vm' 'Paused' --urgency low
|
||||
else
|
||||
"$@"
|
||||
fi
|
11
secrets/desktop/vm/myndows.pass
Normal file
11
secrets/desktop/vm/myndows.pass
Normal file
|
@ -0,0 +1,11 @@
|
|||
age-encryption.org/v1
|
||||
-> ssh-ed25519 8E6j8Q 8osU9NmgeeyA6MiQv1gNNDFvAheWZINmFoxTPgsr1Dw
|
||||
OjviEydBFd1u9doZYGDdqQkMYe4pq7Q9U2qqBTqEcwY
|
||||
-> ssh-ed25519 sfxzoQ 4ve1W5A9VYReikSUNX2J5hRSvQXvteVl5AXL+rH5tHw
|
||||
cA1A8vrUXexDu4Z67TmUoHyRqKbC4PIrKRlb5PZyWbg
|
||||
-> ssh-ed25519 g5GcDQ zhhW9p+0Bgs24yLBZgl51mKyYuZwm9sbj7UWPt5/ZTw
|
||||
pYYHhUX7VVVkoB1EewK27cacZf4eNZJg73zogfQbTVg
|
||||
-> ssh-ed25519 T/dATA nhTYHjuLQxq9Kn2xHLpPNOYiAnEsut+6pxY35ooMAik
|
||||
Dgr+wBPVI9lD2+SLsvkom+0WJ3XlRZsysMQoMjVeCZA
|
||||
--- 234YbLb3XbZts393OGxe2Gmxrup7cbcQGXAb5gQLrhQ
|
||||
Ëú0gÿŸ(]/u&*EǵijeæðtAP¦áŽ—Üîö¸ˆéäÈ™åýZ8Ÿ*
|
|
@ -55,6 +55,7 @@ in {
|
|||
"desktop/bitwarden/client_secret".publicKeys = desktop;
|
||||
"desktop/users/myned.pass".publicKeys = desktop;
|
||||
"desktop/users/root.pass".publicKeys = desktop;
|
||||
"desktop/vm/myndows.pass".publicKeys = desktop;
|
||||
|
||||
### SBC
|
||||
"sbc/borgmatic/borgbase.mypi3".publicKeys = sbc;
|
||||
|
|
Loading…
Reference in a new issue