Skip to content

Commit

Permalink
Merge pull request #40 from EspressoSystems/fix/nix
Browse files Browse the repository at this point in the history
Fix nix build
  • Loading branch information
nyospe authored May 29, 2024
2 parents 5acf179 + 9a0cc50 commit 28854a0
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 52 deletions.
5 changes: 5 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use nix
watch_file flake.nix
watch_file shell.nix
watch_file flake.lock
watch_file .envrc
8 changes: 4 additions & 4 deletions .github/workflows/build_nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ Cargo.lock
# Added by cargo

/target

# generated by nix-pre-commit-hooks
/.pre-commit-config.yaml
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ authors = ["Espresso Systems <[email protected]>"]
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"
53 changes: 7 additions & 46 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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" ];
};
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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 {
Expand All @@ -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;
};
};
};
};
Expand All @@ -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;
};
};
});
Expand Down
13 changes: 13 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 28854a0

Please sign in to comment.