liminix

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

wap.nix (2588B)


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