convert network link/address to module-based-service
... and make bridge use it. We also had to convert bridge back into a pair of services. Downstreams want to depend on the bridge it self being configured even if not necessarily all the members are up. e.g. don't want to break ssh on lan if there's a misconfigured wlan device
This commit is contained in:
parent
1580857fde
commit
31f0213b6f
9 changed files with 185 additions and 58 deletions
29
modules/network/address.nix
Normal file
29
modules/network/address.nix
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
liminix
|
||||
, ifwait
|
||||
, serviceFns
|
||||
, lib
|
||||
}:
|
||||
{interface, family, address, prefixLength} :
|
||||
let
|
||||
inherit (liminix.services) oneshot;
|
||||
# rather depending on the assumption that nobody will
|
||||
# ever add two addresses which are the same but with different
|
||||
# prefixes, or the same but different protocols
|
||||
name = "${interface.name}.a.${address}";
|
||||
up = ''
|
||||
. ${serviceFns}
|
||||
dev=$(output ${interface} ifname)
|
||||
ip address add ${address}/${toString prefixLength} dev $dev
|
||||
(in_outputs ${name}
|
||||
echo ${address} > address
|
||||
echo ${toString prefixLength} > prefix-length
|
||||
echo ${family} > family
|
||||
echo $dev > ifname
|
||||
)
|
||||
'';
|
||||
in oneshot {
|
||||
inherit name up;
|
||||
down = "true"; # this has been broken for ~ ages
|
||||
dependencies = [ interface ];
|
||||
}
|
54
modules/network/default.nix
Normal file
54
modules/network/default.nix
Normal file
|
@ -0,0 +1,54 @@
|
|||
## Network
|
||||
## =======
|
||||
##
|
||||
## Basic network services for creating hardware ethernet devices
|
||||
## and adding addresses
|
||||
|
||||
|
||||
{ lib, pkgs, config, ...}:
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
inherit (pkgs) liminix;
|
||||
in {
|
||||
options = {
|
||||
system.service.network = {
|
||||
link = mkOption {
|
||||
description = "hardware network interface";
|
||||
type = liminix.lib.types.serviceDefn;
|
||||
};
|
||||
address = mkOption {
|
||||
description = "network interface address";
|
||||
type = liminix.lib.types.serviceDefn;
|
||||
};
|
||||
};
|
||||
};
|
||||
config = {
|
||||
system.service.network = {
|
||||
link = liminix.callService ./link.nix {
|
||||
ifname = mkOption {
|
||||
type = types.str;
|
||||
example = "eth0";
|
||||
};
|
||||
# other "ip link add" options could go here as well
|
||||
mtu = mkOption {
|
||||
type = types.nullOr types.int;
|
||||
example = 1480;
|
||||
};
|
||||
};
|
||||
address = liminix.callService ./address.nix {
|
||||
interface = mkOption {
|
||||
type = liminix.lib.types.service;
|
||||
};
|
||||
family = mkOption {
|
||||
type = types.enum [ "inet" "inet6" ];
|
||||
};
|
||||
address = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
prefixLength = mkOption {
|
||||
type = types.ints.between 0 128;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
16
modules/network/link.nix
Normal file
16
modules/network/link.nix
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
liminix
|
||||
, ifwait
|
||||
, serviceFns
|
||||
, lib
|
||||
}:
|
||||
{ifname, mtu} :
|
||||
let
|
||||
inherit (liminix.services) longrun oneshot;
|
||||
inherit (lib) concatStringsSep;
|
||||
name = "${ifname}.link";
|
||||
up = liminix.networking.ifup name ifname;
|
||||
in oneshot {
|
||||
inherit name up;
|
||||
down = "ip link set down dev ${ifname}";
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue