From 8d671d8dee01248ece72913684d9e88890bf4844 Mon Sep 17 00:00:00 2001 From: Astro Date: Sat, 20 Nov 2021 00:43:32 +0100 Subject: [PATCH] nixos-module/server/lxc-containers: resolve lxc interface name issue by ensuring the type key comes first it took very long to find this --- nix/nixos-module/server/lxc-containers.nix | 25 +++++++++------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/nix/nixos-module/server/lxc-containers.nix b/nix/nixos-module/server/lxc-containers.nix index b62b716..04b1c46 100644 --- a/nix/nixos-module/server/lxc-containers.nix +++ b/nix/nixos-module/server/lxc-containers.nix @@ -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