2019-10-08 17:01:14 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.services.mullvad-vpn;
|
|
|
|
in
|
|
|
|
with lib;
|
|
|
|
{
|
2022-10-27 18:44:35 +00:00
|
|
|
options.services.mullvad-vpn = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2022-10-27 18:44:35 +00:00
|
|
|
This option enables Mullvad VPN daemon.
|
|
|
|
This sets {option}`networking.firewall.checkReversePath` to "loose", which might be undesirable for security.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-11-07 17:40:21 +00:00
|
|
|
enableExcludeWrapper = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2022-11-07 17:40:21 +00:00
|
|
|
This option activates the wrapper that allows the use of mullvad-exclude.
|
|
|
|
Might have minor security impact, so consider disabling if you do not use the feature.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-11-27 00:19:27 +00:00
|
|
|
package = mkPackageOption pkgs "mullvad" {
|
|
|
|
example = "mullvad-vpn";
|
|
|
|
extraDescription = ''
|
|
|
|
`pkgs.mullvad` only provides the CLI tool, `pkgs.mullvad-vpn` provides both the CLI and the GUI.
|
2022-10-27 18:44:35 +00:00
|
|
|
'';
|
|
|
|
};
|
2019-10-08 17:01:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
boot.kernelModules = [ "tun" ];
|
|
|
|
|
2022-11-07 17:40:21 +00:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
2020-11-17 01:23:55 +00:00
|
|
|
# mullvad-daemon writes to /etc/iproute2/rt_tables
|
|
|
|
networking.iproute2.enable = true;
|
|
|
|
|
2021-05-06 11:23:54 +00:00
|
|
|
# See https://github.com/NixOS/nixpkgs/issues/113589
|
|
|
|
networking.firewall.checkReversePath = "loose";
|
|
|
|
|
2022-11-07 17:40:21 +00:00
|
|
|
# See https://github.com/NixOS/nixpkgs/issues/176603
|
|
|
|
security.wrappers.mullvad-exclude = mkIf cfg.enableExcludeWrapper {
|
|
|
|
setuid = true;
|
|
|
|
owner = "root";
|
|
|
|
group = "root";
|
|
|
|
source = "${cfg.package}/bin/mullvad-exclude";
|
|
|
|
};
|
|
|
|
|
2019-10-08 17:01:14 +00:00
|
|
|
systemd.services.mullvad-daemon = {
|
|
|
|
description = "Mullvad VPN daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2023-10-04 05:21:50 +00:00
|
|
|
wants = [ "network.target" "network-online.target" ];
|
2019-10-08 17:01:14 +00:00
|
|
|
after = [
|
|
|
|
"network-online.target"
|
|
|
|
"NetworkManager.service"
|
|
|
|
"systemd-resolved.service"
|
|
|
|
];
|
|
|
|
path = [
|
2021-04-08 11:33:09 +00:00
|
|
|
pkgs.iproute2
|
2019-10-08 17:01:14 +00:00
|
|
|
# Needed for ping
|
|
|
|
"/run/wrappers"
|
2023-11-01 20:47:11 +00:00
|
|
|
# See https://github.com/NixOS/nixpkgs/issues/262681
|
|
|
|
] ++ (lib.optional config.networking.resolvconf.enable
|
|
|
|
config.networking.resolvconf.package);
|
2020-09-09 07:31:27 +00:00
|
|
|
startLimitBurst = 5;
|
|
|
|
startLimitIntervalSec = 20;
|
2019-10-08 17:01:14 +00:00
|
|
|
serviceConfig = {
|
2022-10-27 18:44:35 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/mullvad-daemon -v --disable-stdout-timestamps";
|
2019-10-08 17:01:14 +00:00
|
|
|
Restart = "always";
|
|
|
|
RestartSec = 1;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-10-25 22:42:48 +00:00
|
|
|
meta.maintainers = with maintainers; [ arcuru ymarkus ];
|
2019-10-08 17:01:14 +00:00
|
|
|
}
|