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

+1 -1
View File
@@ -27,7 +27,7 @@ in
zsh.enable = true;
atuin.enable = true;
openvpn.enable = true;
vpn.enable = true;
c.enable = true;
go.enable = true;
@@ -1,36 +0,0 @@
{
pkgs,
lib,
config,
...
}:
let
enabled = config.mod.openvpn.enable;
in
{
options = {
mod.openvpn = {
enable = lib.mkEnableOption "enable openpn module";
};
};
config = lib.mkIf enabled {
home-manager.users.alex = {
home.packages = [
pkgs.openvpn
];
};
services.resolved = {
enable = true;
settings = {
Resolve = {
Domains = [ "~." ];
DNSSEC = false;
DNSOverTLS = true;
};
};
};
};
}
+31
View File
@@ -0,0 +1,31 @@
{
lib,
config,
...
}:
let
enabled = config.mod.vpn.enable;
in
{
options = {
mod.vpn = {
enable = lib.mkEnableOption "enable vpn module";
};
};
config = lib.mkIf enabled {
services.cloudflare-warp.enable = true;
services.resolved.enable = true;
systemd.services.cloudflare-warp-dns = {
bindsTo = [ "sys-subsystem-net-devices-CloudflareWARP.device" ];
after = [ "sys-subsystem-net-devices-CloudflareWARP.device" ];
wantedBy = [ "sys-subsystem-net-devices-CloudflareWARP.device" ];
serviceConfig.Type = "oneshot";
script = ''
resolvectl dns CloudflareWARP 127.0.2.2 127.0.2.3
resolvectl domain CloudflareWARP '~.'
'';
};
};
}
+3 -3
View File
@@ -94,7 +94,7 @@ let
work-vpn = pkgs.writeShellScript "work-vpn" ''
connected() {
systemctl is-active --quiet openvpn-work-staging.service openvpn-work-production.service
warp-cli --accept-tos status | ${pkgs.gnugrep}/bin/grep -q "Status update: Connected"
}
output() {
@@ -107,9 +107,9 @@ let
toggle() {
if connected; then
systemctl stop work-vpn.target && ${pkgs.libnotify}/bin/notify-send "Disconnected from work VPN"
work-vpn down && ${pkgs.libnotify}/bin/notify-send "Disconnected from work VPN"
else
systemctl start work-vpn.target && ${pkgs.libnotify}/bin/notify-send "Connected to work VPN"
work-vpn up && ${pkgs.libnotify}/bin/notify-send "Connected to work VPN"
fi
}
+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;
};
};
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -2
View File
@@ -24,9 +24,8 @@ in {
"pinwheel/work-gitconfig.age".publicKeys = [ pinwheel alex ];
"pinwheel/work-github-token.age".publicKeys = [ pinwheel alex ];
"pinwheel/work-rv-teams.age".publicKeys = [ pinwheel alex ];
"pinwheel/work-cloudflare-mdm.age".publicKeys = [ pinwheel alex ];
"pinwheel/work-go-private.age".publicKeys = [ pinwheel alex ];
"pinwheel/work-staging-ovpn.age".publicKeys = [ pinwheel alex ];
"pinwheel/work-production-ovpn.age".publicKeys = [ pinwheel alex ];
"pinwheel/naviterm-config.age".publicKeys = [ pinwheel alex ];
"pinwheel/navidrome-password.age".publicKeys = [ pinwheel alex ];
"pinwheel/ndp-llm-api-key.age".publicKeys = [ pinwheel alex ];