-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
nordvpn: init at 4.3.1 #406725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
different-error
wants to merge
3
commits into
NixOS:master
Choose a base branch
from
different-error:nordvpn
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
nordvpn: init at 4.3.1 #406725
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # NordVPN {#module-services-nordvpn} | ||
|
|
||
| *Source:* {file}`modules/services/networking/nordvpn.nix` | ||
|
|
||
| *Upstream documentation:* <https://github.com/NordSecurity/nordvpn-linux> | ||
|
|
||
| NordVPN offers a paid virtual private network (VPN) service. | ||
| The service operates as closed-source, | ||
| but the Linux client uses open-source code licensed under GPLv3. | ||
| A minimal configuration in NixOS appears as follows: | ||
|
|
||
| ```nix | ||
| { | ||
| services.nordvpn.enable = true; | ||
| networking.firewall.enable = true; | ||
| networking.firewall.checkReversePath = "loose"; | ||
| } | ||
| ``` | ||
|
|
||
| When using a firewall, set `networking.firewall.checkReversePath` to `"loose"` or `false`. | ||
| NordVPN includes a `kill-switch` feature that blocks all packets not associated with the VPN connection. | ||
|
|
||
| Additionally, add your user to the `nordvpn` group. | ||
|
|
||
| ```nix | ||
| { | ||
| users.users.yourUser = { | ||
| #.. | ||
| extraGroups = [ | ||
| #.. | ||
| "nordvpn" | ||
| ]; | ||
| }; | ||
| } | ||
| ``` | ||
|
|
||
| If you prefer to use your own user and group, you can do so using | ||
|
|
||
| ```nix | ||
| { | ||
| services.nordvpn.user = "SOME-USER"; | ||
| services.nordvpn.group = "SOME-GROUP"; | ||
| } | ||
| ``` | ||
|
|
||
| NordVPN provides several useful CLI commands, including: | ||
|
|
||
| ```bash | ||
| nordvpn login # Log in using an OAuth URL | ||
| nordvpn login --token <token> # Log in with a token obtained from your NordVPN account | ||
| nordvpn c # Connect to the VPN | ||
| nordvpn c ie # Connect to a NordVPN server in Ireland | ||
| nordvpn d # Disconnect from the VPN | ||
| nordvpn set technology openvpn # Switch to OpenVPN technology | ||
| nordvpn c # Reconnect after changing technology | ||
| ``` | ||
|
|
||
| Additionally, if you prefer to use the friendly GUI, | ||
|
|
||
| ```bash | ||
| nordvpn-gui | ||
| ``` | ||
|
|
||
| **Disclaimer:** NixOS currently does not support meshnet. | ||
| Contributions welcome! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| { | ||
| config, | ||
| lib, | ||
| pkgs, | ||
| ... | ||
| }: | ||
| let | ||
| cfg = config.services.nordvpn; | ||
| defaultUser = "nordvpn"; | ||
| defaultGroup = "nordvpn"; | ||
|
|
||
| nordvpn = | ||
| let | ||
| cli = cfg.package.cli.overrideAttrs (old: { | ||
| preBuild = | ||
| let | ||
| extraPreBuild = lib.optionalString (cfg.group != defaultGroup) '' | ||
| substituteInPlace internal/permissions.go \ | ||
| --replace-fail \ | ||
| 'string{"nordvpn"}' \ | ||
| 'string{"${cfg.group}"}' | ||
|
|
||
| substituteInPlace internal/constants.go \ | ||
| --replace-fail \ | ||
| 'NordvpnGroup = "nordvpn"' \ | ||
| 'NordvpnGroup = "${cfg.group}"' | ||
| ''; | ||
| in | ||
| extraPreBuild + (old.preBuild or ""); | ||
|
|
||
| # postFixup wraps nordvpnd so that it can find binaries that it calls. | ||
| # here, instead, use systemd to update the path to those binaries. | ||
| postFixup = ""; | ||
| }); | ||
| in | ||
| pkgs.symlinkJoin { | ||
| inherit (cfg.package) pname version meta; | ||
| paths = [ | ||
| cli | ||
| cfg.package.gui | ||
| ]; | ||
| }; | ||
| in | ||
| { | ||
| options.services.nordvpn = { | ||
| enable = lib.mkEnableOption "Enable NordVPN"; | ||
| package = lib.mkPackageOption pkgs "nordvpn" { }; | ||
| user = lib.mkOption { | ||
| type = lib.types.str; | ||
| default = defaultUser; | ||
| description = '' | ||
| The User that owns the `nordvpnd` systemd process. | ||
| If overriding the default, a user with the same name must exist. | ||
| ''; | ||
| }; | ||
| group = lib.mkOption { | ||
| type = lib.types.str; | ||
| default = defaultGroup; | ||
| description = '' | ||
| The Group that owns the `nordvpnd` systemd process. | ||
| If overriding the default, a group with the same name must exist. | ||
| ''; | ||
| }; | ||
| }; | ||
|
|
||
| config = lib.mkIf cfg.enable { | ||
|
|
||
| # create the default user if that's the one used | ||
| users.users = lib.mkIf (cfg.user == defaultUser) { | ||
| ${defaultUser} = { | ||
| description = "User that runs `nordvpnd`."; | ||
| group = cfg.group; | ||
| isSystemUser = true; | ||
| }; | ||
| }; | ||
|
|
||
| # create the default group if that's the one used | ||
| users.groups = lib.mkIf (cfg.group == defaultGroup) { | ||
| ${defaultGroup} = { }; | ||
| }; | ||
|
|
||
| # nordvpnd uses resolved to configure dns | ||
| services.resolved.enable = true; | ||
|
|
||
| # policy that allows nordvpnd to configure dns | ||
| security.polkit = { | ||
| enable = true; | ||
| extraConfig = '' | ||
| polkit.addRule(function(action, subject) { | ||
| if (action.id == "org.freedesktop.resolve1.set-dns-servers" | ||
| && subject.isInGroup("${cfg.group}")) { | ||
| return polkit.Result.YES; | ||
| } | ||
| }); | ||
| ''; | ||
| }; | ||
|
|
||
| environment.systemPackages = [ | ||
| nordvpn | ||
| ]; | ||
|
|
||
| systemd.services.nordvpnd = { | ||
| after = [ "network-online.target" ]; | ||
| description = "NordVPN daemon."; | ||
| path = ( | ||
| with pkgs; | ||
| [ | ||
| e2fsprogs | ||
| iproute2 | ||
| iptables | ||
| libxslt | ||
| procps | ||
| wireguard-tools | ||
| ] | ||
| ++ [ nordvpn ] | ||
| ); | ||
| serviceConfig = { | ||
| # nordvpnd needs CAP_NET_ADMIN to configure network interfaces | ||
| AmbientCapabilities = "CAP_NET_ADMIN"; | ||
| CapabilityBoundingSet = "CAP_NET_ADMIN"; | ||
| ExecStart = lib.getExe' nordvpn "nordvpnd"; | ||
| Group = cfg.group; | ||
| KillMode = "process"; | ||
| NonBlocking = true; | ||
| Requires = "nordvpnd.socket"; | ||
| Restart = "on-failure"; | ||
| RestartSec = 5; | ||
| RuntimeDirectory = "nordvpn"; | ||
| RuntimeDirectoryMode = "0750"; | ||
| StateDirectory = "nordvpn"; | ||
| StateDirectoryMode = "0750"; | ||
| User = cfg.user; | ||
| }; | ||
| wantedBy = [ "default.target" ]; | ||
| wants = [ "network-online.target" ]; | ||
| }; | ||
|
|
||
| systemd.sockets.nordvpnd = { | ||
| description = "NordVPN Daemon Socket"; | ||
| listenStreams = [ "/run/nordvpn/nordvpnd.sock" ]; | ||
| partOf = [ "nordvpnd.service" ]; | ||
| socketConfig = { | ||
| DirectoryMode = "0750"; | ||
| NoDelay = true; | ||
| SocketGroup = cfg.group; | ||
| SocketMode = "0770"; | ||
| SocketUser = cfg.user; | ||
| }; | ||
| wantedBy = [ "sockets.target" ]; | ||
| }; | ||
|
|
||
| systemd.user.services.norduserd = { | ||
| after = [ "network-online.target" ]; | ||
| description = "NordUserD Service"; | ||
| serviceConfig = { | ||
| ExecStart = lib.getExe' nordvpn "norduserd"; | ||
| NonBlocking = true; | ||
| Restart = "on-failure"; | ||
| RestartSec = 5; | ||
| }; | ||
| wantedBy = [ "graphical-session.target" ]; | ||
| wants = [ "network-online.target" ]; | ||
| }; | ||
|
|
||
| }; | ||
|
|
||
| meta = { | ||
| doc = ./nordvpn.md; | ||
| maintainers = with lib.maintainers; [ different-error ]; | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.