Skip to content

Commit

Permalink
flake.nix: use a Nix package to facilitate sharing (#2016)
Browse files Browse the repository at this point in the history
  • Loading branch information
Twey authored May 12, 2024
1 parent 0cbf23c commit dd41104
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 56 deletions.
35 changes: 35 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{ crane, pkgs }:
let
rust-toolchain = (pkgs.rust-bin.fromRustupToolchainFile
./toolchains/build/rust-toolchain.toml);
in ((crane.mkLib pkgs).overrideToolchain rust-toolchain).buildPackage {
pname = "linera";
src = ./.;
cargoExtraArgs = "-p linera-service";
nativeBuildInputs = with pkgs; [
clang
pkg-config
rocksdb
protobufc
];
buildInputs = with pkgs; [
clang.cc.lib
libiconv
nodejs
openssl
protobuf
];
checkInputs = with pkgs; [
# for native testing
jq
kubernetes-helm
kind
kubectl

# for Wasm testing
chromium
chromedriver
wasm-pack
];
passthru = { inherit rust-toolchain; };
}
83 changes: 56 additions & 27 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 13 additions & 29 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default";

# Rust
rust-overlay.url = "github:oxalica/rust-overlay";
crane.url = "github:ipetkov/crane";

# Dev tools
treefmt-nix.url = "github:numtide/treefmt-nix";
Expand All @@ -14,62 +17,43 @@
imports = [
inputs.treefmt-nix.flakeModule
];
perSystem = { config, self', pkgs, lib, system, rust-overlay, ... }:
perSystem = { config, self', inputs', pkgs, lib, system, ... }:
let
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
nonRustDeps = with pkgs; [
# for building
clang
libclang.lib
libiconv
nodejs
openssl
protobuf
pkg-config
rocksdb

# for testing
jq
kubernetes-helm
kind
kubectl

# for Wasm testing
chromium
chromedriver
wasm-pack
];
rustBuildToolchain = (pkgs.rust-bin.fromRustupToolchainFile
./toolchains/build/rust-toolchain.toml);
rustLintToolchain = (pkgs.rust-bin.fromRustupToolchainFile
./toolchains/lint/rust-toolchain.toml);
linera = pkgs.callPackage ./. { inherit (inputs) crane; };
in {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ (import inputs.rust-overlay) ];
};

packages.default = linera;

# Rust dev environment
devShells.default = pkgs.mkShell {
inputsFrom = [
config.treefmt.build.devShell
linera
];
shellHook = ''
# For rust-analyzer 'hover' tooltips to work.
export RUST_SRC_PATH=${rustBuildToolchain.availableComponents.rust-src}
export RUST_SRC_PATH=${linera.rust-toolchain.availableComponents.rust-src}
export LIBCLANG_PATH=${pkgs.libclang.lib}/lib
export PATH=$PWD/target/debug:~/.cargo/bin:$PATH
export ROCKSDB_LIB_DIR=${pkgs.rocksdb}/lib
'';
buildInputs = nonRustDeps;
nativeBuildInputs = with pkgs; [
rustBuildToolchain
rust-analyzer
];
};

devShells.lint = pkgs.mkShell {
nativeBuildInputs = [ rustLintToolchain ];
nativeBuildInputs = [
(pkgs.rust-bin.fromRustupToolchainFile
./toolchains/lint/rust-toolchain.toml)
];
};

# Add your auto-formatters here.
Expand Down

0 comments on commit dd41104

Please sign in to comment.