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