lol

containers: fix broken /etc/hosts entries when localAddress contains a netmask

authored by

montag451 and committed by
Jörg Thalheim
ea5551b5 4889c271

+53 -1
+1 -1
nixos/modules/virtualisation/containers.nix
··· 676 676 # Generate /etc/hosts entries for the containers. 677 677 networking.extraHosts = concatStrings (mapAttrsToList (name: cfg: optionalString (cfg.localAddress != null) 678 678 '' 679 - ${cfg.localAddress} ${name}.containers 679 + ${head (splitString "/" cfg.localAddress)} ${name}.containers 680 680 '') config.containers); 681 681 682 682 networking.dhcpcd.denyInterfaces = [ "ve-*" "vb-*" ];
+52
nixos/tests/containers-hosts.nix
··· 1 + # Test for NixOS' container support. 2 + 3 + import ./make-test.nix ({ pkgs, ...} : { 4 + name = "containers-hosts"; 5 + meta = with pkgs.stdenv.lib.maintainers; { 6 + maintainers = [ montag451 ]; 7 + }; 8 + 9 + machine = 10 + { config, pkgs, lib, ... }: 11 + { 12 + virtualisation.memorySize = 256; 13 + virtualisation.vlans = []; 14 + 15 + networking.bridges.br0.interfaces = []; 16 + networking.interfaces.br0 = { 17 + ip4 = [ { address = "10.11.0.254"; prefixLength = 24; } ]; 18 + }; 19 + 20 + # Force /etc/hosts to be the only source for host name resolution 21 + environment.etc."nsswitch.conf".text = lib.mkForce '' 22 + hosts: files 23 + ''; 24 + 25 + containers.simple = { 26 + autoStart = true; 27 + privateNetwork = true; 28 + localAddress = "10.10.0.1"; 29 + hostAddress = "10.10.0.254"; 30 + 31 + config = {}; 32 + }; 33 + 34 + containers.netmask = { 35 + autoStart = true; 36 + privateNetwork = true; 37 + hostBridge = "br0"; 38 + localAddress = "10.11.0.1/24"; 39 + 40 + config = {}; 41 + }; 42 + }; 43 + 44 + testScript = '' 45 + startAll; 46 + $machine->waitForUnit("default.target"); 47 + 48 + # Ping the containers using the entries added in /etc/hosts 49 + $machine->succeed("ping -n -c 1 simple.containers"); 50 + $machine->succeed("ping -n -c 1 netmask.containers"); 51 + ''; 52 + })