From abdad320fc889fbf05e62b7fc3ba128bf252a4ca Mon Sep 17 00:00:00 2001 From: Berk Arslan Date: Wed, 11 Dec 2024 16:04:30 +0200 Subject: [PATCH] Add MAC address sharing for GUIVM Add report page into control panel MAC address shared with GUIVM Report page is added into settings of control panel Github configuration is added to submit a report Signed-off-by: Berk Arslan --- modules/common/logging/hw-mac-retrieve.nix | 9 +++- .../virtualization/microvm/adminvm.nix | 2 +- .../microvm/virtualization/microvm/guivm.nix | 54 ++++++++++++++++++- modules/reference/profiles/laptop-x86.nix | 3 ++ 4 files changed, 64 insertions(+), 4 deletions(-) diff --git a/modules/common/logging/hw-mac-retrieve.nix b/modules/common/logging/hw-mac-retrieve.nix index 82cc8863c..73927b6b2 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, @@ -28,7 +29,11 @@ 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 + [ "multi-user.target" ] + else + [ "alloy.service" ]; requires = [ "network-online.target" ]; serviceConfig = { Type = "oneshot"; @@ -36,7 +41,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..4088a17df 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 9dd1759d5..6949bf6db 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 @@ -106,6 +110,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"; @@ -183,6 +188,31 @@ let StandardError = "journal"; ExecStart = "${keygenScript}/bin/waypipe-ssh-keygen"; }; + }; + + systemd.services."github-config" = + let + configScript = pkgs.writeShellScriptBin "github-config" '' + mkdir -p "$HOME"/.config/ctrl-panel + cat > "$HOME"/.config/ctrl-panel/config.toml << EOF + token = "${cfg.githubToken}" + owner = "${cfg.githubOwner}" + repo = "${cfg.githubRepo}" + EOF + ''; + in + { + enable = true; + description = "Generate Github configuration file for Ghaf Control Panel"; + path = [ configScript ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + StandardOutput = "journal"; + StandardError = "journal"; + ExecStart = "${configScript}/bin/github-config"; + }; }; environment = { @@ -199,7 +229,9 @@ let pkgs.eww pkgs.wlr-randr ] - ++ [ pkgs.ctrl-panel ] + ++ [ + pkgs.ctrl-panel + ] ++ (lib.optional ( config.ghaf.profiles.debug.enable && config.ghaf.virtualization.microvm.idsvm.mitmproxy.enable ) pkgs.mitmweb-ui) @@ -212,6 +244,7 @@ let sessionVariables = { XDG_PICTURES_DIR = "$HOME/Pictures"; XDG_VIDEOS_DIR = "$HOME/Videos"; + GITHUB_CONFIG = "$HOME/.config/ctrl-panel/config.toml"; }; }; @@ -358,6 +391,25 @@ in ); default = [ ]; }; + + githubOwner = lib.mkOption { + type = lib.types.str; + description = '' + Github owner account of the bug reporter issue + ''; + }; + githubRepo = lib.mkOption { + type = lib.types.str; + description = '' + Github repo of the bug reporter issue + ''; + }; + githubToken = lib.mkOption { + type = lib.types.str; + description = '' + Personal token of the bug reporter Github account + ''; + }; }; config = lib.mkIf cfg.enable { diff --git a/modules/reference/profiles/laptop-x86.nix b/modules/reference/profiles/laptop-x86.nix index 0d97c423d..708375f67 100644 --- a/modules/reference/profiles/laptop-x86.nix +++ b/modules/reference/profiles/laptop-x86.nix @@ -95,6 +95,9 @@ in guivm = { enable = true; extraModules = cfg.guivmExtraModules; + githubToken = "xxxxxxxxxxxxxxxxxxxx"; + githubOwner = "yyyyy"; + githubRepo = "zzzzzz"; }; audiovm = {