liminix

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

default.nix (4431B)


      1 ## Network
      2 ## =======
      3 ##
      4 ## Basic network services for creating hardware ethernet devices
      5 ## and adding addresses
      6 
      7 {
      8   lib,
      9   pkgs,
     10   config,
     11   ...
     12 }:
     13 let
     14   inherit (lib) mkOption types;
     15   inherit (pkgs) liminix;
     16   inherit (pkgs.liminix.services) bundle;
     17 in
     18 {
     19   options = {
     20     system.service.network = {
     21       link = mkOption {
     22         description = "hardware network interface";
     23         type = liminix.lib.types.serviceDefn;
     24       };
     25       address = mkOption {
     26         description = "network interface address";
     27         type = liminix.lib.types.serviceDefn;
     28       };
     29       route = mkOption {
     30         type = liminix.lib.types.serviceDefn;
     31       };
     32       forward = mkOption {
     33         type = liminix.lib.types.serviceDefn;
     34       };
     35       dhcp = {
     36         client = mkOption {
     37           # this needs to move to its own service as it has
     38           # busybox config
     39           description = "DHCP v4 client";
     40           type = liminix.lib.types.serviceDefn;
     41         };
     42       };
     43     };
     44   };
     45   config = {
     46     hardware.networkInterfaces = {
     47       lo =
     48         let
     49           net = config.system.service.network;
     50           iface = net.link.build { ifname = "lo"; };
     51         in
     52         bundle {
     53           name = "loopback";
     54           contents = [
     55             (net.address.build {
     56               interface = iface;
     57               family = "inet";
     58               address = "127.0.0.1";
     59               prefixLength = 8;
     60             })
     61             (net.address.build {
     62               interface = iface;
     63               family = "inet6";
     64               address = "::1";
     65               prefixLength = 128;
     66             })
     67           ];
     68         };
     69     };
     70     services.loopback = config.hardware.networkInterfaces.lo;
     71 
     72     system.service.network = {
     73       link = config.system.callService ./link.nix {
     74         ifname = mkOption {
     75           type = types.str;
     76           example = "eth0";
     77           description = ''
     78             Device name as used by the kernel (as seen in "ip link"
     79             or "ifconfig" output). If devpath is also specified, the
     80             device will be renamed to the name provided.
     81           '';
     82         };
     83         devpath = mkOption {
     84           type = types.nullOr types.str;
     85           default = null;
     86           example = "/devices/platform/soc/soc:internal-regs/f1070000.ethernet";
     87           description = ''
     88             Path to the sysfs node of the device. If you provide this
     89             and the ifname option, the device will be renamed to the
     90             name given by ifname.
     91           '';
     92         };
     93         # other "ip link add" options could go here as well
     94         mtu = mkOption {
     95           type = types.nullOr types.int;
     96           example = 1480;
     97         };
     98       };
     99       address = config.system.callService ./address.nix {
    100         interface = mkOption {
    101           type = liminix.lib.types.service;
    102         };
    103         family = mkOption {
    104           type = types.enum [
    105             "inet"
    106             "inet6"
    107           ];
    108         };
    109         address = mkOption {
    110           type = types.str;
    111         };
    112         prefixLength = mkOption {
    113           type = types.ints.between 0 128;
    114         };
    115       };
    116 
    117       route = config.system.callService ./route.nix {
    118         interface = mkOption {
    119           type = types.nullOr liminix.lib.types.interface;
    120           default = null;
    121           description = "Interface to route through. May be omitted if it can be inferred from \"via\"";
    122         };
    123         target = mkOption {
    124           type = types.str;
    125           description = "host or network to add route to";
    126         };
    127         via = mkOption {
    128           type = types.str;
    129           description = "address of next hop";
    130         };
    131         metric = mkOption {
    132           type = types.int;
    133           description = "route metric";
    134           default = 100;
    135         };
    136       };
    137 
    138       forward = config.system.callService ./forward.nix {
    139         enableIPv4 = mkOption {
    140           type = types.bool;
    141           default = true;
    142         };
    143         enableIPv6 = mkOption {
    144           type = types.bool;
    145           default = true;
    146         };
    147       };
    148 
    149       dhcp.client =
    150         lib.warn
    151           ''
    152             system.services.network.dhcp.client is deprecated and will
    153             be removed in 2026.  Use system.service.dhcp4c instead
    154           ''
    155           config.system.callService
    156           ./dhcpc.nix
    157           {
    158             interface = mkOption {
    159               type = liminix.lib.types.service;
    160             };
    161           };
    162 
    163     };
    164   };
    165 }