Skip to content

Commit

Permalink
make updating cargo.lock more robust
Browse files Browse the repository at this point in the history
* don't assume we have a nix flake registry instead take cargo from the
build
* set experimental flags
* apply patches to build
  • Loading branch information
Mic92 committed Aug 10, 2024
1 parent b0f6dcd commit 479d9fa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
31 changes: 26 additions & 5 deletions nix_update/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
Expand All @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion tests/testpkgs/cargo-lock-generate/simple/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{ python3Packages
, rustPlatform
, fetchFromGitHub
,
}:

python3Packages.buildPythonPackage rec {
Expand All @@ -15,5 +14,10 @@ python3Packages.buildPythonPackage rec {
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};

nativeBuildInputs = [
rustPlatform.cargoSetupHook
rustPlatform.maturinBuildHook
];

cargoDeps = rustPlatform.importCargoLock { lockFile = ./Cargo.lock; };
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{ python3Packages
, rustPlatform
, fetchFromGitHub
,
}:

python3Packages.buildPythonPackage rec {
Expand All @@ -15,5 +14,10 @@ python3Packages.buildPythonPackage rec {
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};

nativeBuildInputs = [
rustPlatform.cargoSetupHook
rustPlatform.maturinBuildHook
];

cargoDeps = rustPlatform.importCargoLock { lockFile = ./Cargo.lock; };
}

0 comments on commit 479d9fa

Please sign in to comment.