diff --git a/pkgs/clan-app/ui-2d/src/queries/clan-meta.ts b/pkgs/clan-app/ui-2d/src/queries/clan-meta.ts index e71790182..1562bd997 100644 --- a/pkgs/clan-app/ui-2d/src/queries/clan-meta.ts +++ b/pkgs/clan-app/ui-2d/src/queries/clan-meta.ts @@ -13,7 +13,7 @@ export const clanMetaQuery = (uri: string | undefined = undefined) => queryFn: async () => { console.log("fetching clan meta", clanURI); - const result = await callApi("show_clan_meta", { + const result = await callApi("get_clan_details", { flake: { identifier: clanURI! }, }).promise; diff --git a/pkgs/clan-app/ui-2d/src/routes/clans/create.tsx b/pkgs/clan-app/ui-2d/src/routes/clans/create.tsx index ea82a0e74..f732499bc 100644 --- a/pkgs/clan-app/ui-2d/src/routes/clans/create.tsx +++ b/pkgs/clan-app/ui-2d/src/routes/clans/create.tsx @@ -203,6 +203,6 @@ export const CreateClan = () => { }; type Meta = Extract< - OperationResponse<"show_clan_meta">, + OperationResponse<"get_clan_details">, { status: "success" } >["data"]; diff --git a/pkgs/clan-app/ui-2d/src/routes/clans/details.tsx b/pkgs/clan-app/ui-2d/src/routes/clans/details.tsx index f087b70a3..7ef28306c 100644 --- a/pkgs/clan-app/ui-2d/src/routes/clans/details.tsx +++ b/pkgs/clan-app/ui-2d/src/routes/clans/details.tsx @@ -128,7 +128,7 @@ const EditClanForm = (props: EditClanFormProps) => { ); }; -type GeneralData = SuccessQuery<"show_clan_meta">["data"]; +type GeneralData = SuccessQuery<"get_clan_details">["data"]; export const ClanDetails = () => { const params = useParams(); diff --git a/pkgs/clan-app/ui-2d/src/routes/flash/view.tsx b/pkgs/clan-app/ui-2d/src/routes/flash/view.tsx index 7bea3a960..e99b5ce93 100644 --- a/pkgs/clan-app/ui-2d/src/routes/flash/view.tsx +++ b/pkgs/clan-app/ui-2d/src/routes/flash/view.tsx @@ -100,7 +100,7 @@ export const Flash = () => { const deviceQuery = createQuery(() => ({ queryKey: ["block_devices"], queryFn: async () => { - const result = await callApi("show_block_devices", {}).promise; + const result = await callApi("list_block_devices", {}).promise; if (result.status === "error") throw new Error("Failed to fetch data"); return result.data; }, diff --git a/pkgs/clan-app/ui/src/queries/clan-meta.ts b/pkgs/clan-app/ui/src/queries/clan-meta.ts index e71790182..1562bd997 100644 --- a/pkgs/clan-app/ui/src/queries/clan-meta.ts +++ b/pkgs/clan-app/ui/src/queries/clan-meta.ts @@ -13,7 +13,7 @@ export const clanMetaQuery = (uri: string | undefined = undefined) => queryFn: async () => { console.log("fetching clan meta", clanURI); - const result = await callApi("show_clan_meta", { + const result = await callApi("get_clan_details", { flake: { identifier: clanURI! }, }).promise; diff --git a/pkgs/clan-app/ui/src/routes/clans/create.tsx b/pkgs/clan-app/ui/src/routes/clans/create.tsx index 92cac1f65..1071f7084 100644 --- a/pkgs/clan-app/ui/src/routes/clans/create.tsx +++ b/pkgs/clan-app/ui/src/routes/clans/create.tsx @@ -202,6 +202,6 @@ export const CreateClan = () => { }; type Meta = Extract< - OperationResponse<"show_clan_meta">, + OperationResponse<"get_clan_details">, { status: "success" } >["data"]; diff --git a/pkgs/clan-app/ui/src/routes/clans/details.tsx b/pkgs/clan-app/ui/src/routes/clans/details.tsx index f087b70a3..7ef28306c 100644 --- a/pkgs/clan-app/ui/src/routes/clans/details.tsx +++ b/pkgs/clan-app/ui/src/routes/clans/details.tsx @@ -128,7 +128,7 @@ const EditClanForm = (props: EditClanFormProps) => { ); }; -type GeneralData = SuccessQuery<"show_clan_meta">["data"]; +type GeneralData = SuccessQuery<"get_clan_details">["data"]; export const ClanDetails = () => { const params = useParams(); diff --git a/pkgs/clan-cli/clan_cli/clan/show.py b/pkgs/clan-cli/clan_cli/clan/show.py index 0af6b599e..1b7e0beac 100644 --- a/pkgs/clan-cli/clan_cli/clan/show.py +++ b/pkgs/clan-cli/clan_cli/clan/show.py @@ -1,14 +1,14 @@ import argparse import logging -from clan_lib.clan.get import show_clan_meta +from clan_lib.clan.get import get_clan_details log = logging.getLogger(__name__) def show_command(args: argparse.Namespace) -> None: flake_path = args.flake.path - meta = show_clan_meta(flake_path) + meta = get_clan_details(flake_path) print(f"Name: {meta.get('name')}") print(f"Description: {meta.get('description', '-')}") diff --git a/pkgs/clan-cli/clan_lib/api/directory.py b/pkgs/clan-cli/clan_lib/api/directory.py index f87c46b42..af533eaeb 100644 --- a/pkgs/clan-cli/clan_lib/api/directory.py +++ b/pkgs/clan-cli/clan_lib/api/directory.py @@ -122,7 +122,7 @@ def blk_from_dict(data: dict) -> BlkInfo: @API.register -def show_block_devices() -> Blockdevices: +def list_block_devices() -> Blockdevices: """ Api method to show local block devices. diff --git a/pkgs/clan-cli/clan_lib/clan/get.py b/pkgs/clan-cli/clan_lib/clan/get.py index 3b8c58ef8..5fb43f31d 100644 --- a/pkgs/clan-cli/clan_lib/clan/get.py +++ b/pkgs/clan-cli/clan_lib/clan/get.py @@ -1,12 +1,12 @@ from clan_lib.api import API from clan_lib.errors import ClanError from clan_lib.flake import Flake -from clan_lib.nix_models.clan import InventoryMeta as Meta +from clan_lib.nix_models.clan import InventoryMeta from clan_lib.persist.inventory_store import InventoryStore @API.register -def show_clan_meta(flake: Flake) -> Meta: +def get_clan_details(flake: Flake) -> InventoryMeta: if flake.is_local and not flake.path.exists(): msg = f"Path {flake} does not exist" raise ClanError(msg, description="clan directory does not exist") diff --git a/templates/clan/flake-parts/clan.nix b/templates/clan/flake-parts/clan.nix new file mode 100644 index 000000000..a29e89894 --- /dev/null +++ b/templates/clan/flake-parts/clan.nix @@ -0,0 +1,81 @@ +{ self }: +{ + meta.name = "__CHANGE_ME__"; # Ensure this is unique among all clans you want to use. + + inherit self; + machines = { + # "jon" will be the hostname of the machine + jon = + { pkgs, ... }: + { + imports = [ + ./modules/shared.nix + ./modules/disko.nix + ./machines/jon/configuration.nix + ]; + + nixpkgs.hostPlatform = "x86_64-linux"; + + # Set this for clan commands use ssh i.e. `clan machines update` + # If you change the hostname, you need to update this line to root@ + # This only works however if you have avahi running on your admin machine else use IP + clan.core.networking.targetHost = pkgs.lib.mkDefault "root@jon"; + + # You can get your disk id by running the following command on the installer: + # Replace with the IP of the installer printed on the screen or by running the `ip addr` command. + # ssh root@ lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT + disko.devices.disk.main = { + device = "/dev/disk/by-id/__CHANGE_ME__"; + }; + + # IMPORTANT! Add your SSH key here + # e.g. > cat ~/.ssh/id_ed25519.pub + users.users.root.openssh.authorizedKeys.keys = throw '' + Don't forget to add your SSH key here! + users.users.root.openssh.authorizedKeys.keys = [ "" ] + ''; + + # Zerotier needs one controller to accept new nodes. Once accepted + # the controller can be offline and routing still works. + clan.core.networking.zerotier.controller.enable = true; + }; + # "sara" will be the hostname of the machine + sara = + { pkgs, ... }: + { + imports = [ + ./modules/shared.nix + ./modules/disko.nix + ./machines/sara/configuration.nix + ]; + + nixpkgs.hostPlatform = "x86_64-linux"; + + # Set this for clan commands use ssh i.e. `clan machines update` + # If you change the hostname, you need to update this line to root@ + # This only works however if you have avahi running on your admin machine else use IP + clan.core.networking.targetHost = pkgs.lib.mkDefault "root@sara"; + + # You can get your disk id by running the following command on the installer: + # Replace with the IP of the installer printed on the screen or by running the `ip addr` command. + # ssh root@ lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT + disko.devices.disk.main = { + device = "/dev/disk/by-id/__CHANGE_ME__"; + }; + + # IMPORTANT! Add your SSH key here + # e.g. > cat ~/.ssh/id_ed25519.pub + users.users.root.openssh.authorizedKeys.keys = throw '' + Don't forget to add your SSH key here! + users.users.root.openssh.authorizedKeys.keys = [ "" ] + ''; + + /* + After jon is deployed, uncomment the following line + This will allow sara to share the VPN overlay network with jon + The networkId is generated by the first deployment of jon + */ + # clan.core.networking.zerotier.networkId = builtins.readFile ../../vars/per-machine/jon/zerotier/zerotier-network-id/value; + }; + }; +} diff --git a/templates/clan/flake-parts/flake.nix b/templates/clan/flake-parts/flake.nix index 2d61576bc..340c9b2a2 100644 --- a/templates/clan/flake-parts/flake.nix +++ b/templates/clan/flake-parts/flake.nix @@ -17,88 +17,13 @@ "x86_64-darwin" "aarch64-darwin" ]; - imports = [ inputs.clan-core.flakeModules.default ]; + imports = [ + inputs.clan-core.flakeModules.default + ]; + # https://docs.clan.lol/guides/getting-started/flake-parts/ - clan = { - meta.name = "__CHANGE_ME__"; # Ensure this is unique among all clans you want to use. + clan = import ./clan.nix { inherit self; }; - inherit self; - machines = { - # "jon" will be the hostname of the machine - jon = - { pkgs, ... }: - { - imports = [ - ./modules/shared.nix - ./modules/disko.nix - ./machines/jon/configuration.nix - ]; - - nixpkgs.hostPlatform = "x86_64-linux"; - - # Set this for clan commands use ssh i.e. `clan machines update` - # If you change the hostname, you need to update this line to root@ - # This only works however if you have avahi running on your admin machine else use IP - clan.core.networking.targetHost = pkgs.lib.mkDefault "root@jon"; - - # You can get your disk id by running the following command on the installer: - # Replace with the IP of the installer printed on the screen or by running the `ip addr` command. - # ssh root@ lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT - disko.devices.disk.main = { - device = "/dev/disk/by-id/__CHANGE_ME__"; - }; - - # IMPORTANT! Add your SSH key here - # e.g. > cat ~/.ssh/id_ed25519.pub - users.users.root.openssh.authorizedKeys.keys = throw '' - Don't forget to add your SSH key here! - users.users.root.openssh.authorizedKeys.keys = [ "" ] - ''; - - # Zerotier needs one controller to accept new nodes. Once accepted - # the controller can be offline and routing still works. - clan.core.networking.zerotier.controller.enable = true; - }; - # "sara" will be the hostname of the machine - sara = - { pkgs, ... }: - { - imports = [ - ./modules/shared.nix - ./modules/disko.nix - ./machines/sara/configuration.nix - ]; - - nixpkgs.hostPlatform = "x86_64-linux"; - - # Set this for clan commands use ssh i.e. `clan machines update` - # If you change the hostname, you need to update this line to root@ - # This only works however if you have avahi running on your admin machine else use IP - clan.core.networking.targetHost = pkgs.lib.mkDefault "root@sara"; - - # You can get your disk id by running the following command on the installer: - # Replace with the IP of the installer printed on the screen or by running the `ip addr` command. - # ssh root@ lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT - disko.devices.disk.main = { - device = "/dev/disk/by-id/__CHANGE_ME__"; - }; - - # IMPORTANT! Add your SSH key here - # e.g. > cat ~/.ssh/id_ed25519.pub - users.users.root.openssh.authorizedKeys.keys = throw '' - Don't forget to add your SSH key here! - users.users.root.openssh.authorizedKeys.keys = [ "" ] - ''; - - /* - After jon is deployed, uncomment the following line - This will allow sara to share the VPN overlay network with jon - The networkId is generated by the first deployment of jon - */ - # clan.core.networking.zerotier.networkId = builtins.readFile ../../vars/per-machine/jon/zerotier/zerotier-network-id/value; - }; - }; - }; perSystem = { pkgs, inputs', ... }: {