Skip to content

Commit

Permalink
chore(nix): Initial flake
Browse files Browse the repository at this point in the history
  • Loading branch information
zvolin committed Feb 13, 2025
1 parent f59466a commit 88f8bb5
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 4 deletions.
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
];
};
};
}
97 changes: 97 additions & 0 deletions nix/devshells.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
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"
]
++ lib.optionals (channel == "stable") [
# android
"aarch64-linux-android"
"armv7-linux-androideabi"
"x86_64-linux-android"
"i686-linux-android"
# ios
"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))
];

# 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 = { };
}

0 comments on commit 88f8bb5

Please sign in to comment.