From 09cc79867dc2a73c3b72b8a3fe9fe4800dbaf77d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 26 Jul 2023 09:27:48 +0200 Subject: [PATCH] cli: get optional deps from our own flake This ensures we actually test if all those binaries build --- pkgs/clan-cli/clan_cli/nix.py | 6 ++-- pkgs/clan-cli/clan_cli/zerotier/__init__.py | 3 +- pkgs/clan-cli/default.nix | 8 ++--- pkgs/clan-cli/flake-module.nix | 40 ++++++++++++++------- pkgs/clan-cli/shell.nix | 9 +++-- pkgs/clan-cli/tests/test_clan_ssh.py | 14 ++++---- 6 files changed, 46 insertions(+), 34 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/nix.py b/pkgs/clan-cli/clan_cli/nix.py index ab585abb3..4173ba93a 100644 --- a/pkgs/clan-cli/clan_cli/nix.py +++ b/pkgs/clan-cli/clan_cli/nix.py @@ -2,9 +2,9 @@ import os def nix_shell(packages: list[str], cmd: list[str]) -> list[str]: - nixpkgs = os.environ.get("CLAN_NIXPKGS") + flake = os.environ.get("CLAN_FLAKE") # in unittest we will have all binaries provided - if nixpkgs is None: + if flake is None: return cmd - wrapped_packages = [f"path:{nixpkgs}#{p}" for p in packages] + wrapped_packages = [f"path:{flake}#{p}" for p in packages] return ["nix", "shell"] + wrapped_packages + ["-c"] + cmd diff --git a/pkgs/clan-cli/clan_cli/zerotier/__init__.py b/pkgs/clan-cli/clan_cli/zerotier/__init__.py index 21210aca1..48a2488cb 100644 --- a/pkgs/clan-cli/clan_cli/zerotier/__init__.py +++ b/pkgs/clan-cli/clan_cli/zerotier/__init__.py @@ -86,8 +86,9 @@ class ZerotierController: def zerotier_controller() -> Iterator[ZerotierController]: # This check could be racy but it's unlikely in practice controller_port = find_free_port(range(10000, 65535)) + cmd = nix_shell(["bash", "zerotierone"], ["bash", "-c", "command -v zerotier-one"]) res = subprocess.run( - nix_shell(["bash", "zerotierone"], ["bash", "-c", "command -v zerotier-one"]), + cmd, check=True, text=True, stdout=subprocess.PIPE, diff --git a/pkgs/clan-cli/default.nix b/pkgs/clan-cli/default.nix index 0eeb62d43..8b8eebc94 100644 --- a/pkgs/clan-cli/default.nix +++ b/pkgs/clan-cli/default.nix @@ -6,13 +6,11 @@ , installShellFiles , zerotierone , bubblewrap +, self }: let pyproject = builtins.fromTOML (builtins.readFile ./pyproject.toml); name = pyproject.project.name; - # Override license so that we can build zerotierone without - # having to re-import nixpkgs. - zerotierone' = zerotierone.overrideAttrs (_old: { meta = { }; }); src = lib.cleanSource ./.; @@ -49,7 +47,7 @@ let passthru.devDependencies = devDependencies; makeWrapperArgs = [ - "--set CLAN_NIXPKGS ${pkgs.path}" + "--set CLAN_FLAKE ${self}" ]; postInstall = '' @@ -73,7 +71,7 @@ let clan-pytest = runCommand "${name}-tests" { - nativeBuildInputs = [ zerotierone' bubblewrap ]; + nativeBuildInputs = [ zerotierone bubblewrap ]; } '' cp -r ${src} ./src chmod +w -R ./src diff --git a/pkgs/clan-cli/flake-module.nix b/pkgs/clan-cli/flake-module.nix index 3af30b89b..e53667557 100644 --- a/pkgs/clan-cli/flake-module.nix +++ b/pkgs/clan-cli/flake-module.nix @@ -1,15 +1,29 @@ -{ - perSystem = { pkgs, ... }: - let - pyproject = builtins.fromTOML (builtins.readFile ./pyproject.toml); - name = pyproject.project.name; - package = pkgs.callPackage ./default.nix { }; - shell = pkgs.callPackage ./shell.nix { }; - in - { - packages.${name} = package; - devShells.${name} = shell; - packages.default = package; - checks = package.tests; +{ self, ... }: { + perSystem = { self', pkgs, ... }: { + devShells.clan = pkgs.callPackage ./shell.nix { + inherit self; + inherit (self'.packages) clan; }; + packages = { + clan = pkgs.callPackage ./default.nix { + inherit self; + zerotierone = self'.packages.zerotierone; + }; + default = self'.packages.clan; + + ## Optional dependencies for clan cli, we re-expose them here to make sure they all build. + inherit (pkgs) + bash + bubblewrap + openssh + sshpass + zbar + tor; + + # Override license so that we can build zerotierone without + # having to re-import nixpkgs. + zerotierone = pkgs.zerotierone.overrideAttrs (_old: { meta = { }; }); + }; + checks = self'.packages.clan.tests; + }; } diff --git a/pkgs/clan-cli/shell.nix b/pkgs/clan-cli/shell.nix index 99665fb2a..632ef2f4c 100644 --- a/pkgs/clan-cli/shell.nix +++ b/pkgs/clan-cli/shell.nix @@ -1,10 +1,9 @@ -{ pkgs }: +{ self, clan, pkgs }: let - package = pkgs.callPackage ./default.nix { }; pythonWithDeps = pkgs.python3.withPackages ( ps: - package.propagatedBuildInputs - ++ package.devDependencies + clan.propagatedBuildInputs + ++ clan.devDependencies ++ [ ps.pip ] @@ -19,7 +18,7 @@ pkgs.mkShell { pythonWithDeps ]; # sets up an editable install and add enty points to $PATH - CLAN_NIXPKGS = pkgs.path; + CLAN_FLAKE = self; shellHook = '' tmp_path=$(realpath ./.pythonenv) repo_root=$(realpath .) diff --git a/pkgs/clan-cli/tests/test_clan_ssh.py b/pkgs/clan-cli/tests/test_clan_ssh.py index 897d53057..e864a18f4 100644 --- a/pkgs/clan-cli/tests/test_clan_ssh.py +++ b/pkgs/clan-cli/tests/test_clan_ssh.py @@ -33,14 +33,14 @@ def mock_env(**environ: str) -> Iterator[None]: # using fp fixture from pytest-subprocess def test_ssh_no_pass(fp: pytest_subprocess.fake_process.FakeProcess) -> None: - with mock_env(CLAN_NIXPKGS="/mocked-nixpkgs"): + with mock_env(CLAN_FLAKE="/mocked-flake"): host = "somehost" user = "user" cmd: list[Union[str, utils.Any]] = [ "nix", "shell", - "path:/mocked-nixpkgs#tor", - "path:/mocked-nixpkgs#openssh", + "path:/mocked-flake#tor", + "path:/mocked-flake#openssh", "-c", "torify", "ssh", @@ -60,15 +60,15 @@ def test_ssh_no_pass(fp: pytest_subprocess.fake_process.FakeProcess) -> None: def test_ssh_with_pass(fp: pytest_subprocess.fake_process.FakeProcess) -> None: - with mock_env(CLAN_NIXPKGS="/mocked-nixpkgs"): + with mock_env(CLAN_FLAKE="/mocked-flake"): host = "somehost" user = "user" cmd: list[Union[str, utils.Any]] = [ "nix", "shell", - "path:/mocked-nixpkgs#tor", - "path:/mocked-nixpkgs#openssh", - "path:/mocked-nixpkgs#sshpass", + "path:/mocked-flake#tor", + "path:/mocked-flake#openssh", + "path:/mocked-flake#sshpass", "-c", "torify", "sshpass",