rotuer.nix (4907B)
1 # This is not part of Liminix per se. This is my "scratchpad" 2 # configuration for the device I'm testing with. 3 # 4 # Parts of it do do things that Liminix eventually needs to do, but 5 # don't look in here for solutions - just for identifying the 6 # problems. 7 8 9 { config, pkgs, lib, ... } : 10 let 11 secrets = import ./rotuer-secrets.nix; 12 inherit (pkgs.liminix.services) oneshot longrun bundle; 13 inherit (pkgs) serviceFns; 14 svc = config.system.service; 15 wirelessConfig = { 16 country_code = "GB"; 17 inherit (secrets) wpa_passphrase; 18 auth_algs = 1; # 1=wpa2, 2=wep, 3=both 19 wpa = 2; # 1=wpa, 2=wpa2, 3=both 20 wpa_key_mgmt = "WPA-PSK"; 21 wpa_pairwise = "TKIP CCMP"; # auth for wpa (may not need this?) 22 rsn_pairwise = "CCMP"; # auth for wpa2 23 wmm_enabled = 1; 24 }; 25 26 in rec { 27 boot = { 28 tftp = { 29 freeSpaceBytes = 3 * 1024 * 1024; 30 serverip = "10.0.0.1"; 31 ipaddr = "10.0.0.8"; 32 }; 33 }; 34 35 imports = [ 36 ../modules/wlan.nix 37 ../modules/network 38 ../modules/ppp 39 ../modules/dnsmasq 40 ../modules/dhcp6c 41 ../modules/firewall 42 ../modules/hostapd 43 ../modules/bridge 44 ../modules/ntp 45 ../modules/ssh 46 ]; 47 hostname = "rotuer"; 48 49 services.hostap = svc.hostapd.build { 50 interface = config.hardware.networkInterfaces.wlan; 51 params = { 52 ssid = "liminix"; 53 hw_mode="g"; 54 channel = "2"; 55 ieee80211n = 1; 56 } // wirelessConfig; 57 }; 58 59 services.hostap5 = svc.hostapd.build { 60 interface = config.hardware.networkInterfaces.wlan5; 61 params = rec { 62 ssid = "liminix_5"; 63 hw_mode="a"; 64 channel = 36; 65 ht_capab = "[HT40+]"; 66 vht_oper_chwidth = 1; 67 vht_oper_centr_freq_seg0_idx = channel + 6; 68 ieee80211ac = 1; 69 } // wirelessConfig; 70 }; 71 72 services.int = svc.network.address.build { 73 interface = svc.bridge.primary.build { ifname = "int"; }; 74 family = "inet"; address ="10.8.0.1"; prefixLength = 16; 75 }; 76 77 services.bridge = svc.bridge.members.build { 78 primary = services.int; 79 members = with config.hardware.networkInterfaces; 80 [ wlan 81 wlan5 82 lan ]; 83 }; 84 85 services.ntp = svc.ntp.build { 86 pools = { "pool.ntp.org" = ["iburst"]; }; 87 makestep = { threshold = 1.0; limit = 3; }; 88 }; 89 90 services.sshd = svc.ssh.build { }; 91 92 users.root = secrets.root; 93 94 services.dns = 95 let interface = services.int; 96 in svc.dnsmasq.build { 97 resolvconf = services.resolvconf; 98 inherit interface; 99 ranges = [ 100 "10.8.0.10,10.8.0.240" 101 # ra-stateless: sends router advertisements with the O and A 102 # bits set, and provides a stateless DHCP service. The client 103 # will use a SLAAC address, and use DHCP for other 104 # configuration information. 105 "::,constructor:$(output ${interface} ifname),ra-stateless" 106 ]; 107 108 # You can add static addresses for the DHCP server here. I'm 109 # not putting my actual MAC addresses in a public git repo ... 110 hosts = { } // lib.optionalAttrs (builtins.pathExists ./static-leases.nix) (import ./static-leases.nix); 111 112 domain = "fake.liminix.org"; 113 }; 114 115 services.wan = svc.pppoe.build { 116 interface = config.hardware.networkInterfaces.wan; 117 ppp-options = [ 118 "debug" "+ipv6" "noauth" 119 "name" secrets.l2tp.name 120 "password" secrets.l2tp.password 121 ]; 122 }; 123 124 services.resolvconf = oneshot rec { 125 dependencies = [ services.wan ]; 126 name = "resolvconf"; 127 up = '' 128 . ${serviceFns} 129 ( in_outputs ${name} 130 echo "nameserver $(output ${services.wan} ns1)" > resolv.conf 131 echo "nameserver $(output ${services.wan} ns2)" >> resolv.conf 132 chmod 0444 resolv.conf 133 ) 134 ''; 135 }; 136 137 filesystem = 138 let inherit (pkgs.pseudofile) dir symlink; 139 in dir { 140 etc = dir { 141 "resolv.conf" = symlink "${services.resolvconf}/.outputs/resolv.conf"; 142 }; 143 }; 144 145 services.defaultroute4 = svc.network.route.build { 146 via = "$(output ${services.wan} address)"; 147 target = "default"; 148 dependencies = [ services.wan ]; 149 }; 150 151 services.defaultroute6 = svc.network.route.build { 152 via = "$(output ${services.wan} ipv6-peer-address)"; 153 target = "default"; 154 interface = services.wan; 155 }; 156 157 services.firewall = svc.firewall.build { 158 ruleset = import ./demo-firewall.nix; 159 }; 160 161 services.packet_forwarding = svc.network.forward.build { }; 162 163 services.dhcp6c = 164 let client = svc.dhcp6c.client.build { 165 interface = services.wan; 166 }; 167 in bundle { 168 name = "dhcp6c"; 169 contents = [ 170 (svc.dhcp6c.prefix.build { 171 inherit client; 172 interface = services.int; 173 }) 174 (svc.dhcp6c.address.build { 175 inherit client; 176 interface = services.wan; 177 }) 178 ]; 179 }; 180 181 defaultProfile.packages = with pkgs; [ 182 min-collect-garbage 183 ]; 184 185 programs.busybox.applets = [ 186 "fdisk" "sfdisk" 187 ]; 188 }