forked from DGNum/liminix
support setting network device names
this means that net devices in devices/foo/default.nix can be specified by their sysfs paths (instead of by "eth0" and "eth1" that may change from one kernel version to the next) and given mnenomic names that are helpful for the hardware. Like "wan" and "lan[1..4]"
This commit is contained in:
parent
e2ea145ce5
commit
cc73a98419
3 changed files with 39 additions and 5 deletions
|
@ -77,8 +77,14 @@
|
||||||
networkInterfaces =
|
networkInterfaces =
|
||||||
let inherit (config.system.service.network) link;
|
let inherit (config.system.service.network) link;
|
||||||
in {
|
in {
|
||||||
wan = link.build { ifname = "eth0"; };
|
wan = link.build {
|
||||||
lan = link.build { ifname = "eth1"; };
|
devpath = "/devices/pci0000:00/0000:00:13.0/virtio0";
|
||||||
|
ifname = "wan";
|
||||||
|
};
|
||||||
|
lan = link.build {
|
||||||
|
devpath = "/devices/pci0000:00/0000:00:14.0/virtio1";
|
||||||
|
ifname = "lan";
|
||||||
|
};
|
||||||
|
|
||||||
wlan_24 = link.build {
|
wlan_24 = link.build {
|
||||||
ifname = "wlan0";
|
ifname = "wlan0";
|
||||||
|
|
|
@ -68,7 +68,21 @@ in {
|
||||||
ifname = mkOption {
|
ifname = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
example = "eth0";
|
example = "eth0";
|
||||||
|
description = ''
|
||||||
|
Device name as used by the kernel (as seen in "ip link"
|
||||||
|
or "ifconfig" output). If devpath is also specified, the
|
||||||
|
device will be renamed to the name provided.
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
|
devpath = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
example = "/devices/platform/soc/soc:internal-regs/f1070000.ethernet";
|
||||||
|
description = ''
|
||||||
|
Path to the sysfs node of the device. If you provide this
|
||||||
|
and the ifname option, the device will be renamed to the
|
||||||
|
name given by ifname.
|
||||||
|
''; };
|
||||||
# other "ip link add" options could go here as well
|
# other "ip link add" options could go here as well
|
||||||
mtu = mkOption {
|
mtu = mkOption {
|
||||||
type = types.nullOr types.int;
|
type = types.nullOr types.int;
|
||||||
|
|
|
@ -4,13 +4,27 @@
|
||||||
, serviceFns
|
, serviceFns
|
||||||
, lib
|
, lib
|
||||||
}:
|
}:
|
||||||
{ifname, mtu} :
|
{
|
||||||
|
ifname
|
||||||
|
, devpath ? null
|
||||||
|
, mtu} :
|
||||||
|
# if devpath is supplied, we rename the interface at that
|
||||||
|
# path to have the specified name.
|
||||||
let
|
let
|
||||||
inherit (liminix.services) longrun oneshot;
|
inherit (liminix.services) longrun oneshot;
|
||||||
inherit (lib) concatStringsSep;
|
inherit (lib) concatStringsSep;
|
||||||
name = "${ifname}.link";
|
name = "${ifname}.link";
|
||||||
up = liminix.networking.ifup name ifname;
|
rename = if devpath != null
|
||||||
|
then ''
|
||||||
|
oldname=$(cd /sys${devpath} && cd net/ && echo *)
|
||||||
|
ip link set ''${oldname} name ${ifname}
|
||||||
|
''
|
||||||
|
else "";
|
||||||
in oneshot {
|
in oneshot {
|
||||||
inherit name up;
|
inherit name;
|
||||||
|
up = ''
|
||||||
|
${rename}
|
||||||
|
${liminix.networking.ifup name ifname}
|
||||||
|
'';
|
||||||
down = "ip link set down dev ${ifname}";
|
down = "ip link set down dev ${ifname}";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue