Merge pull request 'clan-cli: fix nix run clan-core failing inside direnv' (#2619) from Enzime/clan-core:push-slxswzoytzut into main

This commit is contained in:
clan-bot
2024-12-17 02:11:44 +00:00
2 changed files with 71 additions and 76 deletions

View File

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

View File

@@ -28,7 +28,7 @@ mkShell {
inputsFrom = [ self'.devShells.default ]; inputsFrom = [ self'.devShells.default ];
CLAN_STATIC_PROGRAMS = lib.concatStringsSep ":" ( CLAN_STATIC_PROGRAMS = lib.concatStringsSep ":" (
lib.attrNames clan-cli-full.passthru.runtimeDependenciesAsSet lib.attrNames clan-cli-full.passthru.runtimeDependenciesMap
); );
shellHook = '' shellHook = ''