From 61121673b57ae8bd93e2546024d1d17579bf639c Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Mon, 23 Dec 2024 16:00:12 +0000 Subject: [PATCH 1/2] setup build env with nix --- flake.lock | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 103 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 219 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..c76d8b55c --- /dev/null +++ b/flake.lock @@ -0,0 +1,116 @@ +{ + "nodes": { + "crane": { + "locked": { + "lastModified": 1734808813, + "narHash": "sha256-3aH/0Y6ajIlfy7j52FGZ+s4icVX0oHhqBzRdlOeztqg=", + "owner": "ipetkov", + "repo": "crane", + "rev": "72e2d02dbac80c8c86bf6bf3e785536acf8ee926", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1733312601, + "narHash": "sha256-4pDvzqnegAfRkPwO3wmwBhVi/Sye1mzps0zHWYnP88c=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "205b12d8b7cd4802fbcb8e8ef6a0f1408781a4f9", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1734962367, + "narHash": "sha256-34EsaOV2FPGxEEdaQtzQSNXxJxwkycl72OyGyZhAl0s=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63e085d7fb326c044f752dcc9fb46877264442d1", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "release-24.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1733096140, + "narHash": "sha256-1qRH7uAUsyQI7R1Uwl4T+XvdNv778H0Nb5njNrqvylY=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5487e69da40cbd611ab2cadee0b4637225f7cfae.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5487e69da40cbd611ab2cadee0b4637225f7cfae.tar.gz" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-parts": "flake-parts", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1734834660, + "narHash": "sha256-bm8V+Cu8rWJA+vKQnc94mXTpSDgvedyoDKxTVi/uJfw=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "b070e6030118680977bc2388868c4b3963872134", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..06488ec3e --- /dev/null +++ b/flake.nix @@ -0,0 +1,103 @@ +{ + description = "sp1"; + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + nixpkgs.url = "github:NixOS/nixpkgs/release-24.11"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + crane.url = "github:ipetkov/crane"; + gitignore = { + url = "github:hercules-ci/gitignore.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + inputs@{ + flake-parts, + rust-overlay, + crane, + gitignore, + ... + }: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + + ]; + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + "x86_64-darwin" + ]; + perSystem = + { + config, + self', + inputs', + pkgs, + system, + ... + }: + let + craneLib = (crane.mkLib pkgs).overrideToolchain rust-toolchain; + rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain; + in + { + _module.args.pkgs = import inputs.nixpkgs { + inherit system; + overlays = with inputs; [ + rust-overlay.overlays.default + ]; + }; + devShells.default = pkgs.mkShell { + buildInputs = [ + rust-toolchain + ]; + }; + packages = + let + cargoArtifacts = craneLib.buildDepsOnly { + src = craneLib.cleanCargoSource ./.; + doCheck = false; + buildInputs = with pkgs; [ + openssl + openssl.dev + pkg-config + ]; + }; + + # do not depend on nix files and ignored, but still use bin precompiles + nixFilter = name: type: !(pkgs.lib.hasSuffix ".nix" name); + srcFilter = + src: + pkgs.lib.cleanSourceWith { + filter = nixFilter; + src = gitignore.lib.gitignoreSource src; + }; + in + { + default = craneLib.buildPackage rec { + inherit cargoArtifacts; + pname = "cargo-prove"; + name = pname; + doCheck = false; + src = srcFilter ./.; + meta = { + description = "cargo-prove"; + license = pkgs.lib.licenses.mit; + }; + cargoBuildCommand = "cargo build --release --package=sp1-cli --bin=${name}"; + installPhase = '' + mkdir -p $out/bin + cp target/release/${pname} $out/bin/${pname} + ''; + }; + }; + + formatter = pkgs.nixfmt-rfc-style; + }; + }; +} From 15afdae17e6189511712e89623e14b9af7333e7d Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Mon, 23 Dec 2024 17:02:03 +0000 Subject: [PATCH 2/2] devshell also needs ssl for sure --- flake.nix | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index 06488ec3e..3986ebce2 100644 --- a/flake.nix +++ b/flake.nix @@ -44,6 +44,11 @@ let craneLib = (crane.mkLib pkgs).overrideToolchain rust-toolchain; rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain; + buildInputs = with pkgs; [ + openssl + openssl.dev + pkg-config + ]; in { _module.args.pkgs = import inputs.nixpkgs { @@ -55,18 +60,14 @@ devShells.default = pkgs.mkShell { buildInputs = [ rust-toolchain - ]; + ] ++ buildInputs; }; packages = let cargoArtifacts = craneLib.buildDepsOnly { src = craneLib.cleanCargoSource ./.; doCheck = false; - buildInputs = with pkgs; [ - openssl - openssl.dev - pkg-config - ]; + inherit buildInputs; }; # do not depend on nix files and ignored, but still use bin precompiles