Wireguard.nix
One of the many free & open-source VPN protocol and when fused with the wonderful declarative Nix configuration one is able to setup their system without hinders!
In this post I will attempt to explain how to setup a declarative
wireguard.nix
module, enjoy!
Note The
<<X>>
provided in the source-blocks links the remaining source blocks with the source-block they are input in. This is useful when writing your Nix configurations in org-mode and later tangling (outputs the code only) the result to aexample.nix
file.
Systemd.service: wg-quick-wg0
.
This is not a necessary step, but to prevent the service from starting during boot while remaining enabled one has to specify the ~wantedBy~ option.
Another reason to why I am using the following setup is to add the ~path~, listed in the ~systemd.services~, to the scope which helps me reduce the amount of references required when enabling the kill-switch later on.
|
|
Note You are not limited to using ~wg0~ as an interface name. You could instead use whatever name you deem fit for your
wg-quick
interface!
Networking: Setup your wg-quick
Interface
Define your wg-quick
interface (make sure to replace wg0
with your
interface name) and obviously fill in the missing info inside the quotes:
|
|
Kill-Switch: Prevent DNS Leakage!
When the connection is probable to leaking your DNS, the connection will completely shutdown and prevent any form of network flow unless the systemd-service has been restarted:
|
|
Congratulations!
You now have a fully functional wg-quick
interface!