From 9a0cc5004672561245e6fbe6731b2dc04b1c9c5f Mon Sep 17 00:00:00 2001 From: Jeb Bearer Date: Fri, 29 Mar 2024 15:42:38 -0400 Subject: [PATCH] Fix nix build --- .envrc | 5 ++++ .github/workflows/build_nix.yml | 8 ++--- .gitignore | 3 ++ Cargo.toml | 3 +- flake.nix | 53 +++++---------------------------- shell.nix | 13 ++++++++ 6 files changed, 33 insertions(+), 52 deletions(-) create mode 100644 .envrc create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..c6fc575 --- /dev/null +++ b/.envrc @@ -0,0 +1,5 @@ +use nix +watch_file flake.nix +watch_file shell.nix +watch_file flake.lock +watch_file .envrc diff --git a/.github/workflows/build_nix.yml b/.github/workflows/build_nix.yml index 8b9b938..27263fb 100644 --- a/.github/workflows/build_nix.yml +++ b/.github/workflows/build_nix.yml @@ -24,10 +24,10 @@ jobs: - name: Install Nix uses: cachix/install-nix-action@v26 - # - uses: cachix/cachix-action@v12 - # with: - # name: espresso-systems-private - # authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + - uses: cachix/cachix-action@v12 + with: + name: espresso-systems-private + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' - name: Cache cargo uses: actions/cache@v4 diff --git a/.gitignore b/.gitignore index 196e176..f3415af 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ Cargo.lock # Added by cargo /target + +# generated by nix-pre-commit-hooks +/.pre-commit-config.yaml diff --git a/Cargo.toml b/Cargo.toml index cb4c22b..afc2a52 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,12 +7,11 @@ authors = ["Espresso Systems "] repository = "https://github.com/EspressoSystems/versioned-binary-serialization.git" description = "Version-tagged serialization adaptor with compile-time version checking" license = "MIT" - # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] anyhow = "1.0" -derive_more = "0.99" bincode = "1.3" +derive_more = "0.99" serde = { version = "1.0", features = ["derive"] } serde_with = "3.4" diff --git a/flake.nix b/flake.nix index 8403406..f71dfd1 100644 --- a/flake.nix +++ b/flake.nix @@ -26,17 +26,11 @@ inputs.pre-commit-hooks.inputs.flake-utils.follows = "flake-utils"; inputs.pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs"; - inputs.poetry2nixFlake = { - url = "github:nix-community/poetry2nix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - - outputs = { self, nixpkgs, flake-utils, rust-overlay, pre-commit-hooks, poetry2nixFlake, ... }: + outputs = { self, nixpkgs, flake-utils, rust-overlay, pre-commit-hooks, ... }: flake-utils.lib.eachDefaultSystem (system: let overlays = [ (import rust-overlay) ]; pkgs = import nixpkgs { inherit system overlays; }; - poetry2nix = poetry2nixFlake.lib.mkPoetry2Nix { inherit pkgs; }; rustToolchain = pkgs.rust-bin.stable.latest.minimal.override { extensions = [ "rustfmt" "clippy" "llvm-tools-preview" "rust-src" ]; }; @@ -54,10 +48,6 @@ cargo-udeps cargo-sort cmake - - # `postgresql` defaults to an older version (15), so we select the latest version (16) - # explicitly. - postgresql_16 ] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security darwin.apple_sdk.frameworks.CoreFoundation @@ -96,8 +86,6 @@ license = with licenses; [ mit asl20 ]; }; }; - pythonEnv = poetry2nix.mkPoetryEnv { projectDir = ./.; }; - myPython = with pkgs; [ poetry pythonEnv ]; shellHook = '' # Prevent cargo aliases from using programs in `~/.cargo` to avoid conflicts with rustup # installations. @@ -109,6 +97,8 @@ RUST_BACKTRACE = 1; RUST_LOG = "info"; RUSTFLAGS=""; + # Use a distinct target dir for builds from within nix shells. + CARGO_TARGET_DIR = "target/nix"; in { checks = { pre-commit-check = pre-commit-hooks.lib.${system}.run { @@ -132,33 +122,6 @@ entry = "cargo clippy --workspace --all-features --all-targets -- -D clippy::dbg-macro"; pass_filenames = false; }; - license-header-c-style = { - enable = true; - description = - "Ensure files with c-style comments have license header"; - entry = '' - insert_license --license-filepath .license-header.txt --comment-style "//"''; - types_or = [ "rust" ]; - pass_filenames = true; - }; - license-header-hash = { - enable = true; - description = - "Ensure files with hash style comments have license header"; - entry = '' - insert_license --license-filepath .license-header.txt --comment-style "#"''; - types_or = [ "bash" "python" "toml" "nix" ]; - excludes = [ "poetry.lock" ]; - pass_filenames = true; - }; - license-header-html = { - enable = true; - description = "Ensure markdown files have license header"; - entry = '' - insert_license --license-filepath .license-header.txt --comment-style ""''; - types_or = [ "markdown" ]; - pass_filenames = true; - }; }; }; }; @@ -172,20 +135,18 @@ nixWithFlakes nixpkgs-fmt git - mdbook # make-doc, documentation generation - protobuf rustToolchain - ] ++ myPython ++ rustDeps; + ] ++ rustDeps; - inherit RUST_SRC_PATH RUST_BACKTRACE RUST_LOG RUSTFLAGS; + inherit RUST_SRC_PATH RUST_BACKTRACE RUST_LOG RUSTFLAGS CARGO_TARGET_DIR; }; devShells = { perfShell = pkgs.mkShell { shellHook = shellHook; buildInputs = with pkgs; - [ nixWithFlakes cargo-llvm-cov rustToolchain protobuf ] ++ rustDeps; + [ nixWithFlakes cargo-llvm-cov rustToolchain ] ++ rustDeps; - inherit RUST_SRC_PATH RUST_BACKTRACE RUST_LOG RUSTFLAGS; + inherit RUST_SRC_PATH RUST_BACKTRACE RUST_LOG RUSTFLAGS CARGO_TARGET_DIR; }; }; }); diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..9eb132a --- /dev/null +++ b/shell.nix @@ -0,0 +1,13 @@ +(import + ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { + src = ./.; + }).shellNix