nixos/virtualisation: assert nspawn container name length
If the names for systemd-nspawn containers are too long, the generated bridge interface names will surpass the kernel limit IFNAMSIZ (15 characters + '\0').
This commit is contained in:
@@ -70,6 +70,37 @@ in
|
||||
config = {
|
||||
boot.isNspawnContainer = true;
|
||||
|
||||
assertions = [
|
||||
{
|
||||
# Check every interface defined in allInterfaces.
|
||||
# Containers try to create a bridge "${config.system.name}-${interfaceName}"
|
||||
assertion = lib.all (
|
||||
iface:
|
||||
let
|
||||
hostName = "${config.system.name}-${iface.name}";
|
||||
in
|
||||
lib.stringLength hostName <= 15
|
||||
) (lib.attrValues cfg.allInterfaces);
|
||||
|
||||
message =
|
||||
let
|
||||
offendingInterfaces = lib.filter (
|
||||
iface: lib.stringLength "${config.system.name}-${iface.name}" > 15
|
||||
) (lib.attrValues cfg.allInterfaces);
|
||||
offenderList = map (
|
||||
i:
|
||||
"${config.system.name}-${i.name} (${toString (lib.stringLength "${config.system.name}-${i.name}")} chars)"
|
||||
) offendingInterfaces;
|
||||
in
|
||||
''
|
||||
The following generated host interface names exceed the Linux 15-character limit:
|
||||
${lib.concatStringsSep "\n " offenderList}
|
||||
|
||||
Please shorten 'config.system.name' or the interface names in 'virtualisation.interfaces'.
|
||||
'';
|
||||
}
|
||||
];
|
||||
|
||||
# TODO(arianvp): Remove after https://github.com/NixOS/nixpkgs/pull/480686 is merged
|
||||
console.enable = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user