1 { config, lib, pkgs, ... }:
3 cfg = config.services.mullvad-vpn;
7 options.services.mullvad-vpn = {
12 This option enables Mullvad VPN daemon.
13 This sets {option}`networking.firewall.checkReversePath` to "loose", which might be undesirable for security.
17 enableExcludeWrapper = mkOption {
21 This option activates the wrapper that allows the use of mullvad-exclude.
22 Might have minor security impact, so consider disabling if you do not use the feature.
26 package = mkPackageOption pkgs "mullvad" {
27 example = "mullvad-vpn";
29 `pkgs.mullvad` only provides the CLI tool, `pkgs.mullvad-vpn` provides both the CLI and the GUI.
34 config = mkIf cfg.enable {
35 boot.kernelModules = [ "tun" ];
37 environment.systemPackages = [ cfg.package ];
39 # mullvad-daemon writes to /etc/iproute2/rt_tables
40 networking.iproute2.enable = true;
42 # See https://github.com/NixOS/nixpkgs/issues/113589
43 networking.firewall.checkReversePath = "loose";
45 # See https://github.com/NixOS/nixpkgs/issues/176603
46 security.wrappers.mullvad-exclude = mkIf cfg.enableExcludeWrapper {
50 source = "${cfg.package}/bin/mullvad-exclude";
53 systemd.services.mullvad-daemon = {
54 description = "Mullvad VPN daemon";
55 wantedBy = [ "multi-user.target" ];
56 wants = [ "network.target" "network-online.target" ];
58 "network-online.target"
59 "NetworkManager.service"
60 "systemd-resolved.service"
66 # See https://github.com/NixOS/nixpkgs/issues/262681
67 ] ++ (lib.optional config.networking.resolvconf.enable
68 config.networking.resolvconf.package);
70 startLimitIntervalSec = 20;
72 ExecStart = "${cfg.package}/bin/mullvad-daemon -v --disable-stdout-timestamps";
79 meta.maintainers = with maintainers; [ arcuru ymarkus ];