clan-core/pkgs/clan-cli/default.nix

98 lines
2.2 KiB
Nix
Raw Normal View History

{ age
, argcomplete
, bubblewrap
, installShellFiles
, nix
, openssh
, pytest
, pytest-cov
, pytest-subprocess
, python3
, runCommand
, self
, setuptools
, sops
2023-08-09 14:38:08 +00:00
, stdenv
, wheel
, zerotierone
2023-08-10 10:30:52 +00:00
, rsync
}:
let
2023-08-22 21:15:34 +00:00
# This provides dummy options for testing clan config and prevents it from
# evaluating the flake .#
CLAN_OPTIONS_FILE = ./clan_cli/config/jsonschema/options.json;
dependencies = [ argcomplete ];
testDependencies = [
pytest
pytest-cov
pytest-subprocess
2023-08-09 14:38:08 +00:00
openssh
stdenv.cc
];
checkPython = python3.withPackages (_ps: dependencies ++ testDependencies);
# - vendor the jsonschema nix lib (copy instead of symlink).
# - lib.cleanSource prevents unnecessary rebuilds when `self` changes.
source = runCommand "clan-cli-source" { } ''
2023-08-10 09:30:12 +00:00
cp -r ${./.} $out
chmod -R +w $out
rm $out/clan_cli/config/jsonschema
2023-08-10 09:30:12 +00:00
cp -r ${self + /lib/jsonschema} $out/clan_cli/config/jsonschema
'';
in
python3.pkgs.buildPythonPackage {
2023-08-08 12:20:45 +00:00
name = "clan-cli";
src = source;
format = "pyproject";
2023-08-22 21:15:34 +00:00
inherit CLAN_OPTIONS_FILE;
nativeBuildInputs = [
setuptools
installShellFiles
];
propagatedBuildInputs = dependencies;
2023-08-23 10:32:06 +00:00
passthru.tests.clan-pytest = runCommand "clan-tests"
{
nativeBuildInputs = [ age zerotierone bubblewrap sops nix openssh rsync stdenv.cc ];
} ''
export CLAN_OPTIONS_FILE="${CLAN_OPTIONS_FILE}"
cp -r ${source} ./src
chmod +w -R ./src
cd ./src
NIX_STATE_DIR=$TMPDIR/nix ${checkPython}/bin/python -m pytest -s ./tests
touch $out
'';
passthru.devDependencies = [
setuptools
wheel
] ++ testDependencies;
2023-08-23 10:32:06 +00:00
passthru.testDependencies = testDependencies;
makeWrapperArgs = [
"--set CLAN_FLAKE ${self}"
];
postInstall = ''
installShellCompletion --bash --name clan \
<(${argcomplete}/bin/register-python-argcomplete --shell bash clan)
installShellCompletion --fish --name clan.fish \
<(${argcomplete}/bin/register-python-argcomplete --shell fish clan)
'';
2023-08-03 13:33:08 +00:00
checkPhase = ''
PYTHONPATH= $out/bin/clan --help
2023-08-09 08:36:46 +00:00
if grep --include \*.py -Rq "breakpoint()" $out; then
echo "breakpoint() found in $out:"
grep --include \*.py -Rn "breakpoint()" $out
exit 1
fi
2023-08-03 13:33:08 +00:00
'';
meta.mainProgram = "clan";
}