From 07c82fbf2d49369ac4e47f93bb5fc38776e6a8d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Christiansen=20S=C3=B8rby?= Date: Sat, 27 Aug 2022 10:50:09 +0200 Subject: [PATCH] feat: Add nix flake setup with envrc --- .envrc | 6 ++++ Cargo.lock | 4 ++- flake.lock | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 88 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..7c7e899 --- /dev/null +++ b/.envrc @@ -0,0 +1,6 @@ +use_flake() { + watch_file flake.nix + watch_file flake.lock + eval "$(nix print-dev-env)" +} +use flake diff --git a/Cargo.lock b/Cargo.lock index 472e0e8..6d6eb14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5235,7 +5235,7 @@ dependencies = [ [[package]] name = "origintrail-parachain-runtime" -version = "1.0.1" +version = "1.0.2" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -5266,6 +5266,8 @@ dependencies = [ "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", + "pallet-treasury", + "pallet-vesting", "pallet-xcm", "parachain-info", "parity-scale-codec", diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..f2f1413 --- /dev/null +++ b/flake.lock @@ -0,0 +1,102 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1661581637, + "narHash": "sha256-Z1FtMPFoUUGqedmwpdXycRrQsVPvJk1LByOcd+FhTuc=", + "owner": "nix-community", + "repo": "fenix", + "rev": "962dafad624929bf713b6e9da38aeb8818da219e", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1656928814, + "narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "naersk": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1655042882, + "narHash": "sha256-9BX8Fuez5YJlN7cdPO63InoyBy7dm3VlJkkmTt6fS1A=", + "owner": "nix-community", + "repo": "naersk", + "rev": "cddffb5aa211f50c4b8750adbec0bbbdfb26bb9f", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1661361016, + "narHash": "sha256-Bjf6ZDnDc6glTwIIItvwfcaeJ5zWFM6GYfPajSArdUY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b784c5ae63dd288375af1b4d37b8a27dd8061887", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "fenix": "fenix", + "flake-utils": "flake-utils", + "naersk": "naersk", + "nixpkgs": "nixpkgs" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1661539193, + "narHash": "sha256-LJ+Ry218HavJKZDBpexiASLE4k1k4nhaZv8qb1YvG5Y=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "6bea872edd9523a06213270f68725c9fe33f3919", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..eafdd78 --- /dev/null +++ b/flake.nix @@ -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 + ]; + }); + }); +}