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