diff --git a/lib/build-clan/default.nix b/lib/build-clan/default.nix index a2680c52..9625689d 100644 --- a/lib/build-clan/default.nix +++ b/lib/build-clan/default.nix @@ -41,12 +41,10 @@ let clan-core.nixosModules.clanCore (machines.${name} or { }) { - clanCore.machineName = name; clanCore.clanName = clanName; clanCore.clanIcon = clanIcon; clanCore.clanDir = directory; - clanCore.machineIcon = clanIcon; - clanCore.machineDescription = null; + clanCore.machineName = name; nixpkgs.hostPlatform = if forceSystem then lib.mkForce system else lib.mkDefault system; # speeds up nix commands by using the nixpkgs from the host system (especially useful in VMs) diff --git a/nixosModules/clanCore/metadata.nix b/nixosModules/clanCore/metadata.nix index b9a968e0..391f32b8 100644 --- a/nixosModules/clanCore/metadata.nix +++ b/nixosModules/clanCore/metadata.nix @@ -8,12 +8,14 @@ }; machineIcon = lib.mkOption { type = lib.types.nullOr lib.types.path; + default = null; description = '' the location of the machine icon ''; }; machineDescription = lib.mkOption { - type = lib.types.str; + type = lib.types.nullOr lib.types.str; + default = null; description = '' the description of the machine ''; diff --git a/nixosModules/clanCore/vm.nix b/nixosModules/clanCore/vm.nix index f9fdc7e2..2dcd3ddd 100644 --- a/nixosModules/clanCore/vm.nix +++ b/nixosModules/clanCore/vm.nix @@ -172,6 +172,30 @@ in whether to enable native wayland window passthrough with waypipe for the vm ''; }; + machine_icon = lib.mkOption { + type = lib.types.nullOr lib.types.path; + internal = true; + readOnly = true; + description = '' + the location of the clan icon + ''; + }; + machine_name = lib.mkOption { + type = lib.types.str; + internal = true; + readOnly = true; + description = '' + the name of the vm + ''; + }; + machine_description = lib.mkOption { + type = lib.types.nullOr lib.types.str; + internal = true; + readOnly = true; + description = '' + the description of the vm + ''; + }; }; }; @@ -179,6 +203,9 @@ in # for clan vm inspect clanCore.vm.inspect = { clan_name = config.clanCore.clanName; + machine_icon = config.clanCore.machineIcon or config.clanCore.clanIcon; + machine_name = config.clanCore.machineName; + machine_description = config.clanCore.machineDescription; memory_size = config.clan.virtualisation.memorySize; inherit (config.clan.virtualisation) cores graphics waypipe; }; diff --git a/pkgs/clan-cli/clan_cli/flakes/inspect.py b/pkgs/clan-cli/clan_cli/flakes/inspect.py index 8578d187..f5e34127 100644 --- a/pkgs/clan-cli/clan_cli/flakes/inspect.py +++ b/pkgs/clan-cli/clan_cli/flakes/inspect.py @@ -7,7 +7,7 @@ from ..dirs import machine_gcroot from ..errors import ClanError from ..machines.list import list_machines from ..machines.machines import Machine -from ..nix import nix_build, nix_config, nix_eval, nix_metadata +from ..nix import nix_add_to_gcroots, nix_build, nix_config, nix_eval, nix_metadata from ..vms.inspect import VmConfig, inspect_vm @@ -44,6 +44,14 @@ def inspect_flake(flake_url: str | Path, machine_name: str) -> FlakeConfig: machine = Machine(machine_name, flake_url) vm = inspect_vm(machine) + # Make symlink to gcroots from vm.machine_icon + if vm.machine_icon: + gcroot_icon: Path = ( + machine_gcroot(clan_name=vm.clan_name, flake_url=str(flake_url)) + / vm.machine_name + ) + nix_add_to_gcroots(vm.machine_icon, gcroot_icon) + # Get the cLAN name cmd = nix_eval( [ diff --git a/pkgs/clan-cli/clan_cli/nix.py b/pkgs/clan-cli/clan_cli/nix.py index a8672c40..e922fd5e 100644 --- a/pkgs/clan-cli/clan_cli/nix.py +++ b/pkgs/clan-cli/clan_cli/nix.py @@ -53,6 +53,11 @@ def nix_build(flags: list[str], gcroot: Path | None = None) -> list[str]: ) +def nix_add_to_gcroots(nix_path: Path, dest: Path) -> None: + cmd = ["nix-store", "--realise", f"{nix_path}", "--add-root", f"{dest}"] + run(cmd) + + def nix_config() -> dict[str, Any]: cmd = nix_command(["show-config", "--json"]) proc = run(cmd) diff --git a/pkgs/clan-cli/clan_cli/vms/inspect.py b/pkgs/clan-cli/clan_cli/vms/inspect.py index 9e3804fd..cb70b758 100644 --- a/pkgs/clan-cli/clan_cli/vms/inspect.py +++ b/pkgs/clan-cli/clan_cli/vms/inspect.py @@ -9,6 +9,8 @@ from ..machines.machines import Machine @dataclass class VmConfig: machine_name: str + machine_icon: Path + machine_description: str flake_url: str | Path clan_name: str @@ -20,7 +22,7 @@ class VmConfig: def inspect_vm(machine: Machine) -> VmConfig: data = json.loads(machine.eval_nix("config.clanCore.vm.inspect")) - return VmConfig(machine_name=machine.name, flake_url=machine.flake, **data) + return VmConfig(flake_url=machine.flake, **data) @dataclass