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]:
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

View File

@@ -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,

View File

@@ -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

View File

@@ -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;
};
}

View File

@@ -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 .)

View File

@@ -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",