containers: fix broken /etc/hosts entries when localAddress contains a netmask
This commit is contained in:
parent
4889c271ca
commit
ea5551b551
|
@ -676,7 +676,7 @@ in
|
||||||
# Generate /etc/hosts entries for the containers.
|
# Generate /etc/hosts entries for the containers.
|
||||||
networking.extraHosts = concatStrings (mapAttrsToList (name: cfg: optionalString (cfg.localAddress != null)
|
networking.extraHosts = concatStrings (mapAttrsToList (name: cfg: optionalString (cfg.localAddress != null)
|
||||||
''
|
''
|
||||||
${cfg.localAddress} ${name}.containers
|
${head (splitString "/" cfg.localAddress)} ${name}.containers
|
||||||
'') config.containers);
|
'') config.containers);
|
||||||
|
|
||||||
networking.dhcpcd.denyInterfaces = [ "ve-*" "vb-*" ];
|
networking.dhcpcd.denyInterfaces = [ "ve-*" "vb-*" ];
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
# Test for NixOS' container support.
|
||||||
|
|
||||||
|
import ./make-test.nix ({ pkgs, ...} : {
|
||||||
|
name = "containers-hosts";
|
||||||
|
meta = with pkgs.stdenv.lib.maintainers; {
|
||||||
|
maintainers = [ montag451 ];
|
||||||
|
};
|
||||||
|
|
||||||
|
machine =
|
||||||
|
{ config, pkgs, lib, ... }:
|
||||||
|
{
|
||||||
|
virtualisation.memorySize = 256;
|
||||||
|
virtualisation.vlans = [];
|
||||||
|
|
||||||
|
networking.bridges.br0.interfaces = [];
|
||||||
|
networking.interfaces.br0 = {
|
||||||
|
ip4 = [ { address = "10.11.0.254"; prefixLength = 24; } ];
|
||||||
|
};
|
||||||
|
|
||||||
|
# Force /etc/hosts to be the only source for host name resolution
|
||||||
|
environment.etc."nsswitch.conf".text = lib.mkForce ''
|
||||||
|
hosts: files
|
||||||
|
'';
|
||||||
|
|
||||||
|
containers.simple = {
|
||||||
|
autoStart = true;
|
||||||
|
privateNetwork = true;
|
||||||
|
localAddress = "10.10.0.1";
|
||||||
|
hostAddress = "10.10.0.254";
|
||||||
|
|
||||||
|
config = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
containers.netmask = {
|
||||||
|
autoStart = true;
|
||||||
|
privateNetwork = true;
|
||||||
|
hostBridge = "br0";
|
||||||
|
localAddress = "10.11.0.1/24";
|
||||||
|
|
||||||
|
config = {};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
testScript = ''
|
||||||
|
startAll;
|
||||||
|
$machine->waitForUnit("default.target");
|
||||||
|
|
||||||
|
# Ping the containers using the entries added in /etc/hosts
|
||||||
|
$machine->succeed("ping -n -c 1 simple.containers");
|
||||||
|
$machine->succeed("ping -n -c 1 netmask.containers");
|
||||||
|
'';
|
||||||
|
})
|
Loading…
Reference in New Issue