From c001f7763cb504886e16bf50875134c8518c41cb Mon Sep 17 00:00:00 2001 From: Dom Honey Date: Sun, 4 Jan 2026 20:29:04 +0000 Subject: [PATCH] nixos/mullvad-vpn: add boot blocking service as per upstream In their debs and rpms, Mullvad distributes a oneshot systemd service called mullvad-early-boot-blocking.service so it can enforce firewall rules in the event a user configures lockdown mode and wants traffic always routed through Mullvad. The mullvad NixOS service should offer the same functionality. A new option is included should users want to enable it. --- .../services/networking/mullvad-vpn.nix | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/networking/mullvad-vpn.nix b/nixos/modules/services/networking/mullvad-vpn.nix index b6c1a618407d..8ccec7997f82 100644 --- a/nixos/modules/services/networking/mullvad-vpn.nix +++ b/nixos/modules/services/networking/mullvad-vpn.nix @@ -27,6 +27,17 @@ with lib; ''; }; + enableEarlyBootBlocking = mkOption { + type = types.bool; + default = false; + description = '' + This option activates an additional oneshot systemd service to ensure that the mullvad daemon + will start and block traffic before any network configuration will be applied. + This matches what upstream Mullvad distributes for their supported distros, but is disabled by + default in NixOS as it may conflict with non-Mullvad network configuration. + ''; + }; + package = mkPackageOption pkgs "mullvad" { example = "mullvad-vpn"; extraDescription = '' @@ -48,6 +59,23 @@ with lib; source = "${cfg.package}/bin/mullvad-exclude"; }; + # see https://github.com/mullvad/mullvadvpn-app/blob/2025.14/dist-assets/linux/mullvad-early-boot-blocking.service + systemd.services.mullvad-early-boot-blocking = mkIf cfg.enableEarlyBootBlocking { + description = "Mullvad early boot network blocker"; + wantedBy = [ "mullvad-daemon.service" ]; + before = [ + "basic.target" + "mullvad-daemon.service" + ]; + unitConfig = { + DefaultDependencies = "no"; + }; + serviceConfig = { + Type = "oneshot"; + ExecStart = "${cfg.package}/bin/mullvad-daemon --initialize-early-boot-firewall"; + }; + }; + systemd.services.mullvad-daemon = { description = "Mullvad VPN daemon"; wantedBy = [ "multi-user.target" ]; @@ -59,7 +87,8 @@ with lib; "network-online.target" "NetworkManager.service" "systemd-resolved.service" - ]; + ] + ++ lib.optional cfg.enableEarlyBootBlocking "mullvad-early-boot-blocking.service"; # See https://github.com/NixOS/nixpkgs/issues/262681 path = lib.optional config.networking.resolvconf.enable config.networking.resolvconf.package; startLimitBurst = 5;