From bb65867fd6a08e9b21a65e3722f9b1fd614be5e1 Mon Sep 17 00:00:00 2001 From: Justin Restivo Date: Mon, 7 Mar 2022 16:07:59 -0500 Subject: [PATCH] feat: merge flake.nix --- flake.lock | 18 ++--- flake.nix | 65 +++++++++++++--- libp2p-networking/flake.lock | 117 ---------------------------- libp2p-networking/flake.nix | 145 ----------------------------------- 4 files changed, 63 insertions(+), 282 deletions(-) delete mode 100644 libp2p-networking/flake.lock delete mode 100644 libp2p-networking/flake.nix diff --git a/flake.lock b/flake.lock index dace8f6842..0bd572dc68 100644 --- a/flake.lock +++ b/flake.lock @@ -25,11 +25,11 @@ "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1644560676, - "narHash": "sha256-KBC2Fn6ynCIE2sUUmJiNPY2QDWeh9caP8M1RPiUW5nE=", + "lastModified": 1646634355, + "narHash": "sha256-ewRVQz8fyg130FeaVebsB/BhNN097Ew7wg+waNdPkBc=", "owner": "nix-community", "repo": "fenix", - "rev": "6fbfc2821a058eb820bb3742a762bbba5a99f0df", + "rev": "6fdda0faec538afde79431357ccc87d85c8783f4", "type": "github" }, "original": { @@ -56,11 +56,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1644486793, - "narHash": "sha256-EeijR4guVHgVv+JpOX3cQO+1XdrkJfGmiJ9XVsVU530=", + "lastModified": 1646470760, + "narHash": "sha256-dQISyucVCCPaFioUhy5ZgfBz8rOMKGI8k13aPDFTqEs=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "1882c6b7368fd284ad01b0a5b5601ef136321292", + "rev": "1fc7212a2c3992eedc6eedf498955c321ad81cc2", "type": "github" }, "original": { @@ -82,11 +82,11 @@ "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1644391473, - "narHash": "sha256-39Mhn0JxV8QHog+B2KjeMalblXP8DFU5rRVkLXZILGk=", + "lastModified": 1646591490, + "narHash": "sha256-/qKh4utesAjlyG8A3hEmSx+HBgh48Uje6ZRtUGz5f0g=", "owner": "rust-analyzer", "repo": "rust-analyzer", - "rev": "08348d79fa3ccb2aeeea87e758dcd5f1614c7ad8", + "rev": "5fae65dd28b450a437ebc800a410164c3af1d516", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 247a3a092a..5925581d43 100644 --- a/flake.nix +++ b/flake.nix @@ -21,13 +21,16 @@ outputs = { self, nixpkgs, flake-compat, utils, crate2nix, fenix }: utils.lib.eachDefaultSystem (system: let - fenixPackage = fenix.packages.${system}.stable.withComponents [ "cargo" "clippy" "rust-src" "rustc" "rustfmt"]; + fenixStable = fenix.packages.${system}.stable.withComponents [ "cargo" "clippy" "rust-src" "rustc" "rustfmt" ]; + # needed for compiling static binary + fenixMusl = with fenix.packages.${system}; combine [ (stable.withComponents [ "cargo" "clippy" "rustc" "rustfmt" ]) targets.x86_64-unknown-linux-musl.stable.rust-std]; + # needed to generate grcov graphs + fenixNightly = fenix.packages.${system}.latest.withComponents [ "cargo" "clippy" "rust-src" "rustc" "rustfmt" ]; rustOverlay = final: prev: { - inherit fenixPackage; - rustc = fenixPackage; - cargo = fenixPackage; - rust-src = fenixPackage; + rustc = fenixStable; + cargo = fenixStable; + rust-src = fenixStable; }; pkgs = import nixpkgs { @@ -55,22 +58,62 @@ rootFeatures = [ "demo" "docs" "blake3" "threshold_crypto/use-insecure-test-only-mock-crypto" ] ; defaultCrateOverrides = pkgs.defaultCrateOverrides // { # Crate dependency overrides go here + # pass in protobuf + prost-build = attrs: { + buildInputs = [ pkgs.protobuf ]; + PROTOC = "${pkgs.protobuf}/bin/protoc"; + PROTOC_INCLUDE = "${pkgs.protobuf}/include"; + }; + libp2p-core = attrs: { + buildInputs = [ pkgs.protobuf ]; + PROTOC = "${pkgs.protobuf}/bin/protoc"; + PROTOC_INCLUDE = "${pkgs.protobuf}/include"; + }; }; }; + + pkgsAndChecksList = pkgs.lib.mapAttrsToList (name: val: { packages.${name} = val.build; checks.${name} = val.build.override { runTests = true; }; }) project.workspaceMembers; + # programatically generate output packages based on what exists in the workspace + pkgsAndChecksAttrSet = pkgs.lib.foldAttrs (n: a: pkgs.lib.recursiveUpdate n a) {} pkgsAndChecksList; + + buildDeps = with pkgs; [ + cargo-audit nixpkgs-fmt git-chglog protobuf fenix.packages.${system}.rust-analyzer + ] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security pkgs.libiconv darwin.apple_sdk.frameworks.SystemConfiguration]; + in + pkgsAndChecksAttrSet // { - packages.${crateName} = project.workspaceMembers.phaselock.build; - checks.${crateName} = project.workspaceMembers.phaselock.build.override { - runTests = true; - }; - defaultPackage = self.packages.${system}.${crateName}; devShell = pkgs.mkShell { inputsFrom = builtins.attrValues self.packages.${system}; buildInputs = - with pkgs; [ cargo-audit nixpkgs-fmt git-chglog fenix.packages.${system}.rust-analyzer fenixPackage ]; + with pkgs; [ fenixStable ] ++ buildDeps; + }; + + devShells = { + # usage: compile a statically linked musl binary + staticShell = pkgs.mkShell { + shellHook = '' + ulimit -n 1024 + export RUSTFLAGS='-C target-feature=+crt-static' + export CARGO_BUILD_TARGET='x86_64-unknown-linux-musl' + ''; + buildInputs = + with pkgs; [ fenixMusl ] ++ buildDeps; + }; + + # usage: evaluate performance (grcov + flamegraph) + perfShell = pkgs.mkShell { + buildInputs = with pkgs; [ grcov flamegraph fd fenixNightly ] ++ buildDeps; + shellHook = '' + ulimit -n 1024 + export RUSTFLAGS='-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' + export RUSTDOCFLAGS='-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' + export CARGO_INCREMENTAL=0 + ''; + }; }; }); } diff --git a/libp2p-networking/flake.lock b/libp2p-networking/flake.lock deleted file mode 100644 index dab1992d01..0000000000 --- a/libp2p-networking/flake.lock +++ /dev/null @@ -1,117 +0,0 @@ -{ - "nodes": { - "crate2nix": { - "flake": false, - "locked": { - "lastModified": 1636361151, - "narHash": "sha256-PCyoPHYRG4gtgfBuk+N6qcPbc8EvooLBQ4tfeQjrjx0=", - "owner": "balsoft", - "repo": "crate2nix", - "rev": "08c87b1883cfc554a506cdfcbaa487b189cbbd22", - "type": "github" - }, - "original": { - "owner": "balsoft", - "ref": "balsoft/fix-broken-ifd", - "repo": "crate2nix", - "type": "github" - } - }, - "fenix": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ], - "rust-analyzer-src": "rust-analyzer-src" - }, - "locked": { - "lastModified": 1644301403, - "narHash": "sha256-taOPTgB1EFlj7oyG40mplff45QYMJeQ0/Pm4lLuBZ+A=", - "owner": "nix-community", - "repo": "fenix", - "rev": "035306bc8de70b8ed7d79f1fd15d3e2b32ef1dde", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "fenix", - "type": "github" - } - }, - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1641205782, - "narHash": "sha256-4jY7RCWUoZ9cKD8co0/4tFARpWB+57+r1bLLvXNJliY=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "b7547d3eed6f32d06102ead8991ec52ab0a4f1a7", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1643381941, - "narHash": "sha256-pHTwvnN4tTsEKkWlXQ8JMY423epos8wUOhthpwJjtpc=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "5efc8ca954272c4376ac929f4c5ffefcc20551d5", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "crate2nix": "crate2nix", - "fenix": "fenix", - "flake-compat": "flake-compat", - "nixpkgs": "nixpkgs", - "utils": "utils" - } - }, - "rust-analyzer-src": { - "flake": false, - "locked": { - "lastModified": 1644220273, - "narHash": "sha256-6zg648bgcZkcEeLjTXo+ESCR8DVgF9V4Hw7zjiv8OBY=", - "owner": "rust-analyzer", - "repo": "rust-analyzer", - "rev": "9b1978a3ed405c2a5ec34703914ec1878b599e14", - "type": "github" - }, - "original": { - "owner": "rust-analyzer", - "ref": "nightly", - "repo": "rust-analyzer", - "type": "github" - } - }, - "utils": { - "locked": { - "lastModified": 1638122382, - "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "74f7e4319258e287b0f9cb95426c9853b282730b", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/libp2p-networking/flake.nix b/libp2p-networking/flake.nix deleted file mode 100644 index c69a8c434e..0000000000 --- a/libp2p-networking/flake.nix +++ /dev/null @@ -1,145 +0,0 @@ -{ - description = "PhaseLock consensus library"; - - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - utils.url = "github:numtide/flake-utils"; - flake-compat = { - url = "github:edolstra/flake-compat"; - flake = false; - }; - crate2nix = { - url = "github:balsoft/crate2nix/balsoft/fix-broken-ifd"; - flake = false; - }; - fenix = { - url = "github:nix-community/fenix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - }; - - outputs = { self, nixpkgs, flake-compat, utils, crate2nix, fenix }: - utils.lib.eachDefaultSystem (system: - let - fenixStable = with fenix.packages.${system}; combine [ (stable.withComponents [ "cargo" "clippy" "rustc" "rustfmt" ]) targets.x86_64-unknown-linux-musl.stable.rust-std]; - fenixNightly = fenix.packages.${system}.latest.withComponents [ "cargo" "clippy" "rust-src" "rustc" "rustfmt" ]; - rustOverlay = final: prev: - { - rustcNightly = fenixNightly; - cargoNightly = fenixNightly; - rust-srcNightly = fenixNightly; - rustc = fenixStable; - cargo = fenixStable; - rust-src = fenixStable; - }; - - pkgs = import nixpkgs { - inherit system; - overlays = [ - rustOverlay - ]; - }; - - # DON'T FORGET TO PUT YOUR PACKAGE NAME HERE, REMOVING `throw` - crateName = "networking-demo"; - - inherit (import "${crate2nix}/tools.nix" { inherit pkgs; }) - generatedCargoNix; - - project = import - (generatedCargoNix { - name = crateName; - src = ./.; - }) - { - inherit pkgs; - defaultCrateOverrides = pkgs.defaultCrateOverrides // { - # Crate dependency overrides go here - prost-build = attrs: { - buildInputs = [ pkgs.protobuf ]; - PROTOC = "${pkgs.protobuf}/bin/protoc"; - PROTOC_INCLUDE = "${pkgs.protobuf}/include"; - }; - libp2p-core = attrs: { - buildInputs = [ pkgs.protobuf ]; - PROTOC = "${pkgs.protobuf}/bin/protoc"; - PROTOC_INCLUDE = "${pkgs.protobuf}/include"; - }; - networking-demo = attrs: { - buildInputs = (attrs.buildInputs or [ ]) ++ (pkgs.lib.optionals pkgs.stdenv.isDarwin [ pkgs.darwin.apple_sdk.frameworks.Security ]); - }; - }; - }; - - recent_flamegraph = pkgs.cargo-flamegraph.overrideAttrs (oldAttrs: rec { - src = pkgs.fetchFromGitHub { - owner = "flamegraph-rs"; - repo = "flamegraph"; - rev = "a9837efd8744dac853acbe3d476924083f26743d"; - sha256 = "sha256-Fek2AJ8mYYf92NBT0pmVBqK1BXmr6GdEqt2Rp8To8tI="; - }; - version = "master"; - cargoDeps = oldAttrs.cargoDeps.overrideAttrs (pkgs.lib.const { - name = "${oldAttrs.pname}-vendor.tar.gz"; - inherit src; - outputHash = "sha256-i9/Fe+JaCcdHw2CR0n4hULokDN2RvDAzgXNG2zAUFDg="; - }); - }); - # https://github.com/NixOS/nixpkgs/issues/149209 - grcov = pkgs.rustPlatform.buildRustPackage rec { - pname = "grcov"; - version = "v0.8.7"; - - doCheck = false; - - src = pkgs.fetchFromGitHub { - owner = "mozilla"; - repo = pname; - rev = version; - sha256 = "sha256-4McF9tLIjDCftyGI29pm/LnTUBVWG+pY5z+mGFKySQM="; - }; - - cargoSha256 = "sha256-CdsTAMiEK8udRoD9PQSC0jQbPkdynFL0Tdw5aAZUmsM="; - - meta = with pkgs.lib; { - description = "grcov collects and aggregates code coverage information for multiple source files."; - homepage = "https://github.com/mozilla/grcov"; - license = licenses.mpl20; - }; - }; - - buildDeps = with pkgs; [ - cargo-audit nixpkgs-fmt git-chglog protobuf - ] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security pkgs.libiconv darwin.apple_sdk.frameworks.SystemConfiguration]; - - in - { - packages.${crateName} = project.rootCrate.build; - checks.${crateName} = project.rootCrate.build.override { - runTests = true; - }; - - defaultPackage = self.packages.${system}.${crateName}; - - devShell = pkgs.mkShell { - shellHook = '' - ulimit -n 1024 - export RUSTFLAGS='-C target-feature=+crt-static' - export CARGO_BUILD_TARGET='x86_64-unknown-linux-musl' - ''; - buildInputs = - with pkgs; [ fenix.packages.${system}.rust-analyzer fenixStable ] ++ buildDeps; - }; - - devShells.perfShell = pkgs.mkShell { - buildInputs = with pkgs; [ grcov recent_flamegraph fd fenixNightly fenix.packages.${system}.rust-analyzer ] ++ buildDeps; - shellHook = '' - ulimit -n 1024 - export RUSTFLAGS='-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' - export RUSTDOCFLAGS='-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests' - export CARGO_INCREMENTAL=0 - ''; - }; - - }); -}