1
1
Fork 1
mirror of https://github.com/oddlama/nix-config.git synced 2025-10-11 15:20:39 +02:00

feat: use predictable container network creation

This commit is contained in:
oddlama 2023-12-18 01:35:25 +01:00
parent 336f648275
commit aa5ce08891
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A

View file

@ -9,13 +9,16 @@ guestName: guestCfg: {
}: let }: let
inherit inherit
(lib) (lib)
mapAttrs'
flip flip
mapAttrs'
nameValuePair nameValuePair
substring
; ;
initialLinkName = "mv-${(substring 0 13 (builtins.hashString "sha256" guestName))}";
in { in {
autoStart = guestCfg.autostart; autoStart = guestCfg.autostart;
macvlans = ["${guestCfg.container.macvlan}:${guestCfg.networking.mainLinkName}"]; macvlans = ["${guestCfg.container.macvlan}:${initialLinkName}"];
ephemeral = true; ephemeral = true;
privateNetwork = true; privateNetwork = true;
bindMounts = flip mapAttrs' guestCfg.zfs ( bindMounts = flip mapAttrs' guestCfg.zfs (
@ -57,6 +60,14 @@ in {
device = zfsCfg.guestMountpoint; device = zfsCfg.guestMountpoint;
options = ["bind"]; options = ["bind"];
}); });
# Rename the network interface to our liking
systemd.network.links = {
"01-${guestCfg.networking.mainLinkName}" = {
matchConfig.OriginalName = initialLinkName;
linkConfig.Name = guestCfg.networking.mainLinkName;
};
};
} }
(import ./common-guest-config.nix guestName guestCfg) (import ./common-guest-config.nix guestName guestCfg)
] ]