pinwheel: Use the Cloudflare One client for the work VPN

This commit is contained in:
Alexander Heldt committed 2026-11-26 09:00:36 +01:00
1 parent 9d837f7fbd
commit 1bcca33a73
9 files changed
+63 -91

No files matched your search

+27 -49
View File
@@ -8,7 +8,7 @@
let
gitEnabled = config.mod.git.enable;
goEnabled = config.mod.go.enable;
openvpnEnabled = config.mod.openvpn.enable;
vpnEnabled = config.mod.vpn.enable;
in
{
home-manager.users.alex = {
@@ -90,12 +90,32 @@ EOF
pkgs.golangci-lint
(pkgs.writeShellScriptBin "work-vpn" ''
registered() {
! warp-cli --accept-tos status | ${pkgs.gnugrep}/bin/grep -q "Registration Missing"
}
connected() {
warp-cli --accept-tos status | ${pkgs.gnugrep}/bin/grep -q "Status update: Connected"
}
wait-for() {
for _ in $(${pkgs.coreutils}/bin/seq $1); do
$2 && return 0
${pkgs.coreutils}/bin/sleep 1
done
return 1
}
case $1 in
up)
systemctl start work-vpn.target
if ! registered; then
warp-cli --accept-tos registration new
wait-for 300 registered
fi
warp-cli --accept-tos connect && wait-for 30 connected
;;
down)
systemctl stop work-vpn.target
warp-cli --accept-tos disconnect
;;
esac
'')
@@ -145,46 +165,6 @@ EOF
pkgs.zlib
];
services.openvpn.servers = lib.mkIf openvpnEnabled {
work-staging = {
config = "config ${config.age.secrets.work-staging-ovpn.path}";
autoStart = false;
};
work-production = {
config = "config ${config.age.secrets.work-production-ovpn.path}";
autoStart = false;
};
};
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;
@@ -210,12 +190,10 @@ EOF
group = "users";
};
"work-staging-ovpn" = lib.mkIf openvpnEnabled {
file = ../../../../secrets/pinwheel/work-staging-ovpn.age;
};
"work-production-ovpn" = lib.mkIf openvpnEnabled {
file = ../../../../secrets/pinwheel/work-production-ovpn.age;
"work-cloudflare-mdm" = lib.mkIf vpnEnabled {
file = ../../../../secrets/pinwheel/work-cloudflare-mdm.age;
path = "/var/lib/cloudflare-warp/mdm.xml";
symlink = false;
};
};
}