From 98f5787c92c8e86478687258637aed20905906a7 Mon Sep 17 00:00:00 2001 From: Michael Pontus Date: Thu, 25 Aug 2022 15:34:24 +0300 Subject: [PATCH 1/2] chore(flake): Override toolchain using `fenix.fromTemplateFile` This enables wasm target in Rust toolchain used to build the package. --- flake.nix | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/flake.nix b/flake.nix index b2d5eb67a8..5102ac971b 100644 --- a/flake.nix +++ b/flake.nix @@ -23,26 +23,20 @@ pkgs = inputs.nixpkgs.legacyPackages.${system}; cargoTOML = builtins.fromTOML (builtins.readFile ./Cargo.toml); - rustToolChainTOML = builtins.fromTOML (builtins.readFile ./rust-toolchain.toml); name = cargoTOML.package.name; # This is the program version. version = cargoTOML.package.version; - # This selects a nightly Rust version, based on the date. - nightly-date = pkgs.lib.strings.removePrefix "nightly-" rustToolChainTOML.toolchain.channel; - # This is the hash of the Rust toolchain at nightly-date, required for reproducibility. - nightly-sha256 = "sha256-CNMj0ouNwwJ4zwgc/gAeTYyDYe0botMoaj/BkeDTy4M="; - - # This instantiates a new Rust version based on nightly-date. + # Override the toolchain from Rust toolchain file + fenix = inputs.fenix.packages.${system}; + toolchain = fenix.fromToolchainFile { + file = ./rust-toolchain.toml; + sha256 = "sha256-CNMj0ouNwwJ4zwgc/gAeTYyDYe0botMoaj/BkeDTy4M="; + }; nightlyRustPlatform = pkgs.makeRustPlatform { - inherit - (inputs.fenix.packages.${system}.toolchainOf { - channel = "nightly"; - date = nightly-date; - sha256 = nightly-sha256; - }) - cargo rustc; + cargo = toolchain; + rustc = toolchain; }; # This is a mock git program, which just returns the commit-substr value. @@ -108,8 +102,6 @@ LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; PROTOC = "${pkgs.protobuf}/bin/protoc"; - SKIP_WASM_BUILD = 1; - doCheck = false; }; From 7d265eb93f658665187818e6c74d2b0e902ce50a Mon Sep 17 00:00:00 2001 From: Michael Pontus Date: Thu, 25 Aug 2022 16:53:36 +0300 Subject: [PATCH 2/2] chore(flake): use naersk to build rust package --- flake.lock | 21 +++++++++++++++++++++ flake.nix | 12 ++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/flake.lock b/flake.lock index 02c6bdb3e1..9c3a2ea7c2 100644 --- a/flake.lock +++ b/flake.lock @@ -56,6 +56,26 @@ "type": "github" } }, + "naersk": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1659610603, + "narHash": "sha256-LYgASYSPYo7O71WfeUOaEUzYfzuXm8c8eavJcel+pfI=", + "owner": "nmattia", + "repo": "naersk", + "rev": "c6a45e4277fa58abd524681466d3450f896dc094", + "type": "github" + }, + "original": { + "owner": "nmattia", + "repo": "naersk", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1658346836, @@ -77,6 +97,7 @@ "fenix": "fenix", "flake-utils": "flake-utils", "gitignore": "gitignore", + "naersk": "naersk", "nixpkgs": "nixpkgs" } }, diff --git a/flake.nix b/flake.nix index 5102ac971b..633ac20211 100644 --- a/flake.nix +++ b/flake.nix @@ -15,6 +15,10 @@ url = github:nix-community/fenix; inputs.nixpkgs.follows = "nixpkgs"; }; + naersk = { + url = github:nmattia/naersk; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = inputs : @@ -34,7 +38,7 @@ file = ./rust-toolchain.toml; sha256 = "sha256-CNMj0ouNwwJ4zwgc/gAeTYyDYe0botMoaj/BkeDTy4M="; }; - nightlyRustPlatform = pkgs.makeRustPlatform { + naersk' = pkgs.callPackage inputs.naersk { cargo = toolchain; rustc = toolchain; }; @@ -77,7 +81,7 @@ && builtins.all (name: builtins.baseNameOf path != name) ignoreList; in rec { - defaultPackage = nightlyRustPlatform.buildRustPackage { + defaultPackage = naersk'.buildPackage { pname = name; inherit version; @@ -103,6 +107,10 @@ LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; PROTOC = "${pkgs.protobuf}/bin/protoc"; + # Either this or `singleStep = true` is needed to build. + # See https://github.com/nix-community/naersk/issues/133 + copySources = ["runtime/development"]; + doCheck = false; };