demo.nix (6314B)
1 # This is an example configuration for a "typical" small office/home 2 # router and wifi access point. 3 4 # You need to copy it to another filename and change the configuration 5 # wherever the text "EDIT" appears - please consult the tutorial 6 # documentation for details. 7 8 { config, pkgs, ... }: 9 let 10 inherit (pkgs.liminix.services) bundle oneshot; 11 # EDIT: you can pick your preferred RFC1918 address space 12 # for NATted connections, if you don't like this one. 13 ipv4LocalNet = "10.8.0"; 14 svc = config.system.service; 15 16 in 17 rec { 18 boot = { 19 tftp = { 20 freeSpaceBytes = 3 * 1024 * 1024; 21 serverip = "10.0.0.1"; 22 ipaddr = "10.0.0.8"; 23 }; 24 }; 25 26 imports = [ 27 ../modules/bridge 28 ../modules/dhcp6c 29 ../modules/dnsmasq 30 ../modules/firewall 31 ../modules/hostapd 32 ../modules/network 33 ../modules/ntp 34 ../modules/ppp 35 ../modules/ssh 36 ../modules/vlan 37 ../modules/wlan.nix 38 ]; 39 rootfsType = "jffs2"; 40 hostname = "the-internet"; # EDIT 41 42 services.hostap = svc.hostapd.build { 43 interface = config.hardware.networkInterfaces.wlan; 44 # EDIT: you will want to change the obvious things 45 # here to values of your choice 46 params = { 47 ssid = "the-internet"; 48 channel = "1"; 49 country_code = "GB"; 50 wpa_passphrase = "not a real wifi password"; 51 52 hw_mode = "g"; 53 ieee80211n = 1; 54 auth_algs = 1; # 1=wpa2, 2=wep, 3=both 55 wpa = 2; # 1=wpa, 2=wpa2, 3=both 56 wpa_key_mgmt = "WPA-PSK"; 57 wpa_pairwise = "TKIP CCMP"; # auth for wpa (may not need this?) 58 rsn_pairwise = "CCMP"; # auth for wpa2 59 wmm_enabled = 1; 60 }; 61 }; 62 63 services.int = svc.network.address.build { 64 interface = svc.bridge.primary.build { ifname = "int"; }; 65 family = "inet"; 66 address = "${ipv4LocalNet}.1"; 67 prefixLength = 16; 68 }; 69 70 services.bridge = svc.bridge.members.build { 71 primary = services.int; 72 members = with config.hardware.networkInterfaces; [ 73 wlan 74 lan 75 ]; 76 }; 77 78 services.ntp = svc.ntp.build { 79 pools = { 80 "pool.ntp.org" = [ "iburst" ]; 81 }; 82 makestep = { 83 threshold = 1.0; 84 limit = 3; 85 }; 86 }; 87 88 services.sshd = svc.ssh.build { }; 89 90 users.root = { 91 # EDIT: choose a root password and then use 92 # "mkpasswd -m sha512crypt" to determine the hash. 93 # It should start wirh $6$. 94 passwd = "$6$6HG7WALLQQY1LQDE$428cnouMJ7wVmyK9.dF1uWs7t0z9ztgp3MHvN5bbeo0M4Kqg/u2ThjoSHIjCEJQlnVpDOaEKcOjXAlIClHWN21"; 95 openssh.authorizedKeys.keys = [ 96 # EDIT: you can add your ssh pubkey here 97 # "ssh-rsa AAAAB3NzaC1....H6hKd user@example.com"; 98 ]; 99 }; 100 101 services.dns = 102 let 103 interface = services.int; 104 in 105 svc.dnsmasq.build { 106 resolvconf = services.resolvconf; 107 inherit interface; 108 ranges = [ 109 "${ipv4LocalNet}.10,${ipv4LocalNet}.249" 110 # EDIT: ... maybe. In this example we use "ra-stateless", 111 # meaning dnsmasq sends router advertisements with the O and A 112 # bits set, and provides a stateless DHCP service. The client 113 # will use a SLAAC address, and use DHCP for other 114 # configuration information. 115 # If you didn't understand the preceding sentence then 116 # the default is _probably_ fine, but if you need 117 # a DHCP-only IPv6 network or some other different 118 # configuration, this is the place to change it. 119 "::,constructor:$(output ${interface} ifname),ra-stateless" 120 ]; 121 # EDIT: choose a domain name for the DNS names issued for your 122 # DHCP-issued hosts 123 domain = "lan.example.com"; 124 }; 125 126 services.wan = svc.pppoe.build { 127 interface = config.hardware.networkInterfaces.wan; 128 ppp-options = [ 129 "debug" 130 "+ipv6" 131 "noauth" 132 # EDIT: change the strings "chap-username" 133 # and "chap-secret" to match the username/password 134 # provided by your ISP for PPP logins 135 "name" 136 "chap-username" 137 "password" 138 "chap-secret" 139 ]; 140 }; 141 142 services.resolvconf = oneshot rec { 143 dependencies = [ services.wan ]; 144 name = "resolvconf"; 145 up = '' 146 ( in_outputs ${name} 147 echo "nameserver $(output ${services.wan} ns1)" > resolv.conf 148 echo "nameserver $(output ${services.wan} ns2)" >> resolv.conf 149 chmod 0444 resolv.conf 150 ) 151 ''; 152 }; 153 154 filesystem = 155 let 156 inherit (pkgs.pseudofile) dir symlink; 157 in 158 dir { 159 etc = dir { 160 "resolv.conf" = symlink "${services.resolvconf}/.outputs/resolv.conf"; 161 }; 162 }; 163 164 services.defaultroute4 = svc.network.route.build { 165 via = "$(output ${services.wan} address)"; 166 target = "default"; 167 dependencies = [ services.wan ]; 168 }; 169 170 services.defaultroute6 = svc.network.route.build { 171 via = "$(output ${services.wan} ipv6-peer-address)"; 172 target = "default"; 173 interface = services.wan; 174 }; 175 176 services.firewall = svc.firewall.build { }; 177 178 services.packet_forwarding = svc.network.forward.build { }; 179 180 # We expect the ISP uses DHCP6 to issue IPv6 addresses. There is a 181 # service to request address information in the form of a DHCP 182 # lease, and two dependent services that listen for updates to the 183 # DHCP address information and update the addresses of the WAN and 184 # LAN interfaces respectively. 185 186 services.dhcp6c = 187 let 188 client = svc.dhcp6c.client.build { 189 interface = services.wan; 190 }; 191 in 192 bundle { 193 name = "dhcp6c"; 194 contents = [ 195 (svc.dhcp6c.prefix.build { 196 # if your ISP provides you a real IPv6 prefix for your local 197 # network (usually a /64 or /48 or something in between the 198 # two), this service subscribes to that "prefix delegation" 199 # information, and uses it to assign an address to the LAN 200 # device. dnsmasq will notice this address and use it to 201 # form the addresses it hands out to devices on the lan 202 inherit client; 203 interface = services.int; 204 }) 205 (svc.dhcp6c.address.build { 206 # if your ISP provides you a regular global IPv6 address, 207 # this service subscribes to that information and assigns 208 # the address to the WAN device. 209 inherit client; 210 interface = services.wan; 211 }) 212 ]; 213 }; 214 215 defaultProfile.packages = with pkgs; [ min-collect-garbage ]; 216 }