mirror of
https://github.com/tomasriveral/nixos.git
synced 2026-10-10 08:55:18 +02:00
custom-vpn-picker: init
This commit is contained in:
1 parent
7cd934c58c
commit
bc67f2b0e8
11 files changed
+144
-19
No files matched your search
@@ -1,4 +1,4 @@
|
||||
{...}: {
|
||||
_: {
|
||||
flake.nixosModules.hyprland = {
|
||||
pkgs,
|
||||
pkgs-unstable,
|
||||
@@ -93,6 +93,7 @@ let
|
||||
(builtins.readFile ../../other/hyprland/hyprland.lua);
|
||||
in
|
||||
{
|
||||
|
||||
#refer to https://wiki.hypr.land/Nix/Hyprland-on-Home-Manager/
|
||||
wayland.windowManager.hyprland.enable = true;
|
||||
wayland.windowManager.hyprland.package = pkgs-unstable.hyprland;
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
_: {
|
||||
flake.nixosModules.mullvad = _: {
|
||||
services.mullvad-vpn = {
|
||||
enable = true;
|
||||
};
|
||||
};
|
||||
flake.homeModules.mullvad = _: {
|
||||
programs.mullvad-vpn = {
|
||||
# gui
|
||||
enable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -38,7 +38,6 @@
|
||||
latex
|
||||
ly
|
||||
mathematics
|
||||
mullvad
|
||||
networking
|
||||
nixUtils
|
||||
notifications
|
||||
@@ -51,6 +50,7 @@
|
||||
rss
|
||||
udev
|
||||
user
|
||||
vpn
|
||||
];
|
||||
};
|
||||
flake.homeModules.desktop = {...}: {
|
||||
@@ -68,7 +68,6 @@
|
||||
hyprland-desktop
|
||||
kitty
|
||||
librewolf
|
||||
mullvad
|
||||
neovim
|
||||
nix-git-cherry-picker-desktop
|
||||
desktop-notewrapper
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
latex
|
||||
ly
|
||||
mathematics
|
||||
mullvad
|
||||
networking
|
||||
nixUtils-laptop
|
||||
nixUtils
|
||||
@@ -52,6 +51,7 @@
|
||||
rss
|
||||
udev
|
||||
user
|
||||
vpn
|
||||
];
|
||||
};
|
||||
flake.homeModules.laptop = {...}: {
|
||||
@@ -70,7 +70,6 @@
|
||||
hyprland-laptop
|
||||
kitty
|
||||
librewolf
|
||||
mullvad
|
||||
neovim
|
||||
nix-git-cherry-picker-laptop
|
||||
laptop-notewrapper
|
||||
|
||||
@@ -44,6 +44,18 @@ _: {
|
||||
command = "${pkgs-unstable.nixos-rebuild}/bin/nixos-rebuild";
|
||||
options = ["NOPASSWD"];
|
||||
}
|
||||
{
|
||||
command = "/run/current-system/sw/bin/open";
|
||||
options = ["NOPASSWD"];
|
||||
}
|
||||
{
|
||||
command = "${pkgs.openconnect}/bin/openconnect";
|
||||
options = ["NOPASSWD"];
|
||||
}
|
||||
{
|
||||
command = "${pkgs-unstable.openconnect}/bin/openconnect";
|
||||
options = ["NOPASSWD"];
|
||||
}
|
||||
];
|
||||
}
|
||||
];
|
||||
|
||||
@@ -13,5 +13,11 @@
|
||||
group = "users";
|
||||
mode = "0400";
|
||||
};
|
||||
age.secrets.epfl = {
|
||||
file = ../../secrets/epfl.age;
|
||||
owner = "tomasr";
|
||||
group = "users";
|
||||
mode = "0400";
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
# config for openconnect is in ./epfl.nix
|
||||
{self, ...}: {
|
||||
flake.nixosModules.vpn = {pkgs,...}: {
|
||||
services.mullvad-vpn = {
|
||||
enable = true;
|
||||
};
|
||||
environment.systemPackages = [
|
||||
self.packages.${pkgs.system}.custom-vpn-picker
|
||||
];
|
||||
age.secrets.epfl = {
|
||||
file = ../../secrets/epfl.age;
|
||||
};
|
||||
|
||||
};
|
||||
perSystem = {pkgs, ...}: {
|
||||
packages.custom-vpn-picker = pkgs.writeShellApplication {
|
||||
name = "custom-vpn-picker";
|
||||
|
||||
runtimeInputs = with pkgs; [
|
||||
fzf
|
||||
mullvad-compass
|
||||
mullvad
|
||||
openconnect
|
||||
gawk
|
||||
wl-clipboard
|
||||
cliphist
|
||||
];
|
||||
|
||||
text = ''
|
||||
mullvad_connect () {
|
||||
mullvad disconnect
|
||||
mullvad relay set location "$1"
|
||||
mullvad connect
|
||||
}
|
||||
|
||||
profiles=(
|
||||
"mullvad-best"
|
||||
"mullvad-zurich"
|
||||
"mullvad-tirana"
|
||||
"mullvad-bogota"
|
||||
"epfl"
|
||||
"disconnect"
|
||||
)
|
||||
|
||||
selected=$(printf "%s\n" "''${profiles[@]}" |
|
||||
fzf --height 8 --reverse --prompt="Select vpn:")
|
||||
|
||||
[[ -z "$selected" ]] && exit 0
|
||||
|
||||
if [[ "$selected" == "mullvad-best" ]]; then
|
||||
mullvad_connect "$(
|
||||
mullvad-compass |
|
||||
awk '/Best server:/ {
|
||||
getline
|
||||
split($1, a, "-")
|
||||
print a[1]
|
||||
}'
|
||||
)"
|
||||
|
||||
elif [[ "$selected" == "mullvad-zurich" ]]; then
|
||||
mullvad_connect ch
|
||||
|
||||
elif [[ "$selected" == "mullvad-tirana" ]]; then
|
||||
mullvad_connect al
|
||||
|
||||
elif [[ "$selected" == "mullvad-bogota" ]]; then
|
||||
mullvad_connect co
|
||||
|
||||
elif [[ "$selected" == "epfl" ]]; then
|
||||
# shellcheck disable=SC1091
|
||||
source /run/agenix/epfl
|
||||
|
||||
# Put password in clipboard so it can be pasted into openconnect.
|
||||
printf '%s' "$EPFL_VPN_PASSWORD" | wl-copy
|
||||
|
||||
sudo openconnect \
|
||||
--background \
|
||||
--pid-file="$HOME/.local/state/epfl-openconnect.pid" \
|
||||
--server="$EPFL_VPN_SERVER" \
|
||||
--user="$EPFL_VPN_USER"
|
||||
|
||||
# Remove the password from cliphist and clear the current clipboard.
|
||||
cliphist delete-query "$EPFL_VPN_PASSWORD" || true
|
||||
wl-copy --clear
|
||||
|
||||
elif [[ "$selected" == "disconnect" ]]; then
|
||||
if [[ -f "$HOME/.local/state/epfl-openconnect.pid" ]]; then
|
||||
sudo kill "$(cat "$HOME/.local/state/epfl-openconnect.pid")" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
mullvad disconnect
|
||||
rm "$HOME/.local/state/epfl-openconnect.pid"
|
||||
fi
|
||||
|
||||
pkill -f "kitty.*Select vpn option" || true
|
||||
exit
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user