-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
102 lines (97 loc) · 3.22 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
# SPDX-FileCopyrightText: 2021 Eduardo Robles <[email protected]>
#
# SPDX-License-Identifier: AGPL-3.0-only
{
description = "Flake to test rust code";
inputs.rust-overlay.url = "github:oxalica/rust-overlay";
inputs.nixpkgs.url = "nixpkgs/nixos-22.05";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
outputs = { self, nixpkgs, flake-utils, rust-overlay, flake-compat }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
stdenv = pkgs.clangStdenv;
configureRustTargets = targets : pkgs
.rust-bin
.nightly
."2022-07-05"
.default
.override {
extensions = [ "rust-src" ];
${if (builtins.length targets) > 0 then "targets" else null} = targets;
};
rust-wasm = configureRustTargets [ "wasm32-unknown-unknown" ];
rust-system = configureRustTargets [];
# see https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/rust.section.md#importing-a-cargolock-file-importing-a-cargolock-file
cargoPatches = {
cargoLock = let
fixupLockFile = path: (builtins.readFile path);
in {
lockFileContents = fixupLockFile ./Cargo.lock.copy;
};
postPatch = ''
cp ${./Cargo.lock.copy} Cargo.lock
'';
};
buildRustPackageWithCargo = cargoArgs: pkgs.rustPlatform.buildRustPackage (cargoPatches // cargoArgs);
in rec {
packages.strand-wasm = buildRustPackageWithCargo {
pname = "strand-wasm";
version = "0.0.1";
src = ./.;
nativeBuildInputs = [
rust-wasm
pkgs.nodePackages.npm
pkgs.binaryen
pkgs.wasm-pack
pkgs.wasm-bindgen-cli
];
buildPhase = ''
echo 'Build: wasm-pack build'
wasm-pack build --mode no-install --out-name index --release --target web --features=wasmtest
'';
installPhase = "
# set HOME temporarily to fix npm pack
mkdir -p $out/temp_home
export HOME=$out/temp_home
echo 'Install: wasm-pack pack'
wasm-pack -v pack .
rm -Rf $out/temp_home
cp pkg/strand-*.tgz $out
";
};
packages.strand-lib = buildRustPackageWithCargo {
pname = "strand-lib";
version = "0.0.1";
src = ./.;
nativeBuildInputs = [
rust-system
];
};
defaultPackage = self.packages.${system}.strand-wasm;
# configure the dev shell
devShell = (
pkgs.mkShell.override { stdenv = pkgs.clangStdenv; }
) {
nativeBuildInputs =
defaultPackage.nativeBuildInputs;
buildInputs =
[
pkgs.bash
pkgs.reuse
pkgs.cargo-deny
pkgs.clippy
pkgs.pkg-config
pkgs.openssl
];
};
}
);
}