From b706f77a361ee8c6000b2dad844fdcde87e776ed Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Fri, 29 Sep 2023 15:45:43 -0600 Subject: [PATCH] add nix build for `mev-rs` (and clean up devshell) --- flake.lock | 134 +++++++++++++++++++++++++++++++++++++++++++++++++--- flake.nix | 25 ++++++++-- nix/mev.nix | 5 +- shell.nix | 10 ++-- 4 files changed, 153 insertions(+), 21 deletions(-) diff --git a/flake.lock b/flake.lock index 24c999b4..4124655b 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,44 @@ { "nodes": { + "crane": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ], + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1695511445, + "narHash": "sha256-mnE14re43v3/Jc50Jv0BKPMtEk7FEtDSligP6B5HwlI=", + "owner": "ipetkov", + "repo": "crane", + "rev": "3de322e06fc88ada5e3589dc8a375b73e749f512", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -18,26 +57,94 @@ "type": "github" } }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1694422566, - "narHash": "sha256-lHJ+A9esOz9vln/3CJG23FV6Wd2OoOFbDeEs4cMGMqc=", + "lastModified": 1695806987, + "narHash": "sha256-fX5kGs66NZIxCMcpAGIpxuftajHL8Hil1vjHmjjl118=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3a2786eea085f040a66ecde1bc3ddc7099f6dbeb", + "rev": "f3dab3509afca932f3f4fd0908957709bb1c1f57", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-unstable", + "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" } }, "root": { "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "crane": "crane", + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay_2" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "crane", + "flake-utils" + ], + "nixpkgs": [ + "crane", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1695003086, + "narHash": "sha256-d1/ZKuBRpxifmUf7FaedCqhy0lyVbqj44Oc2s+P5bdA=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "b87a14abea512d956f0b89d0d8a1e9b41f3e20ff", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "rust-overlay_2": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1695953491, + "narHash": "sha256-TO26givgQP4F8rXPu5rgP2K82mJyNN+X491FJYLra2s=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "fb948d8eaf5d7c720dec92eb9c75193963fa0c52", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" } }, "systems": { @@ -54,6 +161,21 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index dd248803..e3f17b11 100644 --- a/flake.nix +++ b/flake.nix @@ -2,18 +2,33 @@ description = "flake for `mev-rs` repo"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; flake-utils.url = "github:numtide/flake-utils"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + }; + }; + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; - outputs = { self, flake-utils, nixpkgs }: + outputs = { self, flake-utils, nixpkgs, rust-overlay, crane }: flake-utils.lib.eachDefaultSystem (system: let - pkgs = import nixpkgs { inherit system; }; - lib = pkgs.lib; + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; + mev = pkgs.callPackage ./nix/mev.nix { inherit pkgs; crane = craneLib; }; in { - devShells.default = import ./shell.nix { inherit pkgs lib; }; + packages.mev = mev; + devShells.default = import ./shell.nix { inherit pkgs rustToolchain; }; }); } diff --git a/nix/mev.nix b/nix/mev.nix index 4d4eec6e..2d29198b 100644 --- a/nix/mev.nix +++ b/nix/mev.nix @@ -5,10 +5,7 @@ let pname = "mev-rs"; src = crane.cleanCargoSource (crane.path ../.); buildInputs = [ ] ++ lib.optionals pkgs.stdenv.isDarwin [ - libiconv - ]; - nativeBuildInputs = [ - # pkgs.rustPlatform.bindgenHook + darwin.apple_sdk.frameworks.Network ]; }; cargoArtifacts = crane.buildDepsOnly commonArgs; diff --git a/shell.nix b/shell.nix index 0ff298a8..ad111061 100644 --- a/shell.nix +++ b/shell.nix @@ -1,11 +1,9 @@ -{ pkgs, lib }: +{ pkgs, rustToolchain }: with pkgs; mkShell { - buildInputs = lib.lists.optionals stdenv.isDarwin [ - darwin.apple_sdk.frameworks.Network - ] ++ [ - iconv + buildInputs = [ + just mdbook - zlib + rustToolchain ]; }