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

137 lines
3.3 KiB
Nix
Raw Normal View History

{ age
, argcomplete
2023-08-23 15:17:34 +00:00
, fastapi
, uvicorn
, bubblewrap
, installShellFiles
, nix
, openssh
, pytest
, pytest-cov
, pytest-subprocess
2023-08-27 07:45:15 +00:00
, pytest-parallel
, python3
, runCommand
, setuptools
, sops
2023-08-09 14:38:08 +00:00
, stdenv
, wheel
, zerotierone
2023-08-10 10:30:52 +00:00
, rsync
, pkgs
, ui-assets
, lib
}:
let
2023-08-22 21:15:34 +00:00
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
];
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
];
checkPython = python3.withPackages (_ps: dependencies ++ testDependencies);
# - vendor the jsonschema nix lib (copy instead of symlink).
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-09-06 15:29:49 +00:00
cp -r ${nixpkgs} $out/clan_cli/nixpkgs
cp -r ${../../lib/jsonschema} $out/clan_cli/config/jsonschema
ln -s ${ui-assets} $out/clan_cli/webui/assets
'';
2023-09-06 15:29:49 +00:00
nixpkgs = runCommand "nixpkgs" { nativeBuildInputs = [ pkgs.nix ]; } ''
mkdir $out
2023-09-19 09:29:59 +00:00
mkdir -p $out/unfree
cat > $out/unfree/default.nix <<EOF
import "${pkgs.path}" { config = { allowUnfree = true; overlays = []; }; }
2023-09-06 15:29:49 +00:00
EOF
cat > $out/flake.nix << EOF
{
description = "dependencies for the clan-cli";
inputs = {
nixpkgs.url = "nixpkgs";
};
outputs = _inputs: { };
}
EOF
ln -s ${pkgs.path} $out/path
nix flake lock $out \
--store ./. \
--experimental-features 'nix-command flakes' \
--override-input nixpkgs ${pkgs.path}
'';
in
python3.pkgs.buildPythonPackage {
2023-08-08 12:20:45 +00:00
name = "clan-cli";
src = source;
format = "pyproject";
nativeBuildInputs = [
setuptools
installShellFiles
];
propagatedBuildInputs = dependencies;
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 ];
} ''
cp -r ${source} ./src
chmod +w -R ./src
cd ./src
# git is needed for test_git.py
export PATH="${lib.makeBinPath [pkgs.git]}:$PATH"
2023-09-19 09:29:59 +00:00
export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1
2023-09-14 14:57:19 +00:00
${checkPython}/bin/python -m pytest -m "not impure" -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 15:29:49 +00:00
passthru.nixpkgs = nixpkgs;
passthru.checkPython = checkPython;
passthru.devDependencies = [
setuptools
wheel
] ++ testDependencies;
2023-08-23 15:17:34 +00:00
passthru.testDependencies = dependencies ++ testDependencies;
2023-08-23 10:32:06 +00:00
postInstall = ''
2023-09-06 15:29:49 +00:00
cp -r ${nixpkgs} $out/${python3.sitePackages}/clan_cli/nixpkgs
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";
}