2024-03-17 18:48:49 +00:00
|
|
|
{
|
|
|
|
python3,
|
|
|
|
runCommand,
|
|
|
|
setuptools,
|
|
|
|
copyDesktopItems,
|
|
|
|
pygobject3,
|
|
|
|
wrapGAppsHook,
|
|
|
|
gtk4,
|
|
|
|
gnome,
|
|
|
|
pygobject-stubs,
|
|
|
|
gobject-introspection,
|
|
|
|
clan-cli,
|
|
|
|
makeDesktopItem,
|
|
|
|
libadwaita,
|
2024-03-24 22:36:00 +00:00
|
|
|
pytest, # Testing framework
|
|
|
|
pytest-cov, # Generate coverage reports
|
|
|
|
pytest-subprocess, # fake the real subprocess behavior to make your tests more independent.
|
|
|
|
pytest-xdist, # Run tests in parallel on multiple cores
|
|
|
|
pytest-timeout, # Add timeouts to your tests
|
2023-11-23 13:37:05 +00:00
|
|
|
}:
|
|
|
|
let
|
|
|
|
source = ./.;
|
2024-03-01 11:15:44 +00:00
|
|
|
desktop-file = makeDesktopItem {
|
2024-03-01 11:52:05 +00:00
|
|
|
name = "org.clan.vm-manager";
|
2024-03-01 11:15:44 +00:00
|
|
|
exec = "clan-vm-manager %u";
|
|
|
|
icon = ./clan_vm_manager/assets/clan_white.png;
|
|
|
|
desktopName = "cLAN Manager";
|
|
|
|
startupWMClass = "clan";
|
|
|
|
mimeTypes = [ "x-scheme-handler/clan" ];
|
|
|
|
};
|
2024-03-24 22:36:00 +00:00
|
|
|
|
|
|
|
# Dependencies that are directly used in the project but nor from internal python packages
|
|
|
|
externalPythonDeps = [
|
|
|
|
pygobject3
|
|
|
|
pygobject-stubs
|
|
|
|
gtk4
|
|
|
|
libadwaita
|
|
|
|
gnome.adwaita-icon-theme
|
|
|
|
];
|
|
|
|
|
|
|
|
# Deps including python packages from the local project
|
|
|
|
allPythonDeps = [ (python3.pkgs.toPythonModule clan-cli) ] ++ externalPythonDeps;
|
|
|
|
|
|
|
|
# Runtime binary dependencies required by the application
|
|
|
|
runtimeDependencies = [ ];
|
|
|
|
|
|
|
|
# Dependencies required for running tests
|
2024-03-24 22:52:30 +00:00
|
|
|
externalTestDeps = [
|
|
|
|
pytest # Testing framework
|
|
|
|
pytest-cov # Generate coverage reports
|
|
|
|
pytest-subprocess # fake the real subprocess behavior to make your tests more independent.
|
|
|
|
pytest-xdist # Run tests in parallel on multiple cores
|
|
|
|
pytest-timeout # Add timeouts to your tests
|
|
|
|
];
|
|
|
|
|
|
|
|
# Dependencies required for running tests
|
|
|
|
testDependencies = runtimeDependencies ++ allPythonDeps ++ externalTestDeps;
|
2024-03-24 22:36:00 +00:00
|
|
|
|
|
|
|
# Setup Python environment with all dependencies for running tests
|
|
|
|
pythonWithTestDeps = python3.withPackages (_ps: testDependencies);
|
2023-11-23 13:37:05 +00:00
|
|
|
in
|
2024-03-19 06:00:59 +00:00
|
|
|
python3.pkgs.buildPythonApplication rec {
|
2023-11-23 13:37:05 +00:00
|
|
|
name = "clan-vm-manager";
|
|
|
|
src = source;
|
|
|
|
format = "pyproject";
|
|
|
|
|
|
|
|
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"
|
|
|
|
];
|
|
|
|
|
2024-03-24 22:36:00 +00:00
|
|
|
# Deps needed only at build time
|
2023-11-23 13:37:05 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
setuptools
|
|
|
|
copyDesktopItems
|
|
|
|
wrapGAppsHook
|
|
|
|
gobject-introspection
|
|
|
|
];
|
|
|
|
|
2024-03-24 22:36:00 +00:00
|
|
|
# The necessity of setting buildInputs and propagatedBuildInputs to the
|
|
|
|
# same values for your Python package within Nix largely stems from ensuring
|
|
|
|
# that all necessary dependencies are consistently available both
|
|
|
|
# at build time and runtime,
|
|
|
|
buildInputs = allPythonDeps ++ runtimeDependencies;
|
|
|
|
propagatedBuildInputs = allPythonDeps ++ runtimeDependencies;
|
2024-03-22 18:08:35 +00:00
|
|
|
|
2023-11-23 13:37:05 +00:00
|
|
|
# also re-expose dependencies so we test them in CI
|
2024-03-01 11:15:44 +00:00
|
|
|
passthru = {
|
|
|
|
tests = {
|
2024-03-22 18:08:35 +00:00
|
|
|
clan-vm-manager-pytest =
|
2024-03-24 22:36:00 +00:00
|
|
|
runCommand "clan-vm-manager-pytest" { inherit buildInputs propagatedBuildInputs nativeBuildInputs; }
|
2024-03-22 18:08:35 +00:00
|
|
|
''
|
|
|
|
cp -r ${source} ./src
|
|
|
|
chmod +w -R ./src
|
|
|
|
cd ./src
|
|
|
|
|
|
|
|
export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1
|
2024-03-24 22:36:00 +00:00
|
|
|
${pythonWithTestDeps}/bin/python -m pytest -s -m "not impure" ./tests
|
2024-03-22 18:08:35 +00:00
|
|
|
touch $out
|
|
|
|
'';
|
2024-03-24 22:36:00 +00:00
|
|
|
|
2024-03-01 11:15:44 +00:00
|
|
|
clan-vm-manager-no-breakpoints = runCommand "clan-vm-manager-no-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-11-23 13:37:05 +00:00
|
|
|
};
|
|
|
|
|
2024-03-24 22:36:00 +00:00
|
|
|
# Additional pass-through attributes
|
|
|
|
passthru.desktop-file = desktop-file;
|
|
|
|
passthru.externalPythonDeps = externalPythonDeps;
|
2024-03-24 22:52:30 +00:00
|
|
|
passthru.externalTestDeps = externalTestDeps;
|
2024-03-24 22:36:00 +00:00
|
|
|
passthru.runtimeDependencies = runtimeDependencies;
|
2024-03-24 22:52:30 +00:00
|
|
|
passthru.testDependencies = testDependencies;
|
2024-03-24 22:36:00 +00:00
|
|
|
|
2023-11-23 13:37:05 +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
|
|
|
|
'';
|
|
|
|
checkPhase = ''
|
|
|
|
PYTHONPATH= $out/bin/clan-vm-manager --help
|
|
|
|
'';
|
2024-03-17 18:48:49 +00:00
|
|
|
desktopItems = [ desktop-file ];
|
2023-11-23 13:37:05 +00:00
|
|
|
}
|