liminix

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

default.nix (2038B)


      1 {
      2   callPackage
      3 , liminix
      4 , ifwait
      5 , lib
      6 }:
      7 let
      8   inherit (liminix.services) oneshot longrun;
      9   inherit (lib) concatStringsSep optional;
     10 in {
     11   interface = { type ? "hardware", device, link ? null, primary ? null, id ? null, dependencies ? [] }  @ args:
     12     let ups =
     13           []
     14           ++ optional (type == "bridge")
     15             "ip link add name ${device} type bridge"
     16           ++ optional (type == "vlan")
     17             "ip link add link ${link} name ${device} type vlan id ${id}"
     18           ++ ["${ifwait}/bin/ifwait -v ${device} present"]
     19           ++ ["ip link set up dev ${device}"]
     20           ++ optional (primary != null)
     21             "ip link set dev ${device} master ${primary.device}";
     22     in oneshot {
     23       name = "${device}.link";
     24       up = lib.concatStringsSep "\n" ups;
     25       down = "ip link set down dev ${device}";
     26       dependencies = dependencies ++ lib.optional (primary != null) primary;
     27     } // {
     28       inherit device;
     29     };
     30   address = interface: { family, dependencies ? [], prefixLength, address } @ args:
     31     let inherit (builtins) toString;
     32     in oneshot {
     33       dependencies = [ interface ] ++ dependencies;
     34       name = "${interface.device}.addr.${address}";
     35       up = "ip address add ${address}/${toString prefixLength} dev ${interface.device} ";
     36       down = "ip address del ${address}/${toString prefixLength} dev ${interface.device} ";
     37     } // {
     38       inherit (interface) device;
     39     };
     40   udhcpc = callPackage ./udhcpc.nix {};
     41   odhcpc = interface: { ... } @ args: longrun {
     42     name = "${interface.device}.odhcp";
     43     run = "odhcpcd ${interface.device}";
     44   };
     45   dnsmasq = callPackage ./dnsmasq.nix {};
     46   hostapd = callPackage ./hostapd.nix {};
     47   route = { name, target, via, dependencies, dev ? null }:
     48     let with_dev = if dev != null then "dev ${dev}" else "";
     49     in oneshot {
     50       inherit name;
     51       up = ''
     52         ip route add ${target} via ${via} ${with_dev}
     53       '';
     54       down = ''
     55         ip route del ${target} via ${via} ${with_dev}
     56       '';
     57       inherit dependencies;
     58     };
     59 }