Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(nix): Initial flake #542

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
watch_file nix

use flake
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target

/.env

/.direnv
6 changes: 3 additions & 3 deletions cli/js/package-lock.json

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

97 changes: 97 additions & 0 deletions flake.lock

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

24 changes: 24 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
fenix.url = "github:nix-community/fenix";
fenix.inputs.nixpkgs.follows = "nixpkgs";
};

outputs =
inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"aarch64-linux"
"aarch64-darwin"
"x86_64-linux"
];
perSystem = {
imports = [
./nix/devshells.nix
./nix/packages.nix
];
};
};
}
99 changes: 99 additions & 0 deletions nix/devshells.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
inputs',
pkgs,
lib,
...
}:

let
fenix = inputs'.fenix.packages;

# creates list of components taken from a toolchain for given channel
rustComponents =
channel:
[
"rustc"
"cargo"
"clippy"
"rustfmt"
]
++ lib.optionals (channel == "stable") [
"rust-analyzer"
];

# creates list of the extra targets to be installed for given channel
rustExtraTargets =
channel:
[
"wasm32-unknown-unknown"
]
# android
++ lib.optionals (channel == "stable") [
"aarch64-linux-android"
"armv7-linux-androideabi"
"x86_64-linux-android"
"i686-linux-android"
]
# ios
++ lib.optionals (pkgs.stdenv.isDarwin && channel == "stable") [
"aarch64-apple-ios"
"aarch64-apple-ios-sim"
];

# creates toolchain configuration for given channel
rustToolchain =
channel:
fenix.combine [
# components
(fenix."${channel}".withComponents (rustComponents channel))
# extra targets
(lib.lists.map (target: fenix.targets."${target}"."${channel}".rust-std) (rustExtraTargets channel))
];

# rustup-like-ish wrapper for cargo to allow `+channel` syntax
cargoWrapper = pkgs.writeShellScriptBin "cargo" ''
case "$1" in
"+stable")
shift
exec env PATH="${rustToolchain "stable"}/bin:$PATH" cargo "$@"
;;
"+nightly")
shift
exec env PATH="${rustToolchain "latest"}/bin:$PATH" cargo "$@"
;;
"+"*)
echo "Channel $1 not installed. You may need to add it to the devShell" >&2
exit 1
;;
*)
exec env PATH="${rustToolchain "stable"}/bin:$PATH" cargo "$@"
;;
esac
'';
in
{
devShells.default = pkgs.mkShell {
packages = with pkgs; [
# c/gnu base
gnumake
pkg-config
stdenv

# rust - toolchain
cargoWrapper # first in PATH, to be invoked instead one from toolchain
(rustToolchain "stable")
# rust - wasm
binaryen # wasm-opt
wasm-bindgen-cli_0_2_100
wasm-pack
# rust - other
cargo-edit
cargo-ndk
cargo-udeps

# javascript
nodejs
nodePackages.typescript-language-server
];
};
}
5 changes: 5 additions & 0 deletions nix/packages.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{ ... }:

{
packages.default = { };
}