diff --git a/nix_update/update.py b/nix_update/update.py index d31b0bc..02e3789 100644 --- a/nix_update/update.py +++ b/nix_update/update.py @@ -6,6 +6,7 @@ import sys import tempfile import tomllib +import textwrap from concurrent.futures import ThreadPoolExecutor from contextlib import contextmanager from os import path @@ -258,15 +259,36 @@ def disable_copystat(): finally: shutil.copystat = _orig + getSrcAndCargo = textwrap.dedent(f""" + {get_package(opts)}.overrideAttrs (old: {{ + cargoDeps = null; + cargoVendorDir = "."; + postUnpack = '' + cp -pr --reflink=auto -- . $out + mkdir -p "$out/nix-support" + command -v cargo > $out/nix-support/cargo-bin || {{ + echo "no cargo executable found in native build inputs" >&2 + exit 1 + }} + exit + ''; + outputs = [ "out" ]; + separateDebugInfo = false; + }}) + """) + res = run( [ "nix", + "--extra-experimental-features", + "flakes nix-command", "build", + "-L", "--no-link", "--impure", "--print-out-paths", "--expr", - f"{get_package(opts)}.src", + getSrcAndCargo, ] + opts.extra_flags, ) @@ -276,12 +298,11 @@ def disable_copystat(): with disable_copystat(): shutil.copytree(src, tempdir, dirs_exist_ok=True, copy_function=shutil.copy) + cargo_bin = (src / "nix-support" / "cargo-bin").read_text().rstrip("\n") + run( [ - "nix", - "run", - "nixpkgs#cargo", - "--", + cargo_bin, "generate-lockfile", "--manifest-path", f"{opts.lockfile_metadata_path}/Cargo.toml", diff --git a/tests/testpkgs/cargo-lock-generate/simple/default.nix b/tests/testpkgs/cargo-lock-generate/simple/default.nix index be641aa..c0729f0 100644 --- a/tests/testpkgs/cargo-lock-generate/simple/default.nix +++ b/tests/testpkgs/cargo-lock-generate/simple/default.nix @@ -1,7 +1,6 @@ { python3Packages , rustPlatform , fetchFromGitHub -, }: python3Packages.buildPythonPackage rec { @@ -15,5 +14,10 @@ python3Packages.buildPythonPackage rec { hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; }; + nativeBuildInputs = [ + rustPlatform.cargoSetupHook + rustPlatform.maturinBuildHook + ]; + cargoDeps = rustPlatform.importCargoLock { lockFile = ./Cargo.lock; }; } diff --git a/tests/testpkgs/cargo-lock-generate/with-lockfile-metadata-path/default.nix b/tests/testpkgs/cargo-lock-generate/with-lockfile-metadata-path/default.nix index 1a85d85..b601016 100644 --- a/tests/testpkgs/cargo-lock-generate/with-lockfile-metadata-path/default.nix +++ b/tests/testpkgs/cargo-lock-generate/with-lockfile-metadata-path/default.nix @@ -1,7 +1,6 @@ { python3Packages , rustPlatform , fetchFromGitHub -, }: python3Packages.buildPythonPackage rec { @@ -15,5 +14,10 @@ python3Packages.buildPythonPackage rec { hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; }; + nativeBuildInputs = [ + rustPlatform.cargoSetupHook + rustPlatform.maturinBuildHook + ]; + cargoDeps = rustPlatform.importCargoLock { lockFile = ./Cargo.lock; }; }