diff --git a/pkgs/clan-cli/clan_cli/nix.py b/pkgs/clan-cli/clan_cli/nix.py new file mode 100644 index 000000000..b5515676d --- /dev/null +++ b/pkgs/clan-cli/clan_cli/nix.py @@ -0,0 +1,10 @@ +import os + +CLAN_NIXPKGS = os.environ.get("CLAN_NIXPKGS") + + +def nix_shell(packages: list[str], cmd: list[str]) -> list[str]: + # in unittest we will have all binaries provided + if CLAN_NIXPKGS is None: + return cmd + return ["nix", "shell", "-f", CLAN_NIXPKGS] + packages + ["-c"] + cmd diff --git a/pkgs/clan-cli/clan_cli/zerotier/__init__.py b/pkgs/clan-cli/clan_cli/zerotier/__init__.py index 4f383a885..21210aca1 100644 --- a/pkgs/clan-cli/clan_cli/zerotier/__init__.py +++ b/pkgs/clan-cli/clan_cli/zerotier/__init__.py @@ -1,5 +1,4 @@ import json -import os import socket import subprocess import time @@ -9,6 +8,8 @@ from pathlib import Path from tempfile import TemporaryDirectory from typing import Any, Iterator, Optional +from ..nix import nix_shell + def try_bind_port(port: int) -> bool: tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -36,16 +37,6 @@ def find_free_port(port_range: range) -> int: raise Exception("cannot find a free port") -CLAN_NIXPKGS = os.environ.get("CLAN_NIXPKGS") - - -def nix_shell(packages: list[str], cmd: list[str]) -> list[str]: - # in unittest we will have all binaries provided - if CLAN_NIXPKGS is None: - return cmd - return ["nix", "shell", "-f", CLAN_NIXPKGS] + packages + ["-c"] + cmd - - class ZerotierController: def __init__(self, port: int, home: Path) -> None: self.port = port