nixos-conf/machine-confs/wg-rpi.nix

135 lines
3.7 KiB
Nix
Raw Normal View History

2024-07-20 17:35:00 +03:00
{ config, pkgs, ... }:
2024-05-23 13:39:48 +03:00
let
2024-06-02 05:53:39 +03:00
SSID = "ENTER_SSID";
SSIDpassword = "ENTER_PASSWORD";
interface = "wlan0";
wg_interface = "end0";
hostname = "netflix-huijaus";
ddPassFile = "/root/wg-conf/ddPassFile";
2024-06-02 16:18:19 +03:00
in
{
imports = [ ../base.nix ];
2024-05-23 13:39:48 +03:00
2024-06-02 16:18:19 +03:00
environment.systemPackages = with pkgs; [
wireguard-tools
qrencode
];
2024-05-23 13:39:48 +03:00
# enable NAT
networking.nat.enable = true;
networking.nat.externalInterface = wg_interface;
networking.nat.internalInterfaces = [ "wg0" ];
networking.firewall = {
allowedUDPPorts = [ 51821 ];
};
networking.wireguard.interfaces = {
# "wg0" is the network interface name. You can name the interface arbitrarily.
wg0 = {
# Determines the IP address and subnet of the server's end of the tunnel interface.
ips = [ "10.100.0.1/24" ];
# The port that WireGuard listens to. Must be accessible by the client.
listenPort = 51821;
# This allows the wireguard server to route your traffic to the internet and hence be like a VPN
# For this to work you have to set the dnsserver IP of your router (or dnsserver of choice) in your clients
postSetup = ''
2024-06-02 16:18:19 +03:00
${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING -s 10.100.0.0/24 -o ${wg_interface} -j MASQUERADE
2024-05-23 13:39:48 +03:00
'';
2024-06-02 05:53:39 +03:00
# This undoes the above command
postShutdown = ''
2024-06-02 16:18:19 +03:00
${pkgs.iptables}/bin/iptables -t nat -D POSTROUTING -s 10.100.0.0/24 -o ${wg_interface} -j MASQUERADE
2024-05-23 13:39:48 +03:00
'';
2024-06-02 05:53:39 +03:00
2024-05-23 13:39:48 +03:00
# Path to the private key file.
#
# Note: The private key can also be included inline via the privateKey option,
# but this makes the private key world-readable; thus, using privateKeyFile is
# recommended.
privateKeyFile = "/root/wg-conf/private";
peers = [
2024-06-02 16:18:19 +03:00
{
# Vili Android
2024-05-23 13:39:48 +03:00
publicKey = "niKpC3+Pi4HrYITlzROzqRcxzfzRw1rjpxeJVOr/WAw=";
allowedIPs = [ "10.100.0.2/32" ];
}
2024-06-02 16:18:19 +03:00
{
# Miika Puhelin
2024-05-23 13:39:48 +03:00
publicKey = "mcOs94W9jqn3SGgc8uWbnmUv0tja/P6tAvaCg3WYKlY=";
allowedIPs = [ "10.100.0.3/32" ];
}
2024-06-02 16:18:19 +03:00
{
# Miika Kone
2024-05-23 13:39:48 +03:00
publicKey = "7m7wnwNlmxZfUNvUOYNh4mTNbOsig7z2K/svUhDHFDY=";
allowedIPs = [ "10.100.0.4/32" ];
}
2024-06-02 16:18:19 +03:00
{
# Silja Puhelin
2024-05-23 13:39:48 +03:00
publicKey = "f6wWd6KD63xwnKkre/ZgZxPJv9GfAXK9Zx/EQEq8cik=";
allowedIPs = [ "10.100.0.5/32" ];
}
2024-06-02 16:18:19 +03:00
{
# Silja Kone
2024-05-23 13:39:48 +03:00
publicKey = "t9cmHc6/+0njdzsTFnnhEGKfhCa2VXFrTH9hF1jOCXw=";
allowedIPs = [ "10.100.0.6/32" ];
}
2024-06-02 16:18:19 +03:00
{
# Vili helium
2024-05-23 13:39:48 +03:00
publicKey = "iGO375NT9EK5LH+E9vjPRRJp+UM4rZ2d1RMVR3f5R0c=";
allowedIPs = [ "10.100.0.7/32" ];
}
];
};
};
2024-06-02 05:53:39 +03:00
services.ddclient = {
enable = true;
domains = [ "netflood.ddnsfree.com" ];
use = "web, web=checkip.dynu.com/, web-skip='IP Address'";
server = "api.dynu.com";
username = "VSinerva";
passwordFile = ddPassFile;
};
2024-06-02 16:18:19 +03:00
#################### EVERYTHING BELOW THIS SHOULD NOT NEED TO CHANGE ####################
2024-05-23 13:39:48 +03:00
2024-07-16 22:25:30 +03:00
nix.settings = {
cores = 3;
max-jobs = 2;
};
2024-06-02 05:53:39 +03:00
boot = {
kernelPackages = pkgs.linuxKernel.packages.linux_rpi4;
2024-06-02 16:18:19 +03:00
initrd.availableKernelModules = [
"xhci_pci"
"usbhid"
"usb_storage"
];
2024-06-02 05:53:39 +03:00
loader = {
2024-09-06 10:33:39 +03:00
systemd-boot.enable = pkgs.lib.mkForce false;
efi.canTouchEfiVariables = pkgs.lib.mkForce false;
2024-06-02 05:53:39 +03:00
grub.enable = false;
generic-extlinux-compatible.enable = true;
};
};
2024-05-23 13:39:48 +03:00
2024-06-02 05:53:39 +03:00
fileSystems = {
"/" = {
device = "/dev/disk/by-label/NIXOS_SD";
fsType = "ext4";
options = [ "noatime" ];
};
};
2024-05-23 13:39:48 +03:00
2024-06-02 05:53:39 +03:00
networking = {
hostName = hostname;
wireless = {
enable = false;
networks."${SSID}".psk = SSIDpassword;
interfaces = [ interface ];
};
};
2024-05-23 13:39:48 +03:00
}