From 814dbea27faaa9fa4d7b20541c23237b0a4a386f Mon Sep 17 00:00:00 2001 From: zowoq <59103226+zowoq@users.noreply.github.com> Date: Mon, 6 Jul 2026 17:13:54 +1000 Subject: [PATCH 1/2] nixos/nspawn-container: hash name, remove assertion the code comment is copied from the commit that added the assertion https://github.com/NixOS/nixpkgs/commit/af0238c70efc80925c31d293da3bf8affca6437f --- .../nspawn-container/default.nix | 28 ------------------- .../run-nspawn/src/run_nspawn/__init__.py | 8 ++++++ 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/nixos/modules/virtualisation/nspawn-container/default.nix b/nixos/modules/virtualisation/nspawn-container/default.nix index 82a06929e925..621f2bcb9f33 100644 --- a/nixos/modules/virtualisation/nspawn-container/default.nix +++ b/nixos/modules/virtualisation/nspawn-container/default.nix @@ -81,34 +81,6 @@ in which is prohibited within the Nix build sandbox where the test is run. ''; } - { - # 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'. - ''; - } ]; virtualisation.systemd-nspawn.options = [ diff --git a/nixos/modules/virtualisation/nspawn-container/run-nspawn/src/run_nspawn/__init__.py b/nixos/modules/virtualisation/nspawn-container/run-nspawn/src/run_nspawn/__init__.py index f733ad1845c4..9d5d73433e66 100644 --- a/nixos/modules/virtualisation/nspawn-container/run-nspawn/src/run_nspawn/__init__.py +++ b/nixos/modules/virtualisation/nspawn-container/run-nspawn/src/run_nspawn/__init__.py @@ -1,6 +1,7 @@ import contextlib import dataclasses import fcntl +import hashlib import logging import os import signal @@ -124,6 +125,13 @@ def mk_veth( vlan: int, ) -> typing.Generator[None, None, None]: host_intf_name = f"{container_name}-{container_intf_name}" + # If the names for systemd-nspawn containers are too long, + # the generated bridge interface names will surpass the + # kernel limit IFNAMSIZ (15 characters + '\0'). + if len(host_intf_name) > 15: + hashed = hashlib.sha256(host_intf_name.encode()).hexdigest()[:6] + host_intf_name = f"{host_intf_name[:8]}-{hashed}" + with ensure_vlan_bridge(vlan) as bridge_name: logger.info("creating interface %s", host_intf_name) run_ip( From 2e6f5555de91951c95a1d5010b92b2edf6da2ea6 Mon Sep 17 00:00:00 2001 From: zowoq <59103226+zowoq@users.noreply.github.com> Date: Tue, 7 Jul 2026 10:20:12 +1000 Subject: [PATCH 2/2] nixosTests.grafana: switch to nspawn containers --- nixos/tests/grafana/basic.nix | 4 ++-- nixos/tests/grafana/provision/default.nix | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nixos/tests/grafana/basic.nix b/nixos/tests/grafana/basic.nix index eb024be44fa9..2221960135c5 100644 --- a/nixos/tests/grafana/basic.nix +++ b/nixos/tests/grafana/basic.nix @@ -84,7 +84,7 @@ import ../make-test-python.nix ( }; }; - nodes = builtins.mapAttrs ( + containers = builtins.mapAttrs ( _: val: mkMerge [ val @@ -97,7 +97,7 @@ import ../make-test-python.nix ( meta.maintainers = [ ]; - inherit nodes; + inherit containers; testScript = '' start_all() diff --git a/nixos/tests/grafana/provision/default.nix b/nixos/tests/grafana/provision/default.nix index 8fed76d5b282..9109aa58a99a 100644 --- a/nixos/tests/grafana/provision/default.nix +++ b/nixos/tests/grafana/provision/default.nix @@ -183,7 +183,7 @@ import ../../make-test-python.nix ( }; }; - nodes = builtins.mapAttrs ( + containers = builtins.mapAttrs ( _: val: mkMerge [ val @@ -196,7 +196,7 @@ import ../../make-test-python.nix ( meta.maintainers = [ ]; - inherit nodes; + inherit containers; testScript = '' start_all()