diff --git a/pkgs/clan-cli/default.nix b/pkgs/clan-cli/default.nix index fa00c7cdc..da9596d43 100644 --- a/pkgs/clan-cli/default.nix +++ b/pkgs/clan-cli/default.nix @@ -1,7 +1,6 @@ { # callPackage args argcomplete, - gitMinimal, gnupg, installShellFiles, lib, @@ -34,11 +33,17 @@ let # load nixpkgs runtime dependencies from a json file # This file represents an allow list at the same time that is checked by the run_cmd # implementation in nix.py - runtimeDependenciesAsSet = lib.filterAttrs (_name: pkg: !pkg.meta.unsupported or false) ( - lib.genAttrs (lib.importJSON ./clan_cli/nix/allowed-programs.json) (name: pkgs.${name}) - ); + allDependencies = lib.importJSON ./clan_cli/nix/allowed-programs.json; - runtimeDependencies = lib.attrValues runtimeDependenciesAsSet; + generateRuntimeDependenciesMap = + deps: + lib.filterAttrs (_: pkg: !pkg.meta.unsupported or false) (lib.genAttrs deps (name: pkgs.${name})); + + runtimeDependenciesMap = generateRuntimeDependenciesMap allDependencies; + + runtimeDependencies = lib.attrValues runtimeDependenciesMap; + + includedRuntimeDependenciesMap = generateRuntimeDependenciesMap includedRuntimeDeps; testDependencies = runtimeDependencies @@ -102,28 +107,20 @@ python3.pkgs.buildPythonApplication { format = "pyproject"; # Arguments for the wrapper to unset LD_LIBRARY_PATH to avoid glibc version issues - makeWrapperArgs = - [ - "--unset LD_LIBRARY_PATH" + makeWrapperArgs = [ + "--unset LD_LIBRARY_PATH" + "--unset PYTHONPATH" - # TODO: remove gitMinimal here and use the one from runtimeDependencies - "--suffix" - "PATH" - ":" - "${gitMinimal}/bin/git" - ] # include selected runtime dependencies in the PATH - ++ lib.concatMap (p: [ - "--prefix" - "PATH" - ":" - p - ]) includedRuntimeDeps - ++ [ - "--set" - "CLAN_STATIC_PROGRAMS" - (lib.concatStringsSep ":" includedRuntimeDeps) - ]; + "--prefix" + "PATH" + ":" + (lib.makeBinPath (lib.attrValues includedRuntimeDependenciesMap)) + + "--set" + "CLAN_STATIC_PROGRAMS" + (lib.concatStringsSep ":" (lib.attrNames includedRuntimeDependenciesMap)) + ]; nativeBuildInputs = [ setuptools @@ -133,65 +130,63 @@ python3.pkgs.buildPythonApplication { propagatedBuildInputs = pythonDependencies; # Define and expose the tests and checks to run in CI - passthru.tests = - (lib.mapAttrs' (n: lib.nameValuePair "clan-dep-${n}") runtimeDependenciesAsSet) - // { - clan-pytest-without-core = - runCommand "clan-pytest-without-core" - { nativeBuildInputs = [ pythonWithTestDeps ] ++ testDependencies; } - '' - cp -r ${source} ./src - chmod +w -R ./src - cd ./src + passthru.tests = (lib.mapAttrs' (n: lib.nameValuePair "clan-dep-${n}") runtimeDependenciesMap) // { + clan-pytest-without-core = + runCommand "clan-pytest-without-core" + { nativeBuildInputs = [ pythonWithTestDeps ] ++ testDependencies; } + '' + cp -r ${source} ./src + chmod +w -R ./src + cd ./src - export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1 PYTHONWARNINGS=error - ${pythonWithTestDeps}/bin/python -m pytest -m "not impure and not with_core" ./tests - touch $out - ''; - clan-pytest-with-core = - runCommand "clan-pytest-with-core" - { - nativeBuildInputs = [ pythonWithTestDeps ] ++ testDependencies; - buildInputs = [ + export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1 PYTHONWARNINGS=error + ${pythonWithTestDeps}/bin/python -m pytest -m "not impure and not with_core" ./tests + touch $out + ''; + clan-pytest-with-core = + runCommand "clan-pytest-with-core" + { + nativeBuildInputs = [ pythonWithTestDeps ] ++ testDependencies; + buildInputs = [ + pkgs.bash + pkgs.coreutils + pkgs.nix + ]; + closureInfo = pkgs.closureInfo { + rootPaths = [ pkgs.bash pkgs.coreutils - pkgs.nix + pkgs.jq.dev + pkgs.stdenv + pkgs.stdenvNoCC ]; - closureInfo = pkgs.closureInfo { - rootPaths = [ - pkgs.bash - pkgs.coreutils - pkgs.jq.dev - pkgs.stdenv - pkgs.stdenvNoCC - ]; - }; - } - '' - cp -r ${source} ./src - chmod +w -R ./src - cd ./src + }; + } + '' + cp -r ${source} ./src + chmod +w -R ./src + cd ./src - export CLAN_CORE=${clan-core-path} - export NIX_STATE_DIR=$TMPDIR/nix - export IN_NIX_SANDBOX=1 - export PYTHONWARNINGS=error - export CLAN_TEST_STORE=$TMPDIR/store - # required to prevent concurrent 'nix flake lock' operations - export LOCK_NIX=$TMPDIR/nix_lock - mkdir -p "$CLAN_TEST_STORE/nix/store" - xargs cp --recursive --target "$CLAN_TEST_STORE/nix/store" < "$closureInfo/store-paths" - nix-store --load-db --store "$CLAN_TEST_STORE" < "$closureInfo/registration" - ${pythonWithTestDeps}/bin/python -m pytest -m "not impure and with_core" ./tests - touch $out - ''; - }; + export CLAN_CORE=${clan-core-path} + export NIX_STATE_DIR=$TMPDIR/nix + export IN_NIX_SANDBOX=1 + export PYTHONWARNINGS=error + export CLAN_TEST_STORE=$TMPDIR/store + # required to prevent concurrent 'nix flake lock' operations + export LOCK_NIX=$TMPDIR/nix_lock + mkdir -p "$CLAN_TEST_STORE/nix/store" + xargs cp --recursive --target "$CLAN_TEST_STORE/nix/store" < "$closureInfo/store-paths" + nix-store --load-db --store "$CLAN_TEST_STORE" < "$closureInfo/registration" + ${pythonWithTestDeps}/bin/python -m pytest -m "not impure and with_core" ./tests + touch $out + ''; + }; passthru.nixpkgs = nixpkgs'; passthru.testDependencies = testDependencies; passthru.pythonWithTestDeps = pythonWithTestDeps; passthru.runtimeDependencies = runtimeDependencies; - passthru.runtimeDependenciesAsSet = runtimeDependenciesAsSet; + passthru.runtimeDependenciesMap = runtimeDependenciesMap; postInstall = '' cp -r ${nixpkgs'} $out/${python3.sitePackages}/clan_cli/nixpkgs @@ -210,7 +205,7 @@ python3.pkgs.buildPythonApplication { ''; checkPhase = '' - PYTHONPATH= $out/bin/clan --help + $out/bin/clan --help ''; meta.mainProgram = "clan"; diff --git a/pkgs/clan-cli/shell.nix b/pkgs/clan-cli/shell.nix index 1e1b4dd8c..88ccd6feb 100644 --- a/pkgs/clan-cli/shell.nix +++ b/pkgs/clan-cli/shell.nix @@ -28,7 +28,7 @@ mkShell { inputsFrom = [ self'.devShells.default ]; CLAN_STATIC_PROGRAMS = lib.concatStringsSep ":" ( - lib.attrNames clan-cli-full.passthru.runtimeDependenciesAsSet + lib.attrNames clan-cli-full.passthru.runtimeDependenciesMap ); shellHook = ''