nixos-module/server/lxc-containers: resolve lxc interface name issue by ensuring the type key comes first

it took very long to find this
This commit is contained in:
Astro 2021-11-20 00:43:32 +01:00
parent eb6e47e505
commit 8d671d8dee
1 changed files with 10 additions and 15 deletions

View File

@ -1,16 +1,6 @@
{ hostName, self, config, lib, pkgs, ... }:
let
# Downgrade: lxc-4.0.9 names network interfaces in containers eth0,
# and eth1 despite configured differently.
lxc = pkgs.lxc.overrideAttrs (_: rec {
version = "4.0.6";
src = pkgs.fetchurl {
url = "https://linuxcontainers.org/downloads/lxc/lxc-${version}.tar.gz";
sha256 = "0qz4l7mlhq7hx53q606qgvkyzyr01glsw290v8ppzvxn1fydlrci";
};
});
# Containers that are run on this host
containers =
lib.filterAttrs (_: { role, model, ... }:
@ -54,12 +44,17 @@ let
})
) (builtins.attrNames interfaces);
attrNamesOrdered = attrs:
if attrs ? type
then [ "type" ] ++ lib.remove "type" (builtins.attrNames attrs)
else builtins.attrNames attrs;
serialize = name: x:
if builtins.isString x
then "${name} = ${x}\n"
else if builtins.isAttrs x
then builtins.concatStringsSep "" (
map (n: serialize "${name}.${n}" x.${n}) (builtins.attrNames x)
map (n: serialize "${name}.${n}" x.${n}) (attrNamesOrdered x)
)
else if builtins.isList x
then
@ -176,7 +171,7 @@ in
environment.systemPackages = [
# `lxc-attach` et al
lxc build-script
pkgs.lxc build-script
# User scripts
enable-script disable-script
];
@ -234,14 +229,14 @@ in
"/var/lib/lxc/%i/rootfs/init"
"/etc/start-containers"
];
serviceConfig = {
serviceConfig = with pkgs; {
Type = "simple";
ExecStart = "${lxc}/bin/lxc-start -F -C -n %i";
ExecStop = "${lxc}/bin/lxc-stop -n %i";
ExecReload =
let
script = pkgs.writeScript "reload-lxc-container.sh" ''
#! ${pkgs.runtimeShell} -e
script = writeScript "reload-lxc-container.sh" ''
#! ${runtimeShell} -e
SYSTEM=$(dirname $(readlink /var/lib/lxc/$1/rootfs/init))
exec ${lxc}/bin/lxc-attach -n $1 $SYSTEM/bin/switch-to-configuration switch