Compare commits
2 Commits
41da6fe13f
...
293312b447
Author | SHA1 | Date |
---|---|---|
Simon Bruder | 293312b447 | |
Simon Bruder | ecdbe9b936 |
|
@ -5,7 +5,7 @@ let
|
|||
cfg = config.sbruder.mullvad;
|
||||
|
||||
relayConfigs = lib.mapAttrs'
|
||||
(name: configuration: lib.nameValuePair "mullvad-${name}.conf" (with configuration; ''
|
||||
(name: configuration: lib.nameValuePair "mlv-${name}.conf" (with configuration; ''
|
||||
[Interface]
|
||||
DNS = ${cfg.dnsServer}
|
||||
|
||||
|
@ -53,20 +53,10 @@ in
|
|||
(name: lib.nameValuePair "wireguard/${name}" { source = "${relayConfigFiles}/${name}"; })
|
||||
(lib.attrNames relayConfigs));
|
||||
|
||||
systemPackages = lib.singleton (pkgs.stdenv.mkDerivation {
|
||||
name = "mullvad-on-demand";
|
||||
|
||||
src = ./mullvad.sh;
|
||||
|
||||
dontUnpack = true;
|
||||
dontBuild = true;
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
install -D $src $out/bin/mullvad
|
||||
runHook postInstall
|
||||
'';
|
||||
});
|
||||
systemPackages = lib.singleton (pkgs.runCommandNoCC "mullvad-on-demand" { } ''
|
||||
install -D ${./mullvad.sh} $out/bin/mullvad
|
||||
install -D ${./mullvad-fzf.sh} $out/bin/mullvad-fzf
|
||||
'');
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
#!/usr/bin/env bash
|
||||
mullvad $(find /etc/wireguard -name "mlv-*.conf" -printf "%f\n" | sed 's/mlv-\(.*\)\.conf/\1/' | fzf)
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
# This reads wg-quick compatible configuration files from
|
||||
# /etc/wireguard/mullvad-LOCATION.conf
|
||||
# /etc/wireguard/mlv-LOCATION.conf
|
||||
#
|
||||
# Since they are autogenerated by nix and therefore world-readable, they do not
|
||||
# include secrets like the private key and client address. Instead, they are
|
||||
|
@ -18,7 +18,7 @@ if (( $# < 1 )); then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
INTERFACE="mullvad-$1"
|
||||
INTERFACE="mlv-$1"
|
||||
|
||||
cmd() {
|
||||
echo "[#] $*" >&2
|
||||
|
@ -27,7 +27,7 @@ cmd() {
|
|||
|
||||
for interface in /sys/class/net/*; do
|
||||
interface="${interface#/sys/class/net/}"
|
||||
[[ $interface =~ ^mullvad-(v6-)?[a-z]{2}[0-9]*$ ]] && cmd wg-quick down "$interface"
|
||||
[[ $interface =~ ^mlv-(v6-)?[a-z]{2}(-[a-z]{3}-)?[0-9]*$ ]] && cmd wg-quick down "$interface"
|
||||
done
|
||||
|
||||
if [ "$1" != "off" ]; then
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,7 +3,7 @@
|
|||
# it into a format that takes up less space than the original response.
|
||||
set -euo pipefail
|
||||
curl -s 'https://api.mullvad.net/www/relays/wireguard/' | jq '. | map({
|
||||
key: .hostname | split("-")[0],
|
||||
key: (if .hostname | endswith("-wireguard") then .hostname | split("-")[0] else .hostname | sub("-wg-"; "-") end),
|
||||
value: {
|
||||
endpoint4: .ipv4_addr_in,
|
||||
endpoint6: .ipv6_addr_in,
|
||||
|
|
|
@ -183,7 +183,7 @@ in
|
|||
exec = pkgs.writeShellScript "vpn-state" ''
|
||||
${pkgs.iproute}/bin/ip -j link \
|
||||
| ${pkgs.jq}/bin/jq --unbuffered --compact-output '
|
||||
[[.[].ifname | select(. | startswith("mullvad"))][] | split("-")[1] + " ${thinsp}"] as $conns
|
||||
[[.[].ifname | select(. | startswith("mlv"))][] | sub("mlv-"; "") + " ${thinsp}"] as $conns
|
||||
| { text: ($conns[0] // ""), class: (if $conns | length > 0 then "connected" else "disconnected" end) }'
|
||||
'';
|
||||
return-type = "json";
|
||||
|
|
Loading…
Reference in New Issue