Skip to content

Commit

Permalink
feat: Add nix flake setup with envrc
Browse files Browse the repository at this point in the history
  • Loading branch information
Anderssorby committed Aug 27, 2022
1 parent 1174d98 commit cc5c589
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .envrc
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
4 changes: 3 additions & 1 deletion Cargo.lock

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

102 changes: 102 additions & 0 deletions flake.lock

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

92 changes: 92 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
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};
fenix-pkgs = fenix.packages.${system};
rust = with fenix-pkgs; combine [
default.toolchain
targets.wasm32-unknown-unknown.latest.toolchain
];
# Get a naersk with the input rust version
naerskWithRust = rust: naersk.lib."${system}".override {
rustc = rust;
cargo = rust;
};
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 = [ rust ];
buildInputs = [
fenix-pkgs.rust-analyzer
pkgs.clippy
fenix-pkgs.default.rustfmt
];
});
});
}

0 comments on commit cc5c589

Please sign in to comment.