From 087cc6bcc1acb83068915851f675c89cc337312e Mon Sep 17 00:00:00 2001 From: krendelhoff2 Date: Sat, 28 Sep 2024 10:42:17 +0700 Subject: [PATCH] [Chore] Fix rust deps nix build --- flake.lock | 109 ++++++++++++++++++++++++++---------- flake.nix | 15 ++++- nix/build/ocaml-overlay.nix | 57 ++++++++++++------- 3 files changed, 130 insertions(+), 51 deletions(-) diff --git a/flake.lock b/flake.lock index e83b4a92e..96c6fb9a4 100644 --- a/flake.lock +++ b/flake.lock @@ -98,10 +98,25 @@ "type": "github" } }, + "crane": { + "locked": { + "lastModified": 1727316705, + "narHash": "sha256-/mumx8AQ5xFuCJqxCIOFCHTVlxHkMT21idpbgbm/TIE=", + "owner": "ipetkov", + "repo": "crane", + "rev": "5b03654ce046b5167e7b0bccbd8244cb56c16f0e", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, "deploy-rs": { "inputs": { "flake-compat": "flake-compat_3", - "nixpkgs": "nixpkgs_4", + "nixpkgs": "nixpkgs_5", "utils": "utils" }, "locked": { @@ -417,7 +432,7 @@ }, "gomod2nix": { "inputs": { - "nixpkgs": "nixpkgs_6", + "nixpkgs": "nixpkgs_7", "utils": "utils_2" }, "locked": { @@ -729,7 +744,7 @@ "nix2container": { "inputs": { "flake-utils": "flake-utils_5", - "nixpkgs": "nixpkgs_7" + "nixpkgs": "nixpkgs_8" }, "locked": { "lastModified": 1658567952, @@ -748,7 +763,7 @@ "nix_2": { "inputs": { "lowdown-src": "lowdown-src_2", - "nixpkgs": "nixpkgs_5", + "nixpkgs": "nixpkgs_6", "nixpkgs-regression": "nixpkgs-regression_2" }, "locked": { @@ -769,7 +784,7 @@ "nix_3": { "inputs": { "lowdown-src": "lowdown-src_3", - "nixpkgs": "nixpkgs_9" + "nixpkgs": "nixpkgs_10" }, "locked": { "lastModified": 1633098935, @@ -952,11 +967,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1657802959, - "narHash": "sha256-9+JWARSdlL8KiH3ymnKDXltE1vM+/WEJ78F5B1kjXys=", + "lastModified": 1726937504, + "narHash": "sha256-bvGoiQBvponpZh8ClUcmJ6QnsNKw0EMrCQJARK3bI1c=", "owner": "nixos", "repo": "nixpkgs", - "rev": "4a01ca36d6bfc133bc617e661916a81327c9bbc8", + "rev": "9357f4f23713673f310988025d9dc261c20e70c6", "type": "github" }, "original": { @@ -983,6 +998,21 @@ } }, "nixpkgs_10": { + "locked": { + "lastModified": 1632864508, + "narHash": "sha256-d127FIvGR41XbVRDPVvozUPQ/uRHbHwvfyKHwEt5xFM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "82891b5e2c2359d7e58d08849e4c89511ab94234", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-21.05-small", + "type": "indirect" + } + }, + "nixpkgs_11": { "locked": { "lastModified": 1674736538, "narHash": "sha256-/DszFMkAgYyB9dTWKkoZa9i0zcrA6Z4hYrOr/u/FSxY=", @@ -1028,6 +1058,22 @@ } }, "nixpkgs_4": { + "locked": { + "lastModified": 1727335715, + "narHash": "sha256-1uw3y94dA4l22LkqHRIsb7qr3rV5XdxQFqctINfx8Cc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "28b5b8af91ffd2623e995e20aee56510db49001a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_5": { "locked": { "lastModified": 1648219316, "narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=", @@ -1043,7 +1089,7 @@ "type": "github" } }, - "nixpkgs_5": { + "nixpkgs_6": { "locked": { "lastModified": 1657693803, "narHash": "sha256-G++2CJ9u0E7NNTAi9n5G8TdDmGJXcIjkJ3NF8cetQB8=", @@ -1059,7 +1105,7 @@ "type": "github" } }, - "nixpkgs_6": { + "nixpkgs_7": { "locked": { "lastModified": 1653581809, "narHash": "sha256-Uvka0V5MTGbeOfWte25+tfRL3moECDh1VwokWSZUdoY=", @@ -1075,7 +1121,7 @@ "type": "github" } }, - "nixpkgs_7": { + "nixpkgs_8": { "locked": { "lastModified": 1654807842, "narHash": "sha256-ADymZpr6LuTEBXcy6RtFHcUZdjKTBRTMYwu19WOx17E=", @@ -1090,7 +1136,7 @@ "type": "github" } }, - "nixpkgs_8": { + "nixpkgs_9": { "locked": { "lastModified": 1665087388, "narHash": "sha256-FZFPuW9NWHJteATOf79rZfwfRn5fE0wi9kRzvGfDHPA=", @@ -1106,21 +1152,6 @@ "type": "github" } }, - "nixpkgs_9": { - "locked": { - "lastModified": 1632864508, - "narHash": "sha256-d127FIvGR41XbVRDPVvozUPQ/uRHbHwvfyKHwEt5xFM=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "82891b5e2c2359d7e58d08849e4c89511ab94234", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "ref": "nixos-21.05-small", - "type": "indirect" - } - }, "nosys": { "locked": { "lastModified": 1667881534, @@ -1248,6 +1279,7 @@ }, "root": { "inputs": { + "crane": "crane", "flake-compat": "flake-compat", "flake-utils": "flake-utils", "nix": "nix", @@ -1255,10 +1287,29 @@ "nixpkgs-unstable": "nixpkgs-unstable", "opam-nix": "opam-nix", "opam-repository": "opam-repository_2", + "rust-overlay": "rust-overlay", "serokell-nix": "serokell-nix", "tezos": "tezos" } }, + "rust-overlay": { + "inputs": { + "nixpkgs": "nixpkgs_4" + }, + "locked": { + "lastModified": 1727317727, + "narHash": "sha256-yGYahXzCquyYEgf5GTtvtaN5hXbw20Ok2+o8uVxoaFs=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "a3d832f389606d7dc61a45b244c72ea472d1fcd4", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, "serokell-nix": { "inputs": { "deploy-rs": "deploy-rs", @@ -1268,7 +1319,7 @@ "gitignore-nix": "gitignore-nix", "haskell-nix": "haskell-nix", "nix": "nix_3", - "nixpkgs": "nixpkgs_10" + "nixpkgs": "nixpkgs_11" }, "locked": { "lastModified": 1691752608, @@ -1329,7 +1380,7 @@ ], "n2c": "n2c", "nixago": "nixago", - "nixpkgs": "nixpkgs_8", + "nixpkgs": "nixpkgs_9", "nosys": "nosys", "yants": "yants" }, diff --git a/flake.nix b/flake.nix index 2145bbc0b..e73fee2c7 100644 --- a/flake.nix +++ b/flake.nix @@ -16,6 +16,10 @@ opam-nix.url = "github:tweag/opam-nix"; + rust-overlay.url = "github:oxalica/rust-overlay"; + + crane.url = "github:ipetkov/crane"; + flake-compat.flake = false; opam-repository.url = "github:ocaml/opam-repository"; @@ -25,9 +29,10 @@ tezos.flake = false; }; - outputs = inputs@{ self, nixpkgs, nixpkgs-unstable, flake-utils, serokell-nix, nix, ... }: + outputs = inputs@{ self, nixpkgs, nixpkgs-unstable, flake-utils, serokell-nix, nix, rust-overlay, crane, ... }: let pkgs = import nixpkgs { system = "x86_64-linux"; }; + pkgs-unstable = import nixpkgs-unstable { system = "x86_64-linux"; overlays = [ rust-overlay.overlays.default ]; }; pkgs-darwin = nixpkgs-unstable.legacyPackages."aarch64-darwin"; protocols = nixpkgs.lib.importJSON ./protocols.json; meta = nixpkgs.lib.importJSON ./meta.json; @@ -39,6 +44,12 @@ filter = path: _: !(builtins.elem (baseNameOf path) [ "octez-dev-deps.opam" "tezos-time-measurement.opam" ]); }; + toolchain-version = pkgs-unstable.lib.strings.trim (builtins.readFile "${tezos}/rust-toolchain"); + + rust-toolchain = pkgs-unstable.rust-bin.stable.${toolchain-version}.default; + + craneLib = (crane.mkLib pkgs-unstable).overrideToolchain (p: p.rust-bin.stable.${toolchain-version}.default); + # FIXME Dirty hack! Find out how to remove next release tezos = pkgs.stdenv.mkDerivation { name = "tezos"; @@ -55,7 +66,7 @@ sources = { inherit tezos; inherit (inputs) opam-repository; }; - ocaml-overlay = import ./nix/build/ocaml-overlay.nix (inputs // { inherit sources protocols meta; }); + ocaml-overlay = import ./nix/build/ocaml-overlay.nix (inputs // { inherit sources protocols meta craneLib rust-toolchain; }); in pkgs-darwin.lib.recursiveUpdate { nixosModules = { diff --git a/nix/build/ocaml-overlay.nix b/nix/build/ocaml-overlay.nix index 97c5a732c..ef65f4bbd 100644 --- a/nix/build/ocaml-overlay.nix +++ b/nix/build/ocaml-overlay.nix @@ -1,7 +1,7 @@ # SPDX-FileCopyrightText: 2021-2022 Oxhead Alpha # SPDX-License-Identifier: LicenseRef-MIT-OA -{ sources, protocols, opam-nix, ... }: +{ sources, protocols, opam-nix, craneLib, rust-toolchain, ... }: self: super: let @@ -10,15 +10,11 @@ in with opam-nix.lib.${self.system}; let zcash-overlay = import ./zcash-overlay.nix; hacks = import ./hacks.nix; - octezSourcesResolved = - self.runCommand "resolve-octez-sources" {} '' - cp --no-preserve=all -Lr ${sources.tezos} $out - ''; octezScope = buildOpamProject' { repos = with sources; [opam-repository]; recursive = true; - resolveArgs = { }; - } octezSourcesResolved { }; + resolveArgs = {}; + } sources.tezos {}; in { octezPackages = (octezScope.overrideScope' (pkgs.lib.composeManyExtensions [ (_: # Nullify all the ignored protocols so that we don't build them @@ -31,19 +27,40 @@ in { pkg)) hacks zcash-overlay - (final: prev: { - tezos-rust-libs = prev.tezos-rust-libs.overrideAttrs (drv: { - postInstall = - drv.postInstall + (let - rust-types-h = pkgs.fetchurl { - url = "https://gitlab.com/tezos/tezos-rust-libs/-/raw/v1.4/librustzcash/include/rust/types.h"; - sha256 = "sha256-Q2lEV7JfPpFwfS/fcV7HDbBUSIGovasr7/bcANRuMZA="; - }; - in '' - mkdir -p $out/include/rust - cp ${rust-types-h} $out/include/rust/types.h - ''); - }); + (final: prev: + let + vendored-deps = + let + src = sources.tezos; + commonArgs = { + inherit src; + buildInputs = [ pkgs.ocaml ]; + cargoToml = "${src}/src/rust_deps/Cargo.toml"; + cargoLock = "${src}/src/rust_deps/Cargo.lock"; + postUnpack = '' + cd $sourceRoot/src/rust_deps + sourceRoot="." + ''; + strictDeps = true; + OCAMLOPT = "${pkgs.ocaml}/bin/ocamlopt"; + OCAML_WHERE_PATH = "ocaml"; + OCTEZ_RUST_DEPS_NO_WASMER_HEADERS = true; + }; + in craneLib.vendorCargoDeps commonArgs; + + injectRustDeps = drv: { + buildInputs = drv.buildInputs ++ [ + vendored-deps + rust-toolchain + ]; + configurePhase = '' + export PATH="${rust-toolchain}/bin:$PATH" + cat ${vendored-deps}/config.toml >> ./src/rust_deps/.cargo/config.toml + '' + drv.configurePhase; + }; + in { + octez-rust-deps = prev.octez-rust-deps.overrideAttrs injectRustDeps; + octez-l2-libs = prev.octez-l2-libs.overrideAttrs injectRustDeps; }) ])); }