Skip to content

Commit

Permalink
Add MAC address sharing for GUIVM
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerox9 committed Dec 10, 2024
1 parent 8938072 commit f41d773
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions modules/common/logging/hw-mac-retrieve.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{ hostConfig }:
{
config,
lib,
Expand All @@ -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.
Expand All @@ -28,15 +29,15 @@ 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";
RemainAfterExit = "yes";
# 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";
Expand Down
2 changes: 1 addition & 1 deletion modules/microvm/virtualization/microvm/adminvm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand Down
5 changes: 5 additions & 0 deletions modules/microvm/virtualization/microvm/guivm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit f41d773

Please sign in to comment.