cli: get optional deps from our own flake

This ensures we actually test if all those binaries build
This commit is contained in:
Jörg Thalheim
2023-07-26 09:27:48 +02:00
parent ed474457b3
commit 09cc79867d
6 changed files with 46 additions and 34 deletions

View File

@@ -2,9 +2,9 @@ import os
def nix_shell(packages: list[str], cmd: list[str]) -> list[str]: 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 # in unittest we will have all binaries provided
if nixpkgs is None: if flake is None:
return cmd 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 return ["nix", "shell"] + wrapped_packages + ["-c"] + cmd

View File

@@ -86,8 +86,9 @@ class ZerotierController:
def zerotier_controller() -> Iterator[ZerotierController]: def zerotier_controller() -> Iterator[ZerotierController]:
# This check could be racy but it's unlikely in practice # This check could be racy but it's unlikely in practice
controller_port = find_free_port(range(10000, 65535)) controller_port = find_free_port(range(10000, 65535))
cmd = nix_shell(["bash", "zerotierone"], ["bash", "-c", "command -v zerotier-one"])
res = subprocess.run( res = subprocess.run(
nix_shell(["bash", "zerotierone"], ["bash", "-c", "command -v zerotier-one"]), cmd,
check=True, check=True,
text=True, text=True,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,

View File

@@ -6,13 +6,11 @@
, installShellFiles , installShellFiles
, zerotierone , zerotierone
, bubblewrap , bubblewrap
, self
}: }:
let let
pyproject = builtins.fromTOML (builtins.readFile ./pyproject.toml); pyproject = builtins.fromTOML (builtins.readFile ./pyproject.toml);
name = pyproject.project.name; 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 ./.; src = lib.cleanSource ./.;
@@ -49,7 +47,7 @@ let
passthru.devDependencies = devDependencies; passthru.devDependencies = devDependencies;
makeWrapperArgs = [ makeWrapperArgs = [
"--set CLAN_NIXPKGS ${pkgs.path}" "--set CLAN_FLAKE ${self}"
]; ];
postInstall = '' postInstall = ''
@@ -73,7 +71,7 @@ let
clan-pytest = runCommand "${name}-tests" clan-pytest = runCommand "${name}-tests"
{ {
nativeBuildInputs = [ zerotierone' bubblewrap ]; nativeBuildInputs = [ zerotierone bubblewrap ];
} '' } ''
cp -r ${src} ./src cp -r ${src} ./src
chmod +w -R ./src chmod +w -R ./src

View File

@@ -1,15 +1,29 @@
{ { self, ... }: {
perSystem = { pkgs, ... }: perSystem = { self', pkgs, ... }: {
let devShells.clan = pkgs.callPackage ./shell.nix {
pyproject = builtins.fromTOML (builtins.readFile ./pyproject.toml); inherit self;
name = pyproject.project.name; inherit (self'.packages) clan;
package = pkgs.callPackage ./default.nix { };
shell = pkgs.callPackage ./shell.nix { };
in
{
packages.${name} = package;
devShells.${name} = shell;
packages.default = package;
checks = package.tests;
}; };
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;
};
} }

View File

@@ -1,10 +1,9 @@
{ pkgs }: { self, clan, pkgs }:
let let
package = pkgs.callPackage ./default.nix { };
pythonWithDeps = pkgs.python3.withPackages ( pythonWithDeps = pkgs.python3.withPackages (
ps: ps:
package.propagatedBuildInputs clan.propagatedBuildInputs
++ package.devDependencies ++ clan.devDependencies
++ [ ++ [
ps.pip ps.pip
] ]
@@ -19,7 +18,7 @@ pkgs.mkShell {
pythonWithDeps pythonWithDeps
]; ];
# sets up an editable install and add enty points to $PATH # sets up an editable install and add enty points to $PATH
CLAN_NIXPKGS = pkgs.path; CLAN_FLAKE = self;
shellHook = '' shellHook = ''
tmp_path=$(realpath ./.pythonenv) tmp_path=$(realpath ./.pythonenv)
repo_root=$(realpath .) repo_root=$(realpath .)

View File

@@ -33,14 +33,14 @@ def mock_env(**environ: str) -> Iterator[None]:
# using fp fixture from pytest-subprocess # using fp fixture from pytest-subprocess
def test_ssh_no_pass(fp: pytest_subprocess.fake_process.FakeProcess) -> None: 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" host = "somehost"
user = "user" user = "user"
cmd: list[Union[str, utils.Any]] = [ cmd: list[Union[str, utils.Any]] = [
"nix", "nix",
"shell", "shell",
"path:/mocked-nixpkgs#tor", "path:/mocked-flake#tor",
"path:/mocked-nixpkgs#openssh", "path:/mocked-flake#openssh",
"-c", "-c",
"torify", "torify",
"ssh", "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: 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" host = "somehost"
user = "user" user = "user"
cmd: list[Union[str, utils.Any]] = [ cmd: list[Union[str, utils.Any]] = [
"nix", "nix",
"shell", "shell",
"path:/mocked-nixpkgs#tor", "path:/mocked-flake#tor",
"path:/mocked-nixpkgs#openssh", "path:/mocked-flake#openssh",
"path:/mocked-nixpkgs#sshpass", "path:/mocked-flake#sshpass",
"-c", "-c",
"torify", "torify",
"sshpass", "sshpass",