wap.nix (2458B)
1 { 2 config, 3 pkgs, 4 lib, 5 ... 6 }: 7 let 8 inherit (pkgs) liminix; 9 inherit (lib) mkOption types; 10 11 inherit (pkgs.liminix.services) oneshot target; 12 inherit (pkgs.pseudofile) dir symlink; 13 inherit (pkgs) serviceFns; 14 svc = config.system.service; 15 cfg = config.profile.wap; 16 17 hostaps = 18 let 19 defaults = { 20 auth_algs = 1; # 1=wpa2, 2=wep, 3=both 21 wpa = 2; # 1=wpa, 2=wpa2, 3=both 22 wpa_key_mgmt = "WPA-PSK"; 23 wpa_pairwise = "TKIP CCMP"; # auth for wpa (may not need this?) 24 rsn_pairwise = "CCMP"; # auth for wpa2 25 }; 26 in 27 lib.mapAttrs' ( 28 name: value: 29 let 30 attrs = defaults // { ssid = name; } // value; 31 in 32 lib.nameValuePair "hostap-${name}" ( 33 svc.hostapd.build { 34 interface = attrs.interface; 35 params = lib.filterAttrs (k: v: k != "interface") attrs; 36 } 37 ) 38 ) cfg.wireless.networks; 39 40 in 41 { 42 imports = [ 43 ../wlan.nix 44 ../network 45 ../hostapd 46 ../bridge 47 { config.services = hostaps; } 48 ]; 49 50 options.profile.wap = { 51 interfaces = mkOption { 52 type = types.listOf liminix.lib.types.interface; 53 default = [ ]; 54 }; 55 wireless = mkOption { 56 type = types.attrsOf types.anything; 57 }; 58 }; 59 config = { 60 61 services.int = svc.bridge.primary.build { 62 ifname = "int"; 63 }; 64 65 services.bridge = svc.bridge.members.build { 66 primary = config.services.int; 67 members = cfg.interfaces; 68 }; 69 70 services.dhcpc = svc.network.dhcp.client.build { 71 interface = config.services.int; 72 dependencies = [ config.services.hostname ]; 73 }; 74 75 services.defaultroute4 = svc.network.route.build { 76 via = "$(output ${config.services.dhcpc} router)"; 77 target = "default"; 78 dependencies = [ config.services.dhcpc ]; 79 }; 80 81 services.resolvconf = oneshot rec { 82 dependencies = [ config.services.dhcpc ]; 83 name = "resolvconf"; 84 # CHECK: https://udhcp.busybox.net/README.udhcpc says 85 # 'A list of DNS server' but doesn't say what separates the 86 # list members. Assuming it's a space or other IFS character 87 up = '' 88 ( in_outputs ${name} 89 for i in $(output ${config.services.dhcpc} dns); do 90 echo "nameserver $i" > resolv.conf 91 done 92 ) 93 ''; 94 }; 95 filesystem = dir { 96 etc = dir { 97 "resolv.conf" = symlink "${config.services.resolvconf}/.outputs/resolv.conf"; 98 }; 99 }; 100 }; 101 }