From f41d77397adf49d3bea13d8d922eceb78f86240e Mon Sep 17 00:00:00 2001 From: Berk Arslan Date: Wed, 4 Dec 2024 23:04:28 +0200 Subject: [PATCH] Add MAC address sharing for GUIVM --- modules/common/logging/hw-mac-retrieve.nix | 7 ++++--- modules/microvm/virtualization/microvm/adminvm.nix | 2 +- modules/microvm/virtualization/microvm/guivm.nix | 5 +++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/common/logging/hw-mac-retrieve.nix b/modules/common/logging/hw-mac-retrieve.nix index 82cc8863c..df0f9acf0 100644 --- a/modules/common/logging/hw-mac-retrieve.nix +++ b/modules/common/logging/hw-mac-retrieve.nix @@ -1,5 +1,6 @@ # Copyright 2022-2024 TII (SSRC) and the Ghaf contributors # SPDX-License-Identifier: Apache-2.0 +{ hostConfig }: { config, lib, @@ -12,7 +13,7 @@ let macCommand = "${pkgs.hwinfo}/bin/hwinfo --network --only /class/net/wlp0s5f0 | ${pkgs.gawk}/bin/awk '/Permanent HW Address/ {print $4}'"; macAddressPath = config.ghaf.logging.identifierFilePath; in -{ + { options.ghaf.logging.identifierFilePath = lib.mkOption { description = '' This configuration option used to specify the identifier file path. @@ -28,7 +29,7 @@ in # TODO: Remove hw-mac.service and replace with givc rpc later systemd.services."hw-mac" = { description = "Retrieve MAC address from net-vm"; - wantedBy = [ "alloy.service" ]; + wantedBy = if hostConfig.ghaf.virtualization.microvm.guivm.enable then [ "ewwbar.service" ] else [ "alloy.service" ]; requires = [ "network-online.target" ]; serviceConfig = { Type = "oneshot"; @@ -36,7 +37,7 @@ in # Make sure we can ssh before we retrieve mac address ExecStartPre = "${sshCommand} ls"; ExecStart = '' - ${pkgs.bash}/bin/bash -c "echo -n $(${sshCommand} ${macCommand}) > ${macAddressPath}" + ${pkgs.bash}/bin/bash -c "echo -n $(${sshCommand} ${macCommand}) > ${macAddressPath} " ''; Restart = "on-failure"; RestartSec = "1"; diff --git a/modules/microvm/virtualization/microvm/adminvm.nix b/modules/microvm/virtualization/microvm/adminvm.nix index 9e235a9ca..8a79a8cbb 100644 --- a/modules/microvm/virtualization/microvm/adminvm.nix +++ b/modules/microvm/virtualization/microvm/adminvm.nix @@ -22,7 +22,7 @@ let internalIP = 10; }) # We need to retrieve mac address and start log aggregator - ../../../common/logging/hw-mac-retrieve.nix + (import ../../../common/logging/hw-mac-retrieve.nix { hostConfig=config; }) ../../../common/logging/logs-aggregator.nix ./common/storagevm.nix ( diff --git a/modules/microvm/virtualization/microvm/guivm.nix b/modules/microvm/virtualization/microvm/guivm.nix index 7ddedd443..aa941ba15 100644 --- a/modules/microvm/virtualization/microvm/guivm.nix +++ b/modules/microvm/virtualization/microvm/guivm.nix @@ -11,6 +11,7 @@ let vmName = "gui-vm"; macAddress = "02:00:00:02:02:02"; inherit (import ../../../../lib/launcher.nix { inherit pkgs lib; }) rmDesktopEntries; + hostConfig = config; guivmBaseConfiguration = { imports = [ inputs.impermanence.nixosModules.impermanence @@ -29,6 +30,9 @@ let # To push logs to central location ../../../common/logging/client.nix + + (import ../../../common/logging/hw-mac-retrieve.nix { hostConfig=config; }) + ( { lib, pkgs, ... }: let @@ -82,6 +86,7 @@ let # Logging client configuration logging.client.enable = config.ghaf.logging.client.enable; logging.client.endpoint = config.ghaf.logging.client.endpoint; + logging.identifierFilePath = "/tmp/MACAddress"; storagevm = { enable = true; name = "guivm";