2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.services.mullvad-vpn;
|
|
|
|
in
|
|
|
|
with lib;
|
|
|
|
{
|
2022-10-30 15:09:59 +00:00
|
|
|
options.services.mullvad-vpn = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
This option enables Mullvad VPN daemon.
|
|
|
|
This sets {option}`networking.firewall.checkReversePath` to "loose", which might be undesirable for security.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.mullvad;
|
|
|
|
defaultText = literalExpression "pkgs.mullvad";
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
The Mullvad package to use. `pkgs.mullvad` only provides the CLI tool, `pkgs.mullvad-vpn` provides both the CLI and the GUI.
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
boot.kernelModules = [ "tun" ];
|
|
|
|
|
2020-11-24 20:58:05 +00:00
|
|
|
# mullvad-daemon writes to /etc/iproute2/rt_tables
|
|
|
|
networking.iproute2.enable = true;
|
|
|
|
|
2021-08-08 23:34:03 +00:00
|
|
|
# See https://github.com/NixOS/nixpkgs/issues/113589
|
|
|
|
networking.firewall.checkReversePath = "loose";
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.services.mullvad-daemon = {
|
|
|
|
description = "Mullvad VPN daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
wants = [ "network.target" ];
|
|
|
|
after = [
|
|
|
|
"network-online.target"
|
|
|
|
"NetworkManager.service"
|
|
|
|
"systemd-resolved.service"
|
|
|
|
];
|
|
|
|
path = [
|
2021-04-08 16:26:57 +00:00
|
|
|
pkgs.iproute2
|
2020-04-24 23:36:52 +00:00
|
|
|
# Needed for ping
|
|
|
|
"/run/wrappers"
|
|
|
|
];
|
2020-11-03 02:18:15 +00:00
|
|
|
startLimitBurst = 5;
|
|
|
|
startLimitIntervalSec = 20;
|
2020-04-24 23:36:52 +00:00
|
|
|
serviceConfig = {
|
2022-10-30 15:09:59 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/mullvad-daemon -v --disable-stdout-timestamps";
|
2020-04-24 23:36:52 +00:00
|
|
|
Restart = "always";
|
|
|
|
RestartSec = 1;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-10-30 15:09:59 +00:00
|
|
|
meta.maintainers = with maintainers; [ patricksjackson ymarkus ];
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|