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