2023-08-10 22:05:52 +00:00
|
|
|
{ age
|
|
|
|
, argcomplete
|
2023-08-23 15:17:34 +00:00
|
|
|
, fastapi
|
|
|
|
, uvicorn
|
2023-08-10 22:05:52 +00:00
|
|
|
, bubblewrap
|
|
|
|
, installShellFiles
|
|
|
|
, nix
|
|
|
|
, openssh
|
2023-08-03 11:07:00 +00:00
|
|
|
, pytest
|
|
|
|
, pytest-cov
|
|
|
|
, pytest-subprocess
|
2023-08-27 07:45:15 +00:00
|
|
|
, pytest-parallel
|
2023-08-10 22:05:52 +00:00
|
|
|
, python3
|
|
|
|
, runCommand
|
|
|
|
, setuptools
|
|
|
|
, sops
|
2023-08-09 14:38:08 +00:00
|
|
|
, stdenv
|
2023-08-03 11:07:00 +00:00
|
|
|
, wheel
|
2023-08-10 22:05:52 +00:00
|
|
|
, zerotierone
|
2023-08-10 10:30:52 +00:00
|
|
|
, rsync
|
2023-08-25 19:26:30 +00:00
|
|
|
, pkgs
|
2023-08-25 15:08:39 +00:00
|
|
|
, ui-assets
|
2023-07-20 23:08:11 +00:00
|
|
|
}:
|
|
|
|
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;
|
|
|
|
|
2023-08-23 15:17:34 +00:00
|
|
|
dependencies = [
|
|
|
|
argcomplete # optional dependency: if not enabled, shell completion will not work
|
|
|
|
fastapi
|
|
|
|
uvicorn # optional dependencies: if not enabled, webui subcommand will not work
|
|
|
|
];
|
2023-07-20 16:07:27 +00:00
|
|
|
|
2023-08-03 11:07:00 +00:00
|
|
|
testDependencies = [
|
|
|
|
pytest
|
|
|
|
pytest-cov
|
|
|
|
pytest-subprocess
|
2023-08-27 07:45:15 +00:00
|
|
|
pytest-parallel
|
2023-08-09 14:38:08 +00:00
|
|
|
openssh
|
|
|
|
stdenv.cc
|
2023-08-03 11:07:00 +00:00
|
|
|
];
|
2023-07-25 11:46:58 +00:00
|
|
|
|
2023-08-03 11:07:00 +00:00
|
|
|
checkPython = python3.withPackages (_ps: dependencies ++ testDependencies);
|
2023-08-09 16:38:44 +00:00
|
|
|
|
|
|
|
# - 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
|
2023-08-09 16:38:44 +00:00
|
|
|
chmod -R +w $out
|
|
|
|
rm $out/clan_cli/config/jsonschema
|
2023-09-06 12:40:00 +00:00
|
|
|
cp -r ${depsFlake} $out/clan_cli/deps_flake
|
2023-08-27 08:21:02 +00:00
|
|
|
cp -r ${../../lib/jsonschema} $out/clan_cli/config/jsonschema
|
2023-08-25 15:08:39 +00:00
|
|
|
ln -s ${ui-assets} $out/clan_cli/webui/assets
|
2023-08-26 09:23:15 +00:00
|
|
|
'';
|
2023-09-06 12:40:00 +00:00
|
|
|
depsFlake = runCommand "deps-flake" { } ''
|
|
|
|
mkdir $out
|
|
|
|
cp ${./deps-flake.nix} $out/flake.nix
|
|
|
|
${pkgs.nix}/bin/nix flake lock $out \
|
|
|
|
--store ./. \
|
|
|
|
--experimental-features 'nix-command flakes' \
|
|
|
|
--override-input nixpkgs ${pkgs.path}
|
2023-08-09 16:38:44 +00:00
|
|
|
'';
|
2023-08-03 11:07:00 +00:00
|
|
|
in
|
|
|
|
python3.pkgs.buildPythonPackage {
|
2023-08-08 12:20:45 +00:00
|
|
|
name = "clan-cli";
|
2023-08-09 16:38:44 +00:00
|
|
|
src = source;
|
2023-08-03 11:07:00 +00:00
|
|
|
format = "pyproject";
|
2023-08-16 10:13:48 +00:00
|
|
|
|
2023-08-22 21:15:34 +00:00
|
|
|
inherit CLAN_OPTIONS_FILE;
|
2023-08-16 10:13:48 +00:00
|
|
|
|
2023-08-03 11:07:00 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
setuptools
|
|
|
|
installShellFiles
|
|
|
|
];
|
|
|
|
propagatedBuildInputs = dependencies;
|
2023-07-25 11:46:58 +00:00
|
|
|
|
2023-08-26 08:32:04 +00:00
|
|
|
passthru.tests.clan-pytest = runCommand "clan-pytest"
|
2023-08-23 10:32:06 +00:00
|
|
|
{
|
|
|
|
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
|
2023-08-26 09:23:15 +00:00
|
|
|
|
|
|
|
NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1 ${checkPython}/bin/python -m pytest -s ./tests
|
2023-08-23 10:32:06 +00:00
|
|
|
touch $out
|
|
|
|
'';
|
2023-08-25 09:39:46 +00:00
|
|
|
passthru.clan-openapi = runCommand "clan-openapi" { } ''
|
|
|
|
cp -r ${source} ./src
|
|
|
|
chmod +w -R ./src
|
|
|
|
cd ./src
|
|
|
|
${checkPython}/bin/python ./bin/gen-openapi --out $out/openapi.json --app-dir . clan_cli.webui.app:app
|
|
|
|
touch $out
|
|
|
|
'';
|
2023-09-06 12:40:00 +00:00
|
|
|
passthru.depsFlake = depsFlake;
|
2023-07-20 16:07:27 +00:00
|
|
|
|
2023-08-03 11:07:00 +00:00
|
|
|
passthru.devDependencies = [
|
|
|
|
setuptools
|
|
|
|
wheel
|
|
|
|
] ++ testDependencies;
|
2023-07-20 16:07:27 +00:00
|
|
|
|
2023-08-23 15:17:34 +00:00
|
|
|
passthru.testDependencies = dependencies ++ testDependencies;
|
2023-08-23 10:32:06 +00:00
|
|
|
|
2023-08-03 11:07:00 +00:00
|
|
|
postInstall = ''
|
2023-09-06 12:40:00 +00:00
|
|
|
cp -r ${depsFlake} $out/${python3.sitePackages}/clan_cli/deps_flake
|
2023-08-03 11:07:00 +00:00
|
|
|
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-07-20 16:07:27 +00:00
|
|
|
'';
|
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
|
2023-08-09 08:21:59 +00:00
|
|
|
echo "breakpoint() found in $out:"
|
|
|
|
grep --include \*.py -Rn "breakpoint()" $out
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-08-03 13:33:08 +00:00
|
|
|
'';
|
2023-08-03 11:07:00 +00:00
|
|
|
meta.mainProgram = "clan";
|
|
|
|
}
|