2023-08-10 22:05:52 +00:00
|
|
|
{ age
|
2023-09-20 08:58:06 +00:00
|
|
|
, lib
|
2023-08-10 22:05:52 +00:00
|
|
|
, argcomplete
|
2023-08-23 15:17:34 +00:00
|
|
|
, fastapi
|
|
|
|
, uvicorn
|
2023-08-10 22:05:52 +00:00
|
|
|
, 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-10-04 14:54:24 +00:00
|
|
|
, pytest-timeout
|
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-09-26 13:32:36 +00:00
|
|
|
, fakeroot
|
2023-08-10 10:30:52 +00:00
|
|
|
, rsync
|
2023-08-25 15:08:39 +00:00
|
|
|
, ui-assets
|
2023-09-20 08:58:06 +00:00
|
|
|
, bash
|
|
|
|
, sshpass
|
|
|
|
, zbar
|
|
|
|
, tor
|
|
|
|
, git
|
2023-09-22 06:39:24 +00:00
|
|
|
, nixpkgs
|
2023-09-27 17:02:03 +00:00
|
|
|
, makeDesktopItem
|
|
|
|
, copyDesktopItems
|
2023-09-28 16:27:06 +00:00
|
|
|
, qemu
|
|
|
|
, gnupg
|
2023-10-03 14:51:34 +00:00
|
|
|
, e2fsprogs
|
2023-07-20 23:08:11 +00:00
|
|
|
}:
|
|
|
|
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
|
|
|
|
];
|
2023-07-20 16:07:27 +00:00
|
|
|
|
2023-09-20 08:58:06 +00:00
|
|
|
pytestDependencies = runtimeDependencies ++ dependencies ++ [
|
2023-08-03 11:07:00 +00:00
|
|
|
pytest
|
|
|
|
pytest-cov
|
|
|
|
pytest-subprocess
|
2023-08-27 07:45:15 +00:00
|
|
|
pytest-parallel
|
2023-10-04 14:54:24 +00:00
|
|
|
pytest-timeout
|
2023-08-09 14:38:08 +00:00
|
|
|
openssh
|
2023-09-20 08:58:06 +00:00
|
|
|
git
|
2023-09-29 16:31:05 +00:00
|
|
|
gnupg
|
2023-08-09 14:38:08 +00:00
|
|
|
stdenv.cc
|
2023-08-03 11:07:00 +00:00
|
|
|
];
|
2023-07-25 11:46:58 +00:00
|
|
|
|
2023-09-20 08:58:06 +00:00
|
|
|
# Optional dependencies for clan cli, we re-expose them here to make sure they all build.
|
|
|
|
runtimeDependencies = [
|
|
|
|
bash
|
|
|
|
nix
|
2023-09-26 13:32:36 +00:00
|
|
|
fakeroot
|
2023-09-20 08:58:06 +00:00
|
|
|
openssh
|
|
|
|
sshpass
|
|
|
|
zbar
|
|
|
|
tor
|
|
|
|
age
|
|
|
|
rsync
|
|
|
|
sops
|
|
|
|
git
|
2023-09-28 16:27:06 +00:00
|
|
|
qemu
|
2023-10-03 14:51:34 +00:00
|
|
|
e2fsprogs
|
2023-09-20 08:58:06 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
runtimeDependenciesAsSet = builtins.listToAttrs (builtins.map (p: lib.nameValuePair (lib.getName p.name) p) runtimeDependencies);
|
|
|
|
|
|
|
|
checkPython = python3.withPackages (_ps: pytestDependencies);
|
2023-08-09 16:38:44 +00:00
|
|
|
|
|
|
|
# - vendor the jsonschema nix lib (copy instead of symlink).
|
2023-09-22 06:39:24 +00:00
|
|
|
# Interesting fact: using nixpkgs from flakes instead of nixpkgs.path is reduces evaluation time by 5s.
|
2023-08-09 16:38:44 +00:00
|
|
|
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-22 06:39:24 +00:00
|
|
|
ln -s ${nixpkgs'} $out/clan_cli/nixpkgs
|
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-22 06:39:24 +00:00
|
|
|
nixpkgs' = runCommand "nixpkgs" { nativeBuildInputs = [ nix ]; } ''
|
2023-09-06 12:40:00 +00:00
|
|
|
mkdir $out
|
2023-09-06 15:29:49 +00:00
|
|
|
cat > $out/flake.nix << EOF
|
|
|
|
{
|
|
|
|
description = "dependencies for the clan-cli";
|
|
|
|
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "nixpkgs";
|
|
|
|
};
|
|
|
|
|
|
|
|
outputs = _inputs: { };
|
|
|
|
}
|
|
|
|
EOF
|
2023-09-22 06:39:24 +00:00
|
|
|
ln -s ${nixpkgs} $out/path
|
2023-09-06 15:29:49 +00:00
|
|
|
nix flake lock $out \
|
2023-09-06 12:40:00 +00:00
|
|
|
--store ./. \
|
2023-09-27 13:02:21 +00:00
|
|
|
--extra-experimental-features 'nix-command flakes' \
|
2023-09-22 06:39:24 +00:00
|
|
|
--override-input nixpkgs ${nixpkgs}
|
2023-08-09 16:38:44 +00:00
|
|
|
'';
|
2023-08-03 11:07:00 +00:00
|
|
|
in
|
2023-09-28 09:19:16 +00:00
|
|
|
python3.pkgs.buildPythonApplication {
|
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-10-05 11:43:59 +00:00
|
|
|
makeWrapperArgs = [
|
|
|
|
# This prevents problems with mixed glibc versions that might occur when the
|
|
|
|
# cli is called through a browser built against another glibc
|
|
|
|
"--unset LD_LIBRARY_PATH"
|
|
|
|
];
|
|
|
|
|
2023-08-03 11:07:00 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
setuptools
|
|
|
|
installShellFiles
|
2023-09-27 17:02:03 +00:00
|
|
|
copyDesktopItems
|
2023-08-03 11:07:00 +00:00
|
|
|
];
|
|
|
|
propagatedBuildInputs = dependencies;
|
2023-07-25 11:46:58 +00:00
|
|
|
|
2023-09-20 08:58:06 +00:00
|
|
|
# also re-expose dependencies so we test them in CI
|
2023-09-22 13:39:03 +00:00
|
|
|
passthru.tests = (lib.mapAttrs' (n: lib.nameValuePair "clan-dep-${n}") runtimeDependenciesAsSet) // {
|
2023-09-20 08:58:06 +00:00
|
|
|
clan-pytest = runCommand "clan-pytest" { nativeBuildInputs = [ checkPython ] ++ pytestDependencies; } ''
|
|
|
|
cp -r ${source} ./src
|
|
|
|
chmod +w -R ./src
|
|
|
|
cd ./src
|
2023-09-21 12:07:54 +00:00
|
|
|
|
2023-09-20 08:58:06 +00:00
|
|
|
export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1
|
|
|
|
${checkPython}/bin/python -m pytest -m "not impure" -s ./tests
|
|
|
|
touch $out
|
|
|
|
'';
|
2023-10-27 12:37:43 +00:00
|
|
|
check-for-breakpoints = runCommand "breakpoints" { } ''
|
|
|
|
if grep --include \*.py -Rq "breakpoint()" ${source}; then
|
|
|
|
echo "breakpoint() found in ${source}:"
|
|
|
|
grep --include \*.py -Rn "breakpoint()" ${source}
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
touch $out
|
|
|
|
'';
|
2023-09-20 08:58:06 +00:00
|
|
|
};
|
2023-08-25 09:39:46 +00:00
|
|
|
passthru.clan-openapi = runCommand "clan-openapi" { } ''
|
|
|
|
cp -r ${source} ./src
|
|
|
|
chmod +w -R ./src
|
|
|
|
cd ./src
|
2023-09-20 08:58:06 +00:00
|
|
|
export PATH=${checkPython}/bin:$PATH
|
|
|
|
|
2023-08-25 09:39:46 +00:00
|
|
|
${checkPython}/bin/python ./bin/gen-openapi --out $out/openapi.json --app-dir . clan_cli.webui.app:app
|
|
|
|
touch $out
|
|
|
|
'';
|
2023-09-22 06:39:24 +00:00
|
|
|
passthru.nixpkgs = nixpkgs';
|
2023-09-19 14:46:38 +00:00
|
|
|
passthru.checkPython = checkPython;
|
2023-07-20 16:07:27 +00:00
|
|
|
|
2023-08-03 11:07:00 +00:00
|
|
|
passthru.devDependencies = [
|
|
|
|
setuptools
|
|
|
|
wheel
|
2023-09-20 08:58:06 +00:00
|
|
|
] ++ pytestDependencies;
|
2023-07-20 16:07:27 +00:00
|
|
|
|
2023-09-20 08:58:06 +00:00
|
|
|
passthru.pytestDependencies = pytestDependencies;
|
|
|
|
passthru.runtimeDependencies = runtimeDependencies;
|
2023-08-23 10:32:06 +00:00
|
|
|
|
2023-08-03 11:07:00 +00:00
|
|
|
postInstall = ''
|
2023-09-22 06:39:24 +00:00
|
|
|
cp -r ${nixpkgs'} $out/${python3.sitePackages}/clan_cli/nixpkgs
|
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-10-04 08:34:32 +00:00
|
|
|
# Don't leak python packages into a devshell.
|
|
|
|
# It can be very confusing if you `nix run` than load the cli from the devshell instead.
|
|
|
|
postFixup = ''
|
|
|
|
rm $out/nix-support/propagated-build-inputs
|
|
|
|
'';
|
2023-08-03 13:33:08 +00:00
|
|
|
checkPhase = ''
|
|
|
|
PYTHONPATH= $out/bin/clan --help
|
|
|
|
'';
|
2023-08-03 11:07:00 +00:00
|
|
|
meta.mainProgram = "clan";
|
2023-09-27 17:02:03 +00:00
|
|
|
desktopItems = [
|
|
|
|
(makeDesktopItem {
|
|
|
|
name = "clan";
|
2023-10-05 15:33:38 +00:00
|
|
|
exec = "clan --debug join %u";
|
2023-09-27 17:02:03 +00:00
|
|
|
desktopName = "CLan Manager";
|
|
|
|
startupWMClass = "clan";
|
|
|
|
mimeTypes = [ "x-scheme-handler/clan" ];
|
|
|
|
})
|
|
|
|
];
|
2023-08-03 11:07:00 +00:00
|
|
|
}
|