From 409e5d459c123949a35ab31030ba730f2278580a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 26 Jul 2023 08:00:07 +0200 Subject: [PATCH] zerotier: move nix_shell to external package --- pkgs/clan-cli/clan_cli/nix.py | 10 ++++++++++ pkgs/clan-cli/clan_cli/zerotier/__init__.py | 13 ++----------- 2 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 pkgs/clan-cli/clan_cli/nix.py 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