nixbld: factor out network interface names

This commit is contained in:
Sebastien Bourdeauducq 2019-09-18 12:20:03 +08:00
parent 3bd0f2c1e9
commit 9ea3e2e47b
1 changed files with 14 additions and 11 deletions

View File

@ -5,6 +5,9 @@
{ config, pkgs, ... }: { config, pkgs, ... }:
let let
netifWan = "enp0s31f6";
netifLan = "enp3s0";
netifWifi = "wlp4s0";
hydraWwwOutputs = "/var/www/hydra-outputs"; hydraWwwOutputs = "/var/www/hydra-outputs";
in in
{ {
@ -31,25 +34,25 @@ in
allowedTCPPorts = [ 80 443 631 5901 ]; allowedTCPPorts = [ 80 443 631 5901 ];
allowedUDPPorts = [ 53 67 631 ]; allowedUDPPorts = [ 53 67 631 ];
}; };
networkmanager.unmanaged = [ "interface-name:wlp4s0" "interface-name:enp3s0" ]; networkmanager.unmanaged = [ "interface-name:${netifLan}" "interface-name:${netifWifi}" ];
interfaces."enp3s0".ipv4.addresses = [{ interfaces."${netifLan}".ipv4.addresses = [{
address = "192.168.1.1"; address = "192.168.1.1";
prefixLength = 24; prefixLength = 24;
}]; }];
interfaces."wlp4s0".ipv4.addresses = [{ interfaces."${netifWifi}".ipv4.addresses = [{
address = "192.168.12.1"; address = "192.168.12.1";
prefixLength = 24; prefixLength = 24;
}]; }];
nat = { nat = {
enable = true; enable = true;
externalInterface = "enp0s31f6"; externalInterface = netifWan;
internalInterfaces = ["enp3s0" "wlp4s0"]; internalInterfaces = [ netifLan netifWifi ];
}; };
}; };
services.hostapd = { services.hostapd = {
enable = true; enable = true;
interface = "wlp4s0"; interface = netifWifi;
hwMode = "g"; hwMode = "g";
ssid = "M-Labs"; ssid = "M-Labs";
wpaPassphrase = (import /etc/nixos/secret/wifi_password.nix); wpaPassphrase = (import /etc/nixos/secret/wifi_password.nix);
@ -57,11 +60,11 @@ in
services.dnsmasq = { services.dnsmasq = {
enable = true; enable = true;
extraConfig = '' extraConfig = ''
interface=enp3s0 interface=${netifLan}
interface=wlp4s0 interface=${netifWifi}
bind-interfaces bind-interfaces
dhcp-range=interface:enp3s0,192.168.1.10,192.168.1.254,24h dhcp-range=interface:${netifLan},192.168.1.10,192.168.1.254,24h
dhcp-range=interface:wlp4s0,192.168.12.10,192.168.12.254,24h dhcp-range=interface:${netifWifi},192.168.12.10,192.168.12.254,24h
''; '';
}; };
@ -106,7 +109,7 @@ in
# Enable CUPS to print documents. # Enable CUPS to print documents.
services.avahi.enable = true; services.avahi.enable = true;
services.avahi.interfaces = ["enp3s0"]; services.avahi.interfaces = [ netifLan ];
services.avahi.publish.enable = true; services.avahi.publish.enable = true;
services.avahi.publish.userServices = true; services.avahi.publish.userServices = true;
services.printing.enable = true; services.printing.enable = true;