Skip to content

Commit

Permalink
Introduce fmo-tool
Browse files Browse the repository at this point in the history
- Create fmo-tool service for default config
- Add dynamic-device-passthrough and dynamic-portforwarding services
- Add fmo-tool package
- Add vhotplug package for dynamic-device-passthrough

Signed-off-by: Anh Huy Bui <buianhhuy96@gmail.com>
  • Loading branch information
buianhhuy96 committed Oct 2, 2024
1 parent c01baf8 commit 26c2004
Show file tree
Hide file tree
Showing 21 changed files with 645 additions and 42 deletions.
16 changes: 5 additions & 11 deletions config-processor-hardware.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,9 @@
nixos-hardware,
nixpkgs,
microvm,
}: {
sysconf,
}:
}: sysconf:
let
updateAttrs = (import ./utils/updateAttrs.nix).updateAttrs;
updateHostConfig = (import ./utils/updateHostConfig.nix).updateHostConfig;

targetconf = if lib.hasAttr "extend" sysconf
then updateAttrs false (import (lib.path.append ./hardware sysconf.extend) ).sysconf sysconf
else sysconf;

targetconf = sysconf;
name = targetconf.name;
system = "x86_64-linux";
vms = targetconf.vms;
Expand All @@ -33,6 +25,7 @@ let
};
addSystemPackages = {pkgs, ...}: {environment.systemPackages = map (app: pkgs.${app}) targetconf.systemPackages;};
addCustomLaunchers = { ghaf.graphics.app-launchers.enabled-launchers = targetconf.launchers; };
updateHostConfig = (import ./utils/updateHostConfig.nix).updateHostConfig;

formatModule = nixos-generators.nixosModules.raw-efi;
target = variant: extraModules: let
Expand Down Expand Up @@ -82,7 +75,8 @@ let
++ (import "${ghafOS}/modules/module-list.nix")
++ (import ./modules/fmo-module-list.nix)
++ extraModules
++ (if lib.hasAttr "extraModules" targetconf then targetconf.extraModules else []);
++ (if lib.hasAttr "extraModules" targetconf then targetconf.extraModules else [])
++ (import ./modules/fmo-tools/fmo-hyper-module-list.nix {inherit targetconf;});
};
in {
inherit hostConfiguration;
Expand Down
12 changes: 3 additions & 9 deletions config-processor-installers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@
nixos-hardware,
nixpkgs,
microvm,
}: {
sysconf,
}:
}: sysconf:
let
updateAttrs = (import ./utils/updateAttrs.nix).updateAttrs;

oss = sysconf.oss;
oss_list_name = "installer_os_list";
oss_list_path = "/etc/${oss_list_name}";

installerconf = if lib.hasAttr "extend" sysconf
then updateAttrs false (import (lib.path.append ./installers sysconf.extend) ).sysconf sysconf
else sysconf;

installerconf = sysconf;

installerApp = inst_app: let
installers = (builtins.removeAttrs inst_app ["name"]) //
Expand Down Expand Up @@ -74,7 +68,7 @@ let
addSystemPackages

{
isoImage.squashfsCompression = "lz4";
isoImage.squashfsCompression = "lz4";
}
]
++ (import ./modules/fmo-module-list.nix)
Expand Down
30 changes: 17 additions & 13 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
nixos-generators = ghafOS.inputs.nixos-generators;
nixos-hardware = ghafOS.inputs.nixos-hardware;
microvm = ghafOS.inputs.microvm;

systems = with flake-utils.lib.system; [
x86_64-linux
];
Expand All @@ -39,7 +38,21 @@
lib = final;
};
});


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)
];
instConfigs = [
(import ./installers/fmo-os-installer.nix)
(import ./installers/fmo-os-installer-public.nix)
];
updateAttrs = (import ./utils/updateAttrs.nix).updateAttrs;
inheritConfig = confPath: { sysconf }: if lib.hasAttr "extend" sysconf
then updateAttrs false (import (lib.path.append confPath sysconf.extend) ).sysconf sysconf
else sysconf;
generateHwConfig = import ./config-processor-hardware.nix {inherit nixpkgs ghafOS self nixos-hardware nixos-generators lib microvm;};
generateInstConfig = import ./config-processor-installers.nix {inherit nixpkgs ghafOS self nixos-hardware nixos-generators lib microvm;};
in
Expand All @@ -63,15 +76,6 @@

formatter = pkgs.alejandra;
}))
]
++ map generateHwConfig [
(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)
]
++ map generateInstConfig [
(import ./installers/fmo-os-installer.nix)
(import ./installers/fmo-os-installer-public.nix)
]);
] ++ map generateHwConfig (map (conf: inheritConfig ./hardware conf) hwConfigs)
++ map generateInstConfig (map (conf: inheritConfig ./installers conf) instConfigs));
}
37 changes: 32 additions & 5 deletions hardware/fmo-os-rugged-laptop-7330.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
name = "fmo-os-rugged-laptop-7330";
ipaddr = "192.168.101.2";
defaultgw = "192.168.101.1";
release = "v1.0.0a";

fmo-system = {
RAversion = "v0.8.4";
};
systemPackages = [
"vim"
"tcpdump"
Expand Down Expand Up @@ -36,8 +40,20 @@

services = {
fmo-psk-distribution-service-host = {
enable = true;
};
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;
}; # fmo-config
registration-agent-laptop = {
enable = true;
}; # services.registration-agent-laptop
Expand Down Expand Up @@ -100,12 +116,13 @@

fmo-psk-distribution-service-vm = {
enable = true;
};
}; # fmo-psk-distribution-service-vm

portforwarding-service = {
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";
Expand Down Expand Up @@ -156,7 +173,7 @@
proto = "tcp";
}
];
}; # services.portforwarding-service;
}; # services.dynamic-portforwarding-service
}; # services

microvm = {
Expand Down Expand Up @@ -264,6 +281,16 @@
enable = true;
hostname-path = "/var/lib/fogdata/hostname";
}; # services.fmo-hostnam-service
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";
Expand Down
35 changes: 31 additions & 4 deletions hardware/fmo-os-rugged-tablet-7230.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
name = "fmo-os-rugged-tablet-7230";
ipaddr = "192.168.101.2";
defaultgw = "192.168.101.1";
release = "v1.0.0a";

fmo-system = {
RAversion = "v0.8.4";
};
systemPackages = [
"vim"
"tcpdump"
Expand Down Expand Up @@ -36,8 +40,20 @@

services = {
fmo-psk-distribution-service-host = {
enable = true;
enable = true;
}; # services.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;
}; # fmo-config
registration-agent-laptop = {
enable = true;
}; # services.registration-agent-laptop
Expand Down Expand Up @@ -100,12 +116,13 @@

fmo-psk-distribution-service-vm = {
enable = true;
};
}; # fmo-psk-distribution-service-vm

portforwarding-service = {
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";
Expand Down Expand Up @@ -156,7 +173,7 @@
proto = "tcp";
}
];
}; # services.portforwarding-service;
}; # services.dynamic-portforwarding-service
}; # services

microvm = {
Expand Down Expand Up @@ -244,6 +261,16 @@
enable = true;
hostname-path = "/var/lib/fogdata/hostname";
}; # services.fmo-hostnam-service
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";
Expand Down
2 changes: 2 additions & 0 deletions modules/custom-packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ _: {
(import ./squeekboard)
(import ./sway-scripts)
(import ./terminator)
(import ./fmo-tool)
(import ./vhotplug)
];
}
6 changes: 6 additions & 0 deletions modules/custom-packages/fmo-tool/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
(final: _prev: {
fmo-tool = _prev.callPackage ./fmo-tool.nix {};
typer = _prev.callPackage ./typer.nix {};
})
49 changes: 49 additions & 0 deletions modules/custom-packages/fmo-tool/fmo-tool.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{ pkgs }:
let
# WAR: This is because current typer and paramiko dependencies are old versions,
# Solve by manually build newer versions of the packages
# Will be remove in new version of nixpkgs (with pkgs.python3Packages)
typer = pkgs.callPackage ./typer.nix {};
paramiko = pkgs.callPackage ./paramiko.nix {};
in

pkgs.python3Packages.buildPythonApplication {
pname = "fmo-tool";
version = "0.0.1";

build-system = with pkgs.python3Packages; [
setuptools
wheel
];

dependencies = with pkgs.python3Packages; [
typer
colorama
shellingham
pytest
typing-extensions
pyyaml
paramiko
# py3compat
rich
];

propagatedBuildInputs = with pkgs.python3Packages; [
(pkgs.python3.withPackages (ps: with ps; [ pip ]))
typer
colorama
shellingham
pytest
typing-extensions
pyyaml
paramiko
# py3compat
rich
];

src = builtins.fetchGit {
url = "git@github.com:tiiuae/fmo-tool.git";
rev = "40ca851d4f51af7ecf48939394609c6520b5d549";
ref = "refs/heads/integrate_ddp";
};
}
Loading

0 comments on commit 26c2004

Please sign in to comment.