diff --git a/hosts/pinwheel/modules/default.nix b/hosts/pinwheel/modules/default.nix index 01106f5..57c6159 100644 --- a/hosts/pinwheel/modules/default.nix +++ b/hosts/pinwheel/modules/default.nix @@ -27,7 +27,7 @@ in zsh.enable = true; atuin.enable = true; - openvpn.enable = true; + vpn.enable = true; c.enable = true; go.enable = true; diff --git a/hosts/pinwheel/modules/openvpn/default.nix b/hosts/pinwheel/modules/openvpn/default.nix deleted file mode 100644 index 8288f27..0000000 --- a/hosts/pinwheel/modules/openvpn/default.nix +++ /dev/null @@ -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; - }; - }; - - }; - }; -} diff --git a/hosts/pinwheel/modules/vpn/default.nix b/hosts/pinwheel/modules/vpn/default.nix new file mode 100644 index 0000000..77dd986 --- /dev/null +++ b/hosts/pinwheel/modules/vpn/default.nix @@ -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 '~.' + ''; + }; + }; +} diff --git a/hosts/pinwheel/modules/waybar/default.nix b/hosts/pinwheel/modules/waybar/default.nix index d8550d1..f55b11c 100644 --- a/hosts/pinwheel/modules/waybar/default.nix +++ b/hosts/pinwheel/modules/waybar/default.nix @@ -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 } diff --git a/hosts/pinwheel/modules/work/default.nix b/hosts/pinwheel/modules/work/default.nix index 40fef2d..a17b525 100644 --- a/hosts/pinwheel/modules/work/default.nix +++ b/hosts/pinwheel/modules/work/default.nix @@ -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; }; }; } diff --git a/secrets/pinwheel/work-cloudflare-mdm.age b/secrets/pinwheel/work-cloudflare-mdm.age new file mode 100644 index 0000000..ba77897 Binary files /dev/null and b/secrets/pinwheel/work-cloudflare-mdm.age differ diff --git a/secrets/pinwheel/work-production-ovpn.age b/secrets/pinwheel/work-production-ovpn.age deleted file mode 100644 index 78dd17f..0000000 Binary files a/secrets/pinwheel/work-production-ovpn.age and /dev/null differ diff --git a/secrets/pinwheel/work-staging-ovpn.age b/secrets/pinwheel/work-staging-ovpn.age deleted file mode 100644 index 462c9cf..0000000 Binary files a/secrets/pinwheel/work-staging-ovpn.age and /dev/null differ diff --git a/secrets/secrets.nix b/secrets/secrets.nix index 2945c04..420bf18 100644 --- a/secrets/secrets.nix +++ b/secrets/secrets.nix @@ -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 ];