pinwheel: Toggle the work VPN from waybar without sudo

This commit is contained in:
Alexander Heldt committed 2026-11-13 10:14:00 +01:00
1 parent 36655ac153
commit 404138d411
2 files changed
+69 -26

No files matched your search

+30 -2
View File
@@ -91,10 +91,10 @@ EOF
(pkgs.writeShellScriptBin "work-vpn" ''
case $1 in
up)
sudo sh -c "systemctl start openvpn-work-staging.service; systemctl start openvpn-work-production.service"
systemctl start work-vpn.target
;;
down)
sudo sh -c "systemctl stop openvpn-work-staging.service; systemctl stop openvpn-work-production.service"
systemctl stop work-vpn.target
;;
esac
'')
@@ -142,6 +142,34 @@ EOF
};
};
systemd.targets.work-vpn = lib.mkIf openvpnEnabled {
description = "Work VPN";
requires = [
"openvpn-work-staging.service"
"openvpn-work-production.service"
];
after = [
"openvpn-work-staging.service"
"openvpn-work-production.service"
];
};
systemd.services = lib.mkIf openvpnEnabled {
openvpn-work-staging.partOf = [ "work-vpn.target" ];
openvpn-work-production.partOf = [ "work-vpn.target" ];
};
security.polkit.extraConfig = lib.mkIf openvpnEnabled ''
polkit.addRule(function(action, subject) {
if (action.id == "org.freedesktop.systemd1.manage-units" &&
subject.user == "alex" &&
action.lookup("unit") == "work-vpn.target" &&
["start", "stop", "restart"].indexOf(action.lookup("verb")) >= 0) {
return polkit.Result.YES;
}
});
'';
age.secrets = {
"work-gitconfig" = lib.mkIf gitEnabled {
file = ../../../../secrets/pinwheel/work-gitconfig.age;