Skip to content

Commit

Permalink
Add MAC address sharing for GUIVM
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Nerox9 committed Dec 12, 2024
1 parent 6ac9d7e commit 093e21d
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 9 deletions.
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
9 changes: 7 additions & 2 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 Down Expand Up @@ -28,15 +29,19 @@ 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";
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
54 changes: 53 additions & 1 deletion 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 @@ -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";
Expand Down Expand Up @@ -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 [
Expand All @@ -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)
Expand All @@ -212,6 +244,7 @@ let
sessionVariables = {
XDG_PICTURES_DIR = "$HOME/Pictures";
XDG_VIDEOS_DIR = "$HOME/Videos";
GITHUB_CONFIG = "$HOME/.config/ctrl-panel/config.toml";
};
};

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions modules/reference/profiles/laptop-x86.nix
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ in
guivm = {
enable = true;
extraModules = cfg.guivmExtraModules;
githubToken = "xxxxxxxxxxxxxxxxxxxx";
githubOwner = "yyyyy";
githubRepo = "zzzzzz";
};

audiovm = {
Expand Down

0 comments on commit 093e21d

Please sign in to comment.