diff --git a/pkgs/clan-cli/clan_cli/machines/create.py b/pkgs/clan-cli/clan_cli/machines/create.py index 3155b2d6a..3ee7a5233 100644 --- a/pkgs/clan-cli/clan_cli/machines/create.py +++ b/pkgs/clan-cli/clan_cli/machines/create.py @@ -16,9 +16,9 @@ from clan_lib.persist.util import set_value_by_path from clan_lib.templates import ( InputPrio, TemplateName, - copy_from_nixstore, get_template, ) +from clan_lib.templates.filesystem import copy_from_nixstore from clan_cli.completions import add_dynamic_completer, complete_tags from clan_cli.machines.list import list_full_machines diff --git a/pkgs/clan-cli/clan_cli/tests/test_clan_nix_attrset.py b/pkgs/clan-cli/clan_cli/tests/test_clan_nix_attrset.py index a732c69f9..8cda0d002 100644 --- a/pkgs/clan-cli/clan_cli/tests/test_clan_nix_attrset.py +++ b/pkgs/clan-cli/clan_cli/tests/test_clan_nix_attrset.py @@ -15,11 +15,11 @@ from clan_lib.templates import ( ClanExports, InputName, TemplateName, - copy_from_nixstore, get_clan_nix_attrset, get_template, list_templates, ) +from clan_lib.templates.filesystem import copy_from_nixstore # Function to write clan attributes to a file diff --git a/pkgs/clan-cli/clan_lib/clan/create.py b/pkgs/clan-cli/clan_lib/clan/create.py index fa104c562..ddea36969 100644 --- a/pkgs/clan-cli/clan_lib/clan/create.py +++ b/pkgs/clan-cli/clan_lib/clan/create.py @@ -11,9 +11,9 @@ from clan_lib.persist.inventory_store import InventorySnapshot, InventoryStore from clan_lib.templates import ( InputPrio, TemplateName, - copy_from_nixstore, get_template, ) +from clan_lib.templates.filesystem import copy_from_nixstore log = logging.getLogger(__name__) diff --git a/pkgs/clan-cli/clan_lib/templates/__init__.py b/pkgs/clan-cli/clan_lib/templates/__init__.py index 6e880ec7a..4b30131e5 100644 --- a/pkgs/clan-cli/clan_lib/templates/__init__.py +++ b/pkgs/clan-cli/clan_lib/templates/__init__.py @@ -1,15 +1,11 @@ import logging from dataclasses import dataclass, field -from pathlib import Path from typing import Any, Literal, NewType, TypedDict, cast -from clan_lib.cmd import run from clan_lib.dirs import clan_templates from clan_lib.errors import ClanCmdError, ClanError from clan_lib.flake import Flake -from clan_lib.nix import ( - nix_command, -) +from clan_lib.templates.filesystem import realize_nix_path log = logging.getLogger(__name__) @@ -170,11 +166,6 @@ class InputPrio: return InputPrio(prioritize_self=True, input_names=input_names) -def copy_from_nixstore(src: Path, dest: Path) -> None: - run(["cp", "-r", str(src), str(dest)]) - run(["chmod", "-R", "u+w", str(dest)]) - - @dataclass class TemplateList: inputs: dict[InputName, dict[TemplateName, Template]] = field(default_factory=dict) @@ -205,28 +196,6 @@ def list_templates( return result -def realize_nix_path(flake: Flake, nix_store_path: str) -> None: - """ - Downloads / realizes a nix path into the nix store - """ - - if Path(nix_store_path).exists(): - return - - cmd = [ - "flake", - "prefetch", - "--inputs-from", - flake.identifier, - "--option", - "flake-registry", - "", - nix_store_path, - ] - - run(nix_command(cmd)) - - def get_template( template_name: TemplateName, template_type: TemplateType, diff --git a/pkgs/clan-cli/clan_lib/templates/filesystem.py b/pkgs/clan-cli/clan_lib/templates/filesystem.py new file mode 100644 index 000000000..1e18b57c0 --- /dev/null +++ b/pkgs/clan-cli/clan_lib/templates/filesystem.py @@ -0,0 +1,39 @@ +from pathlib import Path + +from clan_lib.flake import Flake +from clan_lib.nix import ( + nix_command, + run, +) + + +def realize_nix_path(clan_dir: Flake, nix_path: str) -> None: + """ + Downloads / realizes a nix path into the nix store + """ + + if Path(nix_path).exists(): + return + + cmd = [ + "flake", + "prefetch", + "--inputs-from", + clan_dir.identifier, + "--option", + "flake-registry", + "", + nix_path, + ] + + run(nix_command(cmd)) + + +def copy_from_nixstore(src: Path, dest: Path) -> None: + """ + Copy a directory from the nix store to a destination path. + Uses `cp -r` to recursively copy the directory. + Ensures the destination directory is writable by the user. + """ + run(["cp", "-r", str(src), str(dest)]) + run(["chmod", "-R", "u+w", str(dest)])