network-interfaces: support changing MAC addresses of interfaces

svn path=/nixos/trunk/; revision=24846
This commit is contained in:
Evgeny Egorochkin 2010-11-24 22:58:48 +00:00
parent 50d8698fd8
commit 72422d4126

View file

@ -115,6 +115,15 @@ in
'';
};
macAddress = mkOption {
default = "";
example = "00:11:22:33:44:55";
type = types.string;
description = ''
MAC address of the interface. Leave empty to use the default.
'';
};
};
};
@ -157,6 +166,16 @@ in
export PATH=${config.system.sbin.modprobe}/sbin:$PATH
modprobe af_packet || true
${pkgs.lib.concatMapStrings (i:
if i.macAddress != "" then
''
echo "Configuring interface ${i.name}..."
${ifconfig} "${i.name}" down || true
${ifconfig} hw ether "${i.name}" "${i.macAddress}" || true
''
else "") cfg.interfaces
}
for i in $(cd /sys/class/net && ls -d *); do
echo "Bringing up network device $i..."
${ifconfig} $i up || true