From 80942f7eb331b6b975be7a2d3e9bec8acdc941f3 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Mon, 22 Feb 2021 18:59:37 +0100 Subject: [PATCH] wireguard: setup VPN --- .gitattributes | 1 + base/default.nix | 1 + base/networking.nix | 12 ++++ hosts/poseidon/default.nix | 18 ++++++ secrets/default.nix | 4 +- secrets/wireguard.nix | Bin 0 -> 377 bytes services/default.nix | 1 + services/wireguard.nix | 122 +++++++++++++++++++++++++++++++++++++ 8 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 base/networking.nix create mode 100644 secrets/wireguard.nix create mode 100644 services/wireguard.nix diff --git a/.gitattributes b/.gitattributes index ca9c5d8..0fe79d9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ secrets/*.secret filter=git-crypt diff=git-crypt +secrets/wireguard.nix filter=git-crypt diff=git-crypt diff --git a/base/default.nix b/base/default.nix index 35ec4f2..03d0b3d 100644 --- a/base/default.nix +++ b/base/default.nix @@ -1,6 +1,7 @@ { ... }: { imports = [ + ./networking.nix ./nix.nix ./users.nix ]; diff --git a/base/networking.nix b/base/networking.nix new file mode 100644 index 0000000..c17ed76 --- /dev/null +++ b/base/networking.nix @@ -0,0 +1,12 @@ +{ lib, ... }: +{ + options.my.networking.externalInterface = with lib; mkOption { + type = types.nullOr types.str; + default = null; + example = "eth0"; + description = '' + Name of the network interface that egresses to the internet. Used for + e.g. NATing internal networks. + ''; + }; +} diff --git a/hosts/poseidon/default.nix b/hosts/poseidon/default.nix index d5ec7c7..1ff88f2 100644 --- a/hosts/poseidon/default.nix +++ b/hosts/poseidon/default.nix @@ -41,6 +41,7 @@ in "62.210.16.6" "62.210.16.7" ]; + my.networking.externalInterface = "eno1"; # List packages installed in system profile. To search, run: # $ nix search wget @@ -119,6 +120,23 @@ in username = "alarsyo"; password = secrets.transmission-password; }; + + wireguard = { + enable = true; + iface = "wg"; + port = 51820; + + net = { + v4 = { + subnet = "10.0.0"; + mask = 24; + }; + v6 = { + subnet = "fd42:42:42"; + mask = 64; + }; + }; + }; }; security.acme.acceptTerms = true; diff --git a/secrets/default.nix b/secrets/default.nix index 19bd7d6..7d0e393 100644 --- a/secrets/default.nix +++ b/secrets/default.nix @@ -1,4 +1,4 @@ -{ lib, config, ... }: +{ pkgs, lib, config, ... }: with lib; { options.my.secrets = mkOption { @@ -12,5 +12,7 @@ with lib; miniflux-admin-credentials = lib.fileContents ./miniflux-admin-credentials.secret; borg-backup-repo = lib.fileContents ./borg-backup-repo.secret; transmission-password = lib.fileContents ./transmission.secret; + + wireguard = pkgs.callPackage ./wireguard.nix { }; }; } diff --git a/secrets/wireguard.nix b/secrets/wireguard.nix new file mode 100644 index 0000000000000000000000000000000000000000..e2bed7964ad51f1b653c57785e7468455aad3a78 GIT binary patch literal 377 zcmV-<0fznnM@dveQdv+`0DK+d{uV>~6PsL=#VK5MFIh(1dHLCe2d1yC26kegnTWlg zv<5$JMVzoo?Kxi0?hMzbm77M1HO%PhJm`5(dEtqDJLf+6MtA<4GjVJmkS?~46FW@LcL5j{^bq2T_{ZW=F%Ee)pW3F2d Xb7I>sKW@Bv4iF7IV)