nix/nixos/hosts/osaka-vultr-01/default.nix

72 lines
2.2 KiB
Nix
Raw Normal View History

2023-09-20 11:52:00 +02:00
{ config, lib, pkgs, modulesPath, desktop, username, ... }: {
2023-09-20 13:26:12 +02:00
imports = [
./disks.nix
];
# Enable distributed Builds
nix.distributedBuilds = true;
2023-09-20 11:52:00 +02:00
nixpkgs.config.allowUnfree = false;
2023-09-20 12:40:48 +02:00
boot.initrd.availableKernelModules = [ "ata_piix" "ohci_pci" "virtio_pci" "virtio_blk" "sr_mod" ];
2023-09-20 11:52:00 +02:00
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ ];
boot.extraModulePackages = [ ];
2023-09-20 13:33:35 +02:00
virtualisation.hypervGuest.enable = true;
2023-09-20 11:52:00 +02:00
networking.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
time.timeZone = "Asia/Tokyo";
2023-10-04 12:51:02 +02:00
networking.hostName = "osaka-vultr-01";
2023-09-20 11:52:00 +02:00
2023-10-07 14:51:08 +02:00
networking.firewall.allowedTCPPorts = [
22
80
2023-10-07 15:18:18 +02:00
443
2023-10-07 14:51:08 +02:00
];
2023-10-06 05:53:53 +02:00
networking.firewall.allowedUDPPorts = [ 51820 ];
2023-10-06 05:52:40 +02:00
# Set up the secrets file:
2023-10-06 06:04:39 +02:00
sops.secrets."wireguard_keys/osaka-vultr-01" = {
2023-10-06 05:52:40 +02:00
owner = "root";
sopsFile = ../../../secrets/wireguard.yaml;
};
2023-10-06 06:08:55 +02:00
sops.secrets."wireguard_keys/preshared_key" = {
owner = "root";
sopsFile = ../../../secrets/wireguard.yaml;
};
2023-10-06 05:52:40 +02:00
# Wireguard Forwarder
boot.kernel.sysctl = { "net.ipv4.ip_forward" = true; };
2023-10-07 14:29:33 +02:00
networking.firewall.allowPing = true;
2023-10-06 05:52:40 +02:00
networking.wireguard = {
enable = true;
interfaces = {
2023-10-06 06:04:39 +02:00
"wireguard0" = {
2023-10-06 07:57:17 +02:00
ips = [ "10.100.0.1/24" ];
2023-10-06 06:04:39 +02:00
listenPort = 51820;
2023-10-07 13:10:33 +02:00
privateKeyFile = "/run/secrets/wireguard_keys/osaka-vultr-01";
2023-10-08 06:15:32 +02:00
postSetup = ''${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING -s 10.100.0.0/24 -o eno3 -j MASQUERADE'';
postShutdown = ''${pkgs.iptables}/bin/iptables -t nat -D POSTROUTING -s 10.100.0.0/24 -o eno3 -j MASQUERADE'';
2023-10-06 06:04:39 +02:00
peers = [
{ # nixos-rpi4-03
2023-10-06 06:18:32 +02:00
publicKey = "trHvfNtQ7HKMiJjxEXo2Iubq5G6egjx7gHiBlDmJ5Ek=";
2023-10-06 06:08:55 +02:00
presharedKeyFile = "/run/secrets/wireguard_keys/preshared_key";
2023-10-07 13:10:33 +02:00
persistentKeepalive = 5;
allowedIPs = [ "10.100.0.2/32" ];
2023-10-06 06:04:39 +02:00
}
];
2023-10-06 05:52:40 +02:00
};
};
};
2023-10-08 05:09:31 +02:00
networking.nat = {
enable = true;
externalInterface = "eno3";
2023-10-08 05:10:37 +02:00
internalInterfaces = [ "wireguard0" ];
2023-10-08 05:53:21 +02:00
internalIPs = [ "10.100.0.0/24" ];
2023-10-08 05:09:31 +02:00
forwardPorts = [
2023-10-08 06:20:09 +02:00
{ sourcePort = 80; destination = "10.100.0.2:80"; }
{ sourcePort = 443; destination = "10.100.0.2:443"; }
2023-10-08 05:09:31 +02:00
];
};
2023-09-20 13:54:06 +02:00
}