forked from anoma/namada
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flakes are a new (experimental) of Nix. Here we add a `flake.nix` for the repository, which allows us to use its outputs easily elsewhere. For example, you could say `nix run github:anoma/anoma -- client` on any machine to launch the anoma client from scratch. - The `Cargo.nix` and `crate-checksums.json` files (created with `crate2nix`) are now checked in git, because flakes' evaluation is stricter in that untracked files are not available in expressions. Another option would be to do IFD with `crate2nix`, but I couldn't get this to work because of the brittle Cargo dependency vendoring. This is hardly a Nix issue though; `cargo vendor` also fails. - Added a `generateCargoNix` derivation for updating the generated files: `nix run .#generateCargoNix`. - Replaced `shell.nix` and `default.nix` with `flake-compat` shims. This means that `nix-build` and `nix-shell` work very much like they used to. - Added `scripts/ci/nix-check.sh` which checks the flake functionality. This is not yet integrated to the CI, though.
- Loading branch information
1 parent
1e17942
commit 5babb40
Showing
17 changed files
with
478 additions
and
116 deletions.
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
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 |
---|---|---|
@@ -1,30 +1,13 @@ | ||
{ pkgs ? import ./nix { } | ||
# Allows specifying Rust features for anoma crates. | ||
, features ? ["std" "ABCI"] | ||
# Allows overriding Tendermint derivation. | ||
, tendermint ? pkgs.tendermint | ||
, ... }: | ||
let | ||
packages = rec { | ||
apps = pkgs.cargoNix.workspaceMembers.anoma_apps.build.override { inherit features; }; | ||
|
||
# By default we want to have executables that have the correct "tendermint" and | ||
# "anoma*" executables available in PATH no matter how the user calls anoma etc. | ||
anoma = pkgs.runCommandNoCC "anoma" { | ||
nativeBuildInputs = [ pkgs.makeWrapper ]; | ||
} '' | ||
mkdir -p $out/bin | ||
for exe in ${apps}/bin/* ${tendermint}/bin/*; do | ||
makeWrapper $exe $out/bin/$(basename $exe) \ | ||
--prefix PATH : ${apps}/bin:${tendermint}/bin | ||
done | ||
''; | ||
|
||
docs = pkgs.callPackage ./docs { }; | ||
|
||
wasm = pkgs.runCommand "anoma-wasm" { } '' | ||
mkdir -p $out/wasm | ||
cp ${./wasm/checksums.json} $out/wasm/checksums.json | ||
''; | ||
}; | ||
in packages | ||
# NOTE the "anoma" and "wasm" top-level atrtibutes + the "features" can be | ||
# removed when all code that use this default.nix is adapted. | ||
{ features ? [ "default" ], ... }: | ||
let lf = (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 = ./.; | ||
}).defaultNix; in | ||
lf // { inherit (lf.packages.${builtins.currentSystem}) anoma wasm; } |
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 |
---|---|---|
|
@@ -7,5 +7,5 @@ In short: | |
Using Nix: | ||
|
||
```bash | ||
nix-shell --run "make serve" | ||
nix develop ..#anoma-docs -c make serve | ||
``` |
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
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,86 @@ | ||
{ | ||
description = "Anoma"; | ||
|
||
inputs.flake-utils.url = "github:numtide/flake-utils"; | ||
inputs.rust-overlay.url = "github:oxalica/rust-overlay"; | ||
inputs.flake-compat = { | ||
url = "github:edolstra/flake-compat"; | ||
flake = false; | ||
}; | ||
|
||
|
||
outputs = { self, nixpkgs, flake-utils, rust-overlay, flake-compat }: | ||
let | ||
supportedSystems = [ "x86_64-linux" "x86_64-darwin" ]; | ||
in | ||
|
||
with nixpkgs.lib; | ||
with flake-utils.lib; | ||
|
||
eachSystem supportedSystems (system: | ||
|
||
let | ||
overlays = [ (import rust-overlay) ] ++ import nix/overlays.nix; | ||
|
||
pkgs = import nixpkgs { inherit system overlays; }; | ||
|
||
cargoNix = pkgs.cargoNixWith [ "default" ]; | ||
cargoNix-ABCI-plus-plus = pkgs.cargoNixWith [ "ABCI-plus-plus" ]; | ||
|
||
# By default we want to have executables that have the correct "tendermint" and | ||
# "anoma*" executables available in PATH no matter how the user calls `anoma`, | ||
# `anoma` calls `anoman`, `anoman` calls `tendermint` and so on. | ||
mkAnoma = apps: pkgs.runCommandNoCC "anoma" { nativeBuildInputs = [ pkgs.makeWrapper ]; } '' | ||
mkdir -p $out/bin | ||
for exe in ${apps}/bin/* ${pkgs.tendermint}/bin/*; do | ||
makeWrapper $exe $out/bin/$(basename $exe) \ | ||
--prefix PATH : ${apps}/bin:${pkgs.tendermint}/bin | ||
done | ||
''; | ||
in | ||
{ | ||
defaultApp = self.apps.${system}.anoma; | ||
|
||
apps = { | ||
anoma = mkApp { drv = self.packages.${system}.anoma; }; | ||
generateCargoNix = mkApp { drv = pkgs.generateCargoNix [ "default" ]; }; | ||
generateCargoNixABCI-plus-plus = mkApp { drv = pkgs.generateCargoNix [ "ABCI-plus-plus" ]; }; | ||
}; | ||
|
||
devShell = with pkgs; pkgs.mkShell { | ||
packages = [ | ||
cargoWrapper | ||
using-nightly | ||
rustfmt | ||
clippy | ||
miri | ||
rustc | ||
clang | ||
llvmPackages.libclang | ||
protobuf | ||
openssl | ||
# Needed to build WASM modules (provides `wasm-opt`) | ||
binaryen | ||
# Needed at runtime | ||
tendermint | ||
] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security ]; | ||
LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib"; | ||
PROTOC = "${protobuf}/bin/protoc"; | ||
PROTOC_INCLUDE = "${protobuf}/include"; | ||
}; | ||
|
||
defaultPackage = self.packages.${system}.anoma; | ||
|
||
packages = { | ||
anoma = mkAnoma cargoNix.workspaceMembers.anoma_apps.build; | ||
"anoma:ABCI-plus-plus" = mkAnoma cargoNix-ABCI-plus-plus.workspaceMembers.anoma_apps.build; | ||
|
||
inherit (pkgs) wasm anoma-docs; | ||
|
||
# wasm src build - broken | ||
#inherit (pkgs) anoma-wasm; | ||
} | ||
// mapAttrs' (n: v: nameValuePair ("rust_" + n) v.build) cargoNix.workspaceMembers | ||
// mapAttrs' (n: v: nameValuePair ("rust_" + n + ":ABCI-plus-plus") v.build) cargoNix-ABCI-plus-plus.workspaceMembers; | ||
}); | ||
} |
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
Oops, something went wrong.