From 093e21da5d3f25d54dfbfe5a647a4512732b22f9 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 --- flake.lock | 8 +-- flake.nix | 2 +- 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 ++ 6 files changed, 69 insertions(+), 9 deletions(-) diff --git a/flake.lock b/flake.lock index 26330790a..404947b9a 100644 --- a/flake.lock +++ b/flake.lock @@ -50,17 +50,17 @@ ] }, "locked": { - "lastModified": 1731669088, - "narHash": "sha256-D95Q0Q6fbrTOcvgwctBAvL23oZItoheXjQGXbBwYLWc=", + "lastModified": 1733993653, + "narHash": "sha256-T4AecFbphXdQ+GmegXjdaYSUaDTp81Htth82BxPBVz4=", "owner": "tiiuae", "repo": "ghaf-ctrl-panel", - "rev": "5ca381ba51c05cf370299056f6e377cd6003283f", + "rev": "de341ebfc797ce2e1783cd7b2fc1e083c5fb8347", "type": "github" }, "original": { "owner": "tiiuae", "repo": "ghaf-ctrl-panel", - "rev": "5ca381ba51c05cf370299056f6e377cd6003283f", + "rev": "de341ebfc797ce2e1783cd7b2fc1e083c5fb8347", "type": "github" } }, diff --git a/flake.nix b/flake.nix index c30670bfa..46dc5b5f4 100644 --- a/flake.nix +++ b/flake.nix @@ -156,7 +156,7 @@ }; ctrl-panel = { - url = "github:tiiuae/ghaf-ctrl-panel/5ca381ba51c05cf370299056f6e377cd6003283f"; + url = "github:tiiuae/ghaf-ctrl-panel/de341ebfc797ce2e1783cd7b2fc1e083c5fb8347"; inputs = { nixpkgs.follows = "nixpkgs"; flake-utils.follows = "flake-utils"; 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..ca0c171e0 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"; @@ -185,6 +190,31 @@ let }; }; + systemd.user.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 = [ "ewwbar.service" ]; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + StandardOutput = "journal"; + StandardError = "journal"; + ExecStart = "${configScript}/bin/github-config"; + }; + }; + environment = { systemPackages = (rmDesktopEntries [ @@ -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 = {