liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

wap.nix (2596B)


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