forked from dfinity/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dfx.nix
107 lines (98 loc) · 2.9 KB
/
dfx.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
# This file defines all flavors of the dfx build:
# * lint and documentation
# * debug build
# * release build
#
# If you only intend to perform a release build, run:
# nix-build ./dfx.nix -A build
{ pkgs ? import ./nix { inherit system; }
, system ? builtins.currentSystem
, assets ? import ./assets.nix { inherit pkgs; }
}:
let
lib = pkgs.lib;
workspace = pkgs.buildDfinityRustPackage {
name = "dfinity-sdk-rust";
srcDir = ./.;
regexes = [
".*/assets/.*$"
".*\.rs$"
".*\.lalrpop$"
".*Cargo\.toml$"
".*Cargo\.lock$"
"^.cargo/config$"
];
cargoTestCommands = _: [
''cargo $cargo_options test $cargo_test_options --workspace''
];
override = attrs: {
preConfigure = (attrs.preConfigure or "") + ''
unset SDKROOT
'';
nativeBuildInputs = (
attrs.nativeBuildInputs or []
) ++ lib.optional pkgs.stdenv.isDarwin pkgs.pkgsStatic.libiconv;
};
};
# set DFX_ASSETS for the builds and shells
addAssets = ws:
# override all derivations and add DFX_ASSETS as an environment variable
(
lib.mapAttrs (
k: drv:
if !lib.isDerivation drv then drv else
drv.overrideAttrs (
_: {
DFX_ASSETS = assets;
}
)
) ws
);
# add a `standalone` target stripped of nix references
addStandalone = ws:
ws // {
standalone = pkgs.lib.standaloneRust
{
drv = ws.build;
exename = "dfx";
usePackager = false;
};
};
cc = pkgs.stdenv.cc;
# fixup the shell for more convenient developer use
fixShell = ws:
ws // {
shell =
pkgs.mkCompositeShell {
name = "dfinity-sdk-rust-env";
nativeBuildInputs = [
pkgs.agent-rs # for icx and icx-proxy
pkgs.rls
# wabt-sys needs file in path, as well as cc (for cmake).
pkgs.file
cc
pkgs.gettext
pkgs.coreutils
pkgs.libiconv
] ++ lib.optional pkgs.stdenv.isDarwin pkgs.stdenv.cc.bintools;
inputsFrom = [ ws.shell ];
shellHook = ''
# Set CARGO_HOME to minimize interaction with any environment outside nix
export CARGO_HOME=${if pkgs.lib.isHydra then "." else toString ./.}/.cargo-home
if [ ! -d "$CARGO_HOME" ]; then
mkdir -p $CARGO_HOME
echo "[net]
git-fetch-with-cli = true" > $CARGO_HOME/config
fi
# Set environment variable for debug version.
export DFX_TIMESTAMP_DEBUG_MODE_ONLY=$(date +%s)
# the presence of this var breaks brotli-sys compilation
unset SDKROOT
'';
};
};
in
fixShell (
addStandalone (addAssets workspace)
(throw "this argument is used to trigger the functor and shouldn't actually be evaluated.")
)