-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add nix flake setup with envrc
- Loading branch information
1 parent
1174d98
commit 07c82fb
Showing
4 changed files
with
199 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use_flake() { | ||
watch_file flake.nix | ||
watch_file flake.lock | ||
eval "$(nix print-dev-env)" | ||
} | ||
use flake |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
{ | ||
description = "OriginTrail parachain node"; | ||
inputs = { | ||
nixpkgs.url = "nixpkgs/nixos-unstable"; | ||
flake-utils = { | ||
url = "github:numtide/flake-utils"; | ||
inputs.nixpkgs.follows = "nixpkgs"; | ||
}; | ||
fenix = { | ||
url = "github:nix-community/fenix"; | ||
inputs.nixpkgs.follows = "nixpkgs"; | ||
}; | ||
naersk = { | ||
url = "github:nix-community/naersk"; | ||
inputs.nixpkgs.follows = "nixpkgs"; | ||
}; | ||
}; | ||
|
||
outputs = | ||
{ self | ||
, nixpkgs | ||
, flake-utils | ||
, naersk | ||
, fenix | ||
}: | ||
flake-utils.lib.eachDefaultSystem (system: | ||
let | ||
lib = nixpkgs.lib; | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
rust = fenix.packages.${system}.default; | ||
inherit (rust) cargo rustc; | ||
# Get a naersk with the input rust version | ||
naerskWithRust = rust: naersk.lib."${system}".override { | ||
inherit (rust) cargo rustc; | ||
}; | ||
env = with pkgs; { | ||
LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib"; | ||
PROTOC = "${protobuf}/bin/protoc"; | ||
ROCKSDB_LIB_DIR = "${rocksdb}/lib"; | ||
}; | ||
# Naersk using the default rust version | ||
buildRustProject = pkgs.makeOverridable ({ naersk ? naerskWithRust rust, ... } @ args: with pkgs; naersk.buildPackage ({ | ||
buildInputs = [ | ||
clang | ||
pkg-config | ||
] ++ lib.optionals stdenv.isDarwin [ | ||
darwin.apple_sdk.frameworks.Security | ||
]; | ||
copyLibs = true; | ||
copyBins = true; | ||
targets = [ ]; | ||
remapPathPrefix = | ||
true; # remove nix store references for a smaller output package | ||
} // env // args)); | ||
|
||
crateName = "origintrail-parachain"; | ||
root = ./.; | ||
# This is a wrapper around naersk build | ||
# Remember to add Cargo.lock to git for naersk to work | ||
project = buildRustProject { | ||
inherit root; | ||
copySources = [ "node" "pallets" "runtime" ]; | ||
}; | ||
# Running tests | ||
testProject = project.override { | ||
doCheck = true; | ||
}; | ||
in | ||
{ | ||
packages = { | ||
${crateName} = project; | ||
"${crateName}-test" = testProject; | ||
}; | ||
|
||
defaultPackage = self.packages.${system}.${crateName}; | ||
|
||
# `nix develop` | ||
devShell = pkgs.mkShell (env // { | ||
inputsFrom = builtins.attrValues self.packages.${system}; | ||
nativeBuildInputs = [ rustc cargo ]; | ||
buildInputs = with rust; [ | ||
fenix.packages.${system}.rust-analyzer | ||
pkgs.clippy | ||
rustfmt | ||
]; | ||
}); | ||
}); | ||
} |