-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathflake.nix
117 lines (103 loc) · 3.43 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
cargo2nix.url = "github:cargo2nix/cargo2nix/release-0.11.0";
cargo2nix.inputs.nixpkgs.follows = "nixpkgs";
# rust-overlay.url = "github:oxalica/rust-overlay";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = inputs: with inputs;
flake-utils.lib.eachDefaultSystem (system:
let
rustPackagesOverlays = [
cargo2nix.overlays.default
# rust-overlay.overlays.default
];
nodePackagesOverlays = [
(final: prev: {
nodejs = prev.nodejs-18_x;
})
];
pkgs = import nixpkgs {
inherit system;
overlays = rustPackagesOverlays
++ nodePackagesOverlays;
};
#pkgs-wasm = import nixpkgs {
# inherit system;
# crossSystem = {
# config = "wasm32-wasi";
# # Nixpkgs currently only supports LLVM lld linker for wasm32-wasi.
# useLLVM = true;
# };
# overlays = rustPackagesOverlays
# ++ nodePackagesOverlays;
#};
rustVersion = "1.61.0";
# when u want to use rust-overlay
# rustWithWasmTarget = pkgs.rust-bin.stable.${rustVersion}.minimal.override {
# targets = [
# "wasm32-wasi"
# ];
# };
rustPackageSets = {
inherit rustVersion;
rustChannel = "stable";
rustProfile = "minimal";
# extraRustComponents = [ "rust-std" ];
workspaceSrc = ./swc;
# the file Cargo.nix was provided by command cargo2nix in swc directory
packageFun = import ./swc/Cargo.nix;
# target = "wasm32-unknown-unknown";
target = "wasm32-wasi";
};
rustPkgs = pkgs.rustBuilder.makePackageSet rustPackageSets;
# TODO
# cargo2nix targeted to wasm32-wasi
# rustPkgs-wasm = pkgs-wasm.rustBuilder.makePackageSet rustPackageSets;
in
rec {
# nix flake check
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
eslint.enable = true;
rustfmt.enable = true;
prettier.enable = true;
nixpkgs-fmt.enable = true;
};
};
};
# nix develop
#
# OR with current shell
#
# nix develop -C $SHELL
devShells.default = rustPkgs.workspaceShell {
name = "fetch_macro-devShell";
shellHook = ''
echo "Welcome to fetch.macro devShell 🛠️"
echo ""
echo "Commands -------------------------"
echo " yarn build - to build swc_plugin_fetch_macro."
echo " yarn test - to run test for fetch.macro in nodejs and rust."
echo "----------------------------------"
echo ""
echo "pre-commit-hooks status:"
'' + checks.pre-commit-check.shellHook;
packages = with pkgs; [
nodejs
nodePackages.yarn
# pkgs.cargo2nix
];
};
packages = {
swc_plugin_fetch_macro = (rustPkgs.workspace.swc_plugin_fetch_macro { }).bin;
default = packages.swc_plugin_fetch_macro;
};
}
);
}