From 1930efc6b382e8c0b94fe621b39b0ef79e8c560f Mon Sep 17 00:00:00 2001 From: buianhhuy96 Date: Thu, 12 Dec 2024 13:01:55 +0200 Subject: [PATCH] FMO-81: Merge fmo-os images into fmo-os-x86_64 - Create device-info folder containing pci device map and rugged-devices.nix for pci info of rugged devices - Create systemd service to write pci device paths into config file for microvm - Map touch device in sway via a script - Clean up tablet and laptop config file - Build targets are: + fmo-os-rugged-devices-debug / fmo-os-rugged-devices-release + fmo-os-rugged-devices-public-debug / fmo-os-rugged-devices-public-release + fmo-os-installer-debug / fmo-os-installer-release + fmo-os-installer-public-debug / fmo-os-installer-public-release Signed-off-by: Anh Huy Bui --- config-processor-hardware.nix | 3 +- flake.nix | 6 +- hardware/device-info/rugged-devices.nix | 35 ++ hardware/example.nix | 4 + ...c.nix => fmo-os-rugged-devices-public.nix} | 4 +- ...let-7230.nix => fmo-os-rugged-devices.nix} | 16 +- hardware/fmo-os-rugged-laptop-7330-public.nix | 30 -- hardware/fmo-os-rugged-laptop-7330.nix | 360 ------------------ hydrajobs/flake-module.nix | 6 +- installers/fmo-os-installer-public.nix | 5 +- installers/fmo-os-installer.nix | 7 +- modules/desktop/graphics/sway/sway.ini.nix | 12 + modules/flake-module.nix | 1 + modules/hardwareInfo/default.nix | 48 +++ modules/virtualization/microvm/vm.nix | 40 +- utils/default.nix | 2 + 16 files changed, 155 insertions(+), 424 deletions(-) create mode 100644 hardware/device-info/rugged-devices.nix rename hardware/{fmo-os-rugged-tablet-7230-public.nix => fmo-os-rugged-devices-public.nix} (87%) rename hardware/{fmo-os-rugged-tablet-7230.nix => fmo-os-rugged-devices.nix} (96%) delete mode 100644 hardware/fmo-os-rugged-laptop-7330-public.nix delete mode 100644 hardware/fmo-os-rugged-laptop-7330.nix create mode 100644 modules/hardwareInfo/default.nix diff --git a/config-processor-hardware.nix b/config-processor-hardware.nix index 7f45f3f..ffbbfe7 100644 --- a/config-processor-hardware.nix +++ b/config-processor-hardware.nix @@ -8,7 +8,7 @@ }: sysconf: let inherit (import ./utils {inherit lib self ghafOS;}) - updateAttrs updateHostConfig addCustomLaunchers addSystemPackages importvm generateFMOToolConfig; + updateAttrs updateHostConfig addHardwareInfo addCustomLaunchers addSystemPackages importvm generateFMOToolConfig; targetconf = sysconf; name = targetconf.name; @@ -48,6 +48,7 @@ let ++ (importvm targetconf.vms) ++ (updateHostConfig targetconf) ++ (generateFMOToolConfig targetconf) + ++ (if lib.hasAttr "device-info" targetconf then addHardwareInfo (import targetconf.device-info) else []) ++ (if lib.hasAttr "extraModules" targetconf then targetconf.extraModules else []); }; in { diff --git a/flake.nix b/flake.nix index ef28f07..984a94f 100644 --- a/flake.nix +++ b/flake.nix @@ -35,10 +35,8 @@ }); hwConfigs = [ - (import ./hardware/fmo-os-rugged-laptop-7330.nix) - (import ./hardware/fmo-os-rugged-laptop-7330-public.nix) - (import ./hardware/fmo-os-rugged-tablet-7230.nix) - (import ./hardware/fmo-os-rugged-tablet-7230-public.nix) + (import ./hardware/fmo-os-rugged-devices.nix) + (import ./hardware/fmo-os-rugged-devices-public.nix) ]; instConfigs = [ (import ./installers/fmo-os-installer.nix) diff --git a/hardware/device-info/rugged-devices.nix b/hardware/device-info/rugged-devices.nix new file mode 100644 index 0000000..f546170 --- /dev/null +++ b/hardware/device-info/rugged-devices.nix @@ -0,0 +1,35 @@ +# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors +# SPDX-License-Identifier: Apache-2.0 +# +# FMO PCI-device maps for rugged devices +{ + # Device information of Dell Rugged Tablet 7230 + "0BB7 Latitude 7230 Rugged Extreme Tablet" = { + touchDevices = [ + "3823:49156:EETI8082:00_0EEF:C004" + ]; + pciDevices = { + netvm = [ + "0000:00:14.3" + ]; + dockervm = []; + }; + }; + # Device information of Dell Rugged Laptop 7330 + "0A9E Latitude 7330 Rugged Extreme" = { + touchDevices = [ + "3823:49155:CUST0000:00_0EEF:C003" + ]; + pciDevices = { + netvm = [ + "0000:72:00.0" + "0000:00:1f.0" + "0000:00:1f.3" + "0000:00:1f.4" + "0000:00:1f.5" + "0000:00:1f.6" + ]; + dockervm = []; + }; + }; +} diff --git a/hardware/example.nix b/hardware/example.nix index bb0397f..bbfeb3d 100644 --- a/hardware/example.nix +++ b/hardware/example.nix @@ -13,6 +13,10 @@ "tcpdump" ]; # systemPackages + # Optional + # File containing information about VMs and pci-devices passed through + # device-info = ./device-info/rugged-devices.nix; + # VMs description vms = { # NetVM -- the network VM diff --git a/hardware/fmo-os-rugged-tablet-7230-public.nix b/hardware/fmo-os-rugged-devices-public.nix similarity index 87% rename from hardware/fmo-os-rugged-tablet-7230-public.nix rename to hardware/fmo-os-rugged-devices-public.nix index 0f8189b..3984808 100644 --- a/hardware/fmo-os-rugged-tablet-7230-public.nix +++ b/hardware/fmo-os-rugged-devices-public.nix @@ -4,8 +4,8 @@ # fmo-os-disabled-for-public -target { sysconf = { - extend = "./fmo-os-rugged-tablet-7230.nix"; - name = "fmo-os-rugged-tablet-7230-public"; + extend = "./fmo-os-rugged-devices.nix"; + name = "fmo-os-rugged-devices-public"; extraModules = [ { services = { diff --git a/hardware/fmo-os-rugged-tablet-7230.nix b/hardware/fmo-os-rugged-devices.nix similarity index 96% rename from hardware/fmo-os-rugged-tablet-7230.nix rename to hardware/fmo-os-rugged-devices.nix index 60ec39e..f83bae1 100644 --- a/hardware/fmo-os-rugged-tablet-7230.nix +++ b/hardware/fmo-os-rugged-devices.nix @@ -1,10 +1,10 @@ # Copyright 2022-2024 TII (SSRC) and the Ghaf contributors # SPDX-License-Identifier: Apache-2.0 # -# fmo-os-rugged-tablet-7230 computer -target +# fmo-os-rugged-devices computer -target { sysconf = { - name = "fmo-os-rugged-tablet-7230"; + name = "fmo-os-rugged-devices"; ipaddr = "192.168.101.2"; defaultgw = "192.168.101.1"; release = "v1.1.0a"; @@ -13,6 +13,8 @@ RAversion = "v0.8.4"; }; + device-info = ./device-info/rugged-devices.nix; + systemPackages = [ "vim" "tcpdump" @@ -65,10 +67,6 @@ ''; }; # services.udev }; # services - ghaf.graphics.sway.extraConfig = '' - # Map touch screen input to internal display - input "3823:49156:EETI8082:00_0EEF:C004" map_to_output "eDP-1" - ''; # graphics.sway } ]; # extraModules; @@ -82,11 +80,6 @@ "vim" "tcpdump" ]; # systemPackages - pciDevices = [ - { - path = "0000:00:14.3"; - } - ]; # pciDevices extraModules = [ { users.users."ghaf".extraGroups = ["networkmanager"]; @@ -240,7 +233,6 @@ "tcpdump" "gpsd" ]; # systemPackages - pciDevices = []; extraModules = [ { users.users."ghaf".extraGroups = ["docker" "dialout"]; diff --git a/hardware/fmo-os-rugged-laptop-7330-public.nix b/hardware/fmo-os-rugged-laptop-7330-public.nix deleted file mode 100644 index 66d0021..0000000 --- a/hardware/fmo-os-rugged-laptop-7330-public.nix +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors -# SPDX-License-Identifier: Apache-2.0 -# -# fmo-os-rugged-laptop-7330-public -target -{ - sysconf = { - extend = "./fmo-os-rugged-laptop-7330.nix"; - name = "fmo-os-rugged-laptop-7330-public"; - extraModules = [ - { - services = { - registration-agent-laptop = { - enable = false; - }; # services.registration-agent-laptop - }; # services - }]; # extraModules; - vms = { - dockervm = { - extraModules = [ - { - services = { - registration-agent-laptop = { - enable = false; - }; # services.registration-agent-laptop - }; # services - }]; # extraModules - }; # dockervm - }; # vms - }; # sysconf -} diff --git a/hardware/fmo-os-rugged-laptop-7330.nix b/hardware/fmo-os-rugged-laptop-7330.nix deleted file mode 100644 index 40ad3e5..0000000 --- a/hardware/fmo-os-rugged-laptop-7330.nix +++ /dev/null @@ -1,360 +0,0 @@ -# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors -# SPDX-License-Identifier: Apache-2.0 -# -# fmo-os-rugged-laptop-7330 computer -target -{ - sysconf = { - name = "fmo-os-rugged-laptop-7330"; - ipaddr = "192.168.101.2"; - defaultgw = "192.168.101.1"; - release = "v1.1.0a"; - - fmo-system = { - RAversion = "v0.8.4"; - }; - - systemPackages = [ - "vim" - "tcpdump" - "gpsd" - ]; # systemPackages - - launchers = [ - { - app = "terminal"; - } - { - app = "google-chrome"; - extraArgs = "192.168.101.11"; - } - { - app = "nmLauncher"; - extraArgs = "192.168.101.1 ghaf"; - } - ]; # launchers; - - extraModules = [ - { - # Add NVMe support into initrd to be able to boot from it - boot.initrd.availableKernelModules = [ "nvme" "ahci" ]; - - services = { - fmo-psk-distribution-service-host = { - enable = true; - }; # fmo-psk-distribution-service-host - fmo-dynamic-portforwarding-service-host = { - enable = true; - config-paths = { - netvm = "/var/netvm/netconf/dpf.config"; - }; - }; # services.dynamic-portforwarding-service - fmo-dynamic-device-passthrough-service-host = { - enable = true; - }; # services.dynamic-device-passthrough-service-host - fmo-config = { - enable = true; - }; # services.fmo-config - registration-agent-laptop = { - enable = true; - }; # services.registration-agent-laptop - udev = { - extraRules = '' - # Add usb to kvm group - SUBSYSTEM=="usb", ATTR{idVendor}=="0525", ATTR{idProduct}=="a4a2", GROUP+="kvm" - SUBSYSTEM=="usb", ATTR{idVendor}=="1546", ATTR{idProduct}=="01a9", GROUP+="kvm" - ''; - }; # services.udev - }; # services - ghaf.graphics.sway.extraConfig = '' - # Map touch screen input to internal display - input "3823:49155:CUST0000:00_0EEF:C003" map_to_output "eDP-1" - ''; # graphics.sway - } - ]; # extraModules; - - vms = { - netvm = { - enable = true; - name = "netvm"; - macaddr = "02:00:00:01:01:01"; - ipaddr = "192.168.101.1"; - systemPackages = [ - "vim" - "tcpdump" - ]; # systemPackages - pciDevices = [ - { - path = "0000:72:00.0"; - } - { - path = "0000:00:1f.0"; - } - { - path = "0000:00:1f.3"; - } - { - path = "0000:00:1f.4"; - } - { - path = "0000:00:1f.5"; - } - { - path = "0000:00:1f.6"; - } - ]; # pciDevices - extraModules = [ - { - users.users."ghaf".extraGroups = ["networkmanager"]; - networking = { - useDHCP = false; - nat = { - enable = true; - internalIPs = [ "192.168.101.0/24" ]; - }; # networking.nat - networkmanager = { - enable = true; - unmanaged = [ - "ethint0" - ]; - }; - }; # networking - systemd.network.links."10-ethint0".extraConfig = "MTUBytes=1460"; - - services = { - udev = { - extraRules = '' - # Rename network devices - SUBSYSTEM=="net", ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idProduct}=="a4a2", ATTRS{idVendor}=="0525", NAME="mesh0" - SUBSYSTEM=="net", ACTION=="add", DRIVERS=="e1000e", SUBSYSTEMS=="pci", ATTRS{vendor}=="0x8086", NAME="eth0" - ''; - }; # services.udev - - avahi = { - enable = true; - nssmdns4 = true; - reflector = true; - }; # services.avahi - - fmo-psk-distribution-service-vm = { - enable = true; - }; # services.fmo-psk-distribution-service-vm - - dynamic-portforwarding-service = { - enable = true; - ipaddress = "192.168.100.12"; - ipaddress-path = "/etc/NetworkManager/system-connections/ip-address"; - config-path = "/etc/NetworkManager/system-connections/dpf.config"; - configuration = [ - { - dip = "192.168.101.11"; - dport = "4222"; - sport = "4222"; - proto = "tcp"; - } - { - dip = "192.168.101.11"; - dport = "4222"; - sport = "4222"; - proto = "udp"; - } - { - dip = "192.168.101.11"; - dport = "7222"; - sport = "7222"; - proto = "tcp"; - } - { - dip = "192.168.101.11"; - dport = "7222"; - sport = "7222"; - proto = "udp"; - } - { - dip = "192.168.101.11"; - dport = "7422"; - sport = "7422"; - proto = "tcp"; - } - { - dip = "192.168.101.11"; - dport = "7423"; - sport = "7423"; - proto = "tcp"; - } - { - dip = "192.168.101.11"; - dport = "123"; - sport = "123"; - proto = "udp"; - } - { - dip = "192.168.101.11"; - dport = "123"; - sport = "123"; - proto = "tcp"; - } - ]; - }; # services.dynamic-portforwarding-service - }; # services - - microvm = { - volumes = [ - { - image = "/var/tmp/netvm_internal.img"; - mountPoint = "/var/lib/internal"; - size = 10240; - autoCreate = true; - fsType = "ext4"; - } - ];# microvm.volumes - - shares = [ - { - source = "/var/vms_shares/common"; - mountPoint = "/var/vms_share/common"; - tag = "common_share_netvm"; - proto = "virtiofs"; - socket = "common_share_netvm.sock"; - } - { - source = "/var/vms_shares/netvm"; - mountPoint = "/var/vms_share/host"; - tag = "netvm_share"; - proto = "virtiofs"; - socket = "netvm_share.sock"; - } - { - source = "/var/netvm/netconf"; - mountPoint = "/etc/NetworkManager/system-connections"; - tag = "netconf"; - proto = "virtiofs"; - socket = "netconf.sock"; - } - { - tag = "ssh-public-key"; - source = "/run/ssh-public-key"; - mountPoint = "/run/ssh-public-key"; - } - ]; # microvm.shares - }; # microvm - - fileSystems."/run/ssh-public-key".options = ["ro"]; - # For WLAN firmwares - hardware.enableRedistributableFirmware = true; - }]; # extraModules - }; # netvm - - dockervm = { - enable = true; - name = "dockervm"; - macaddr = "02:00:00:01:01:02"; - ipaddr = "192.168.101.11"; - defaultgw = "192.168.101.1"; - systemPackages = [ - "vim" - "tcpdump" - "gpsd" - ]; # systemPackages - pciDevices = []; - extraModules = [ - { - users.users."ghaf".extraGroups = ["docker" "dialout"]; - systemd.network.links."10-ethint0".extraConfig = "MTUBytes=1460"; - microvm = { - mem = 4096; - vcpu = 2; - volumes = [ - { - image = "/var/tmp/dockervm_internal.img"; - mountPoint = "/var/lib/internal"; - size = 10240; - autoCreate = true; - fsType = "ext4"; - } - { - image = "/var/tmp/dockervm.img"; - mountPoint = "/var/lib/docker"; - size = 51200; - autoCreate = true; - fsType = "ext4"; - } - ];# microvm.volumes - shares = [ - { - source = "/var/vms_shares/common"; - mountPoint = "/var/vms_share/common"; - tag = "common_share_dockervm"; - proto = "virtiofs"; - socket = "common_share_dockervm.sock"; - } - { - source = "/var/vms_shares/dockervm"; - mountPoint = "/var/vms_share/host"; - tag = "dockervm_share"; - proto = "virtiofs"; - socket = "dockervm_share.sock"; - } - { - source = "/var/fogdata"; - mountPoint = "/var/lib/fogdata"; - tag = "fogdatafs"; - proto = "virtiofs"; - socket = "fogdata.sock"; - } - { - tag = "ssh-public-key"; - source = "/run/ssh-public-key"; - mountPoint = "/run/ssh-public-key"; - } - ]; # microvm.shares - };# microvm - fileSystems."/run/ssh-public-key".options = ["ro"]; - services = { - fmo-hostname-service = { - enable = true; - hostname-path = "/var/lib/fogdata/hostname"; - }; # services.fmo-hostnam-service - fmo-psk-distribution-service-vm = { - enable = true; - }; # services.fmo-psk-distribution-service-vm - fmo-dynamic-device-passthrough = { - enable = true; - devices = [ - { - bus = "usb"; - vendorid = "1546"; - productid = "01a9"; - } - ]; - }; # services.fmo-dynamic-device-passthrough - fmo-dci = { - enable = true; - compose-path = "/var/lib/fogdata/docker-compose.yml"; - update-path = "/var/lib/fogdata/docker-compose.yml.new"; - backup-path = "/var/lib/fogdata/docker-compose.yml.backup"; - pat-path = "/var/lib/fogdata/PAT.pat"; - preloaded-images = "tii-offline-map-data-loader.tar.gz"; - docker-url = "cr.airoplatform.com"; - docker-url-path = "/var/lib/fogdata/cr.url"; - }; # services.fmo-dci - avahi = { - enable = true; - nssmdns4 = true; - }; # services.avahi - registration-agent-laptop = { - enable = true; - run_on_boot = true; - certs_path = "/var/lib/fogdata/certs"; - config_path = "/var/lib/fogdata"; - token_path = "/var/lib/fogdata"; - hostname_path = "/var/lib/fogdata"; - ip_path = "/var/lib/fogdata"; - post_install_path = "/var/lib/fogdata/certs"; - }; # services.registration-agent-laptop - }; # services - networking.firewall.enable = false; - }]; # extraModules - }; # dockervm - }; # vms - }; # system -} diff --git a/hydrajobs/flake-module.nix b/hydrajobs/flake-module.nix index a6fa7a1..96481f3 100644 --- a/hydrajobs/flake-module.nix +++ b/hydrajobs/flake-module.nix @@ -5,9 +5,7 @@ flake.hydraJobs = { fmo-os-installer-public-debug.x86_64-linux = self.packages.x86_64-linux.fmo-os-installer-public-debug; fmo-os-installer-public-release.x86_64-linux = self.packages.x86_64-linux.fmo-os-installer-public-release; - fmo-os-rugged-laptop-7330-public-debug.x86_64-linux = self.packages.x86_64-linux.fmo-os-rugged-laptop-7330-public-debug; - fmo-os-rugged-laptop-7330-public-release.x86_64-linux = self.packages.x86_64-linux.fmo-os-rugged-laptop-7330-public-release; - fmo-os-rugged-tablet-7230-public-debug.x86_64-linux = self.packages.x86_64-linux.fmo-os-rugged-tablet-7230-public-debug; - fmo-os-rugged-tablet-7230-public-release.x86_64-linux = self.packages.x86_64-linux.fmo-os-rugged-tablet-7230-public-release; + fmo-os-rugged-devices-public-debug.x86_64-linux = self.packages.x86_64-linux.fmo-os-rugged-devices-public-debug; + fmo-os-rugged-devices-public-release.x86_64-linux = self.packages.x86_64-linux.fmo-os-rugged-devices-public-release; }; } diff --git a/installers/fmo-os-installer-public.nix b/installers/fmo-os-installer-public.nix index 41e5e3d..f84e41c 100644 --- a/installers/fmo-os-installer-public.nix +++ b/installers/fmo-os-installer-public.nix @@ -1,7 +1,7 @@ # Copyright 2022-2024 TII (SSRC) and the Ghaf contributors # SPDX-License-Identifier: Apache-2.0 # -# FMO-OS general installer includes images for Rugged tablet and laptop without registration agent +# FMO-OS general installer includes images for FMO-OS x86_64 devices without registration agent # { # system and host description @@ -30,8 +30,7 @@ # OS to include oss = [ - "fmo-os-rugged-laptop-7330-public" - "fmo-os-rugged-tablet-7230-public" + "fmo-os-rugged-devices-public" ]; # oss }; # system } diff --git a/installers/fmo-os-installer.nix b/installers/fmo-os-installer.nix index 43e221e..f37b73f 100644 --- a/installers/fmo-os-installer.nix +++ b/installers/fmo-os-installer.nix @@ -1,13 +1,13 @@ # Copyright 2022-2024 TII (SSRC) and the Ghaf contributors # SPDX-License-Identifier: Apache-2.0 # -# FMO-OS general installer includes images for Rugged tablet and laptop +# FMO-OS general installer includes images for FMO-OS x86_64 devices # { # system and host description sysconf = { name = "fmo-os-installer"; - description = "FMO-OS general installer includes images for Rugged tablet and laptop"; + description = "FMO-OS general installer includes images for FMO-OS x86_64 devices"; systemPackages = [ "vim" ]; # systemPackages @@ -60,8 +60,7 @@ # OS to include oss = [ - "fmo-os-rugged-laptop-7330" - "fmo-os-rugged-tablet-7230" + "fmo-os-rugged-devices" ]; # oss }; # system } diff --git a/modules/desktop/graphics/sway/sway.ini.nix b/modules/desktop/graphics/sway/sway.ini.nix index b22ea27..cf27d4c 100644 --- a/modules/desktop/graphics/sway/sway.ini.nix +++ b/modules/desktop/graphics/sway/sway.ini.nix @@ -7,6 +7,17 @@ ... }: let cfg = config.ghaf.graphics.sway; + map-touch-devices = pkgs.writeShellScriptBin "map-touch-devices" '' + #${pkgs.bash}/bin/bash + while [ ! -f ${config.device.hardwareInfo.skuFile} ]; do + : + done + system_sku=$(cat ${config.device.hardwareInfo.skuFile}) + devices=$(echo '${config.device.hardwareInfo.configJson}' | ${pkgs.jq}/bin/jq -r --arg sku "$system_sku" '.[$sku].touchDevices.[]') + for device in $devices; do + swaymsg "input $device map_to_output eDP-1" + done + ''; swayConfig = pkgs.writeTextFile { name = "generated-sway-config"; @@ -18,6 +29,7 @@ output * bg ${../assets/wallpaper.jpg} fill ${builtins.readFile ./config} + exec ${map-touch-devices}/bin/map-touch-devices ''; }; in { diff --git a/modules/flake-module.nix b/modules/flake-module.nix index 577a9ad..5b8de25 100644 --- a/modules/flake-module.nix +++ b/modules/flake-module.nix @@ -19,6 +19,7 @@ ./fmo-services/host-services.nix ./profiles/x86.nix ./desktop + ./hardwareInfo ]; # fmo services/ultilities that runs only on VMs diff --git a/modules/hardwareInfo/default.nix b/modules/hardwareInfo/default.nix new file mode 100644 index 0000000..2d07b57 --- /dev/null +++ b/modules/hardwareInfo/default.nix @@ -0,0 +1,48 @@ +# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors +# SPDX-License-Identifier: Apache-2.0 +{ lib, pkgs, config, ... }: +with lib; +let + cfg = config.device.hardwareInfo; +in { + options.device.hardwareInfo = { + configJson = mkOption { + type = types.str; + description = "Device Config in JSON format"; + default = ""; + }; + skuFile = mkOption { + type = types.str; + description = "File contains SKU information generated at runtime"; + default = "/var/host/SKU"; + }; + }; + + config = mkIf (cfg.configJson != "") { + environment.systemPackages = [ pkgs.dmidecode ]; + + # Read device SKU and write in to ${skuFile} + systemd.services."device-sku" = { + script = '' + system_product_name=$(${pkgs.dmidecode}/bin/dmidecode -s system-product-name) + system_sku_number=$(${pkgs.dmidecode}/bin/dmidecode -s system-sku-number) + system_sku="$system_sku_number $system_product_name" + mkdir -p $(dirname ${cfg.skuFile}) + echo $system_sku > ${cfg.skuFile} + chmod 444 ${cfg.skuFile} + ''; + + wantedBy = ["multi-user.target"]; + before = [ + "microvms.target" + "graphical-session.target" + ]; + + # TODO: restart always + serviceConfig = { + Restart = lib.mkForce "on-failure"; + RestartSec = "5"; + }; + }; + }; +} diff --git a/modules/virtualization/microvm/vm.nix b/modules/virtualization/microvm/vm.nix index 29d4a15..c7cc38e 100644 --- a/modules/virtualization/microvm/vm.nix +++ b/modules/virtualization/microvm/vm.nix @@ -118,7 +118,7 @@ in { pciConfigPath = lib.mkOption { type = lib.types.str; description = "Path to pci-device-path file"; - default = "/etc/pciDevices/${vmconf.name}"; + default = "/var/host/pciDevices/${vmconf.name}"; }; extraModules = lib.mkOption { @@ -144,8 +144,40 @@ in { specialArgs = {inherit lib;}; }; - # Generate pci device information for passthrough - environment.etc."pciDevices/${vmconf.name}".text = - lib.concatMapStringsSep "\n" (device: "${device.path}") vmconf.pciDevices; + # Write all pci device information for passthrough + systemd.services."microvm-pci-declaration@${vmconf.name}" = { + description = "Declare MicroVM '${vmconf.name}' pci devices"; + before = [ + "install-microvm-${vmconf.name}.service" + "microvm@${vmconf.name}.service" + "microvm-tap-interfaces@${vmconf.name}.service" + "microvm-pci-devices@${vmconf.name}.service" + "microvm-virtiofsd@${vmconf.name}.service" + ]; + partOf = [ "microvm@${vmconf.name}.service" ]; + wantedBy = [ "microvms.target" ]; + # Read create source for symlink file that contains information about + # pci devices + serviceConfig.Type = "oneshot"; + script = '' + system_product_name=$(${pkgs.dmidecode}/bin/dmidecode -s system-product-name) + system_sku_number=$(${pkgs.dmidecode}/bin/dmidecode -s system-sku-number) + system_sku="$system_sku_number $system_product_name" + + mkdir -p $(dirname ${cfg.pciConfigPath}) + + devices=$(echo '${config.device.hardwareInfo.configJson}' | ${pkgs.jq}/bin/jq -r --arg sku "$system_sku" '.[$sku].pciDevices.${vmconf.name}.[]') + for device in $devices; do + if [ -f ${cfg.pciConfigPath} ]; then + assigned_devices=$(cat ${cfg.pciConfigPath}) + if [[ $assigned_devices == *$device* ]]; then + continue + fi + fi + echo "$device" >> ${cfg.pciConfigPath} + done + ''; + serviceConfig.SyslogIdentifier = "microvm-pci-declaration-${vmconf.name}"; + }; }; } diff --git a/utils/default.nix b/utils/default.nix index b609e93..2342fc5 100644 --- a/utils/default.nix +++ b/utils/default.nix @@ -9,6 +9,8 @@ addCustomLaunchers = (launchers: [{ghaf.graphics.app-launchers.enabled-launchers = launchers;}]); + addHardwareInfo = (deviceInfo: [{device.hardwareInfo.configJson = builtins.toJSON deviceInfo;}]); + importvm = (vms: (map (vm: (import ../modules/virtualization/microvm/vm.nix {inherit ghafOS self; vmconf=vms.${vm};}) ) (builtins.attrNames vms))); generateFMOToolConfig = (import ./fmo-tools/fmo-hyper-module-list.nix);