Skip to content

Commit 9a4f412

Browse files
authored
Merge pull request stacks-network#5849 from stacks-network/feat/nix_build_shell
Feat: build with `nix`
2 parents 6367b83 + b4e0f72 commit 9a4f412

File tree

4 files changed

+313
-1
lines changed

4 files changed

+313
-1
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
88
## [Unreleased]
99

1010
### Added"
11-
- Add fee information to transaction log ending with "success" or "skipped", while building a new block
11+
- Add fee information to transaction log ending with "success" or "skipped", while building a new block
1212

1313
### Changed
1414

contrib/nix/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# `nix` flake
2+
3+
Build `stacks-node` and `stacks-signer` by pointing to the `flake.nix` file in
4+
this directory. For instance, from the root directory: `nix build
5+
'./contrib/nix'`.
6+
7+
## Installing `nix`
8+
9+
Follow the [official documentation](https://nix.dev/install-nix) or use the
10+
[Determinate Nix Installer](https://github.com/DeterminateSystems/nix-installer).
11+
12+
## Using `direnv`
13+
14+
If using `direnv`, from the root directory of this repository:
15+
16+
```bash
17+
echo "use flake ./contrib/nix/" > .envrc
18+
direnv allow
19+
```
20+
21+
This will provide a `sh` environment with required dependencies (e.g., `bitcoind`) available.

contrib/nix/flake.lock

+101
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/nix/flake.nix

+190
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
{
2+
description = "stacks-core";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
6+
systems.url = "github:nix-systems/default";
7+
8+
flake-utils = {
9+
url = "github:numtide/flake-utils";
10+
inputs.systems.follows = "systems";
11+
};
12+
13+
rust-overlay = {
14+
url = "github:oxalica/rust-overlay";
15+
inputs.nixpkgs.follows = "nixpkgs";
16+
};
17+
18+
crane = {
19+
url = "github:ipetkov/crane";
20+
};
21+
22+
};
23+
24+
outputs =
25+
{
26+
nixpkgs,
27+
flake-utils,
28+
rust-overlay,
29+
crane,
30+
...
31+
}:
32+
flake-utils.lib.eachDefaultSystem (
33+
system:
34+
let
35+
overlays = [ (import rust-overlay) ];
36+
pkgs = import nixpkgs {
37+
inherit system overlays;
38+
};
39+
40+
inherit (pkgs) lib;
41+
42+
toolchain = pkgs.rust-bin.fromRustupToolchainFile ../../rust-toolchain;
43+
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
44+
45+
name = "stacks-core";
46+
47+
versions = (builtins.fromTOML (builtins.readFile ../../versions.toml));
48+
version = versions.stacks_node_version;
49+
50+
# Common arguments can be set here to avoid repeating them later
51+
commonArgs = {
52+
strictDeps = true;
53+
54+
buildInputs =
55+
[
56+
# Add additional build inputs here
57+
]
58+
++ lib.optionals pkgs.stdenv.isDarwin [
59+
# Darwin specific inputs
60+
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
61+
];
62+
};
63+
64+
# Build *just* the cargo dependencies, so we can reuse
65+
# all of that work (e.g. via cachix) when running in CI
66+
cargoArtifacts = craneLib.buildDepsOnly (
67+
commonArgs
68+
// {
69+
inherit version;
70+
pname = name;
71+
src = fileSetForCrate ../..;
72+
}
73+
);
74+
75+
individualCrateArgs = commonArgs // {
76+
inherit cargoArtifacts;
77+
78+
# NB: we disable tests since we'll run them all via cargo-nextest
79+
doCheck = false;
80+
};
81+
82+
# TODO: Return minimum fileSets per each crate
83+
fileSetForCrate =
84+
crate:
85+
lib.fileset.toSource {
86+
root = ../..;
87+
fileset = lib.fileset.unions [
88+
../../Cargo.toml
89+
../../Cargo.lock
90+
#
91+
../../versions.toml
92+
#
93+
../../stx-genesis/name_zonefiles.txt
94+
../../stx-genesis/name_zonefiles.txt.sha256
95+
../../stx-genesis/name_zonefiles-test.txt
96+
../../stx-genesis/name_zonefiles-test.txt.sha256
97+
../../stx-genesis/chainstate.txt
98+
../../stx-genesis/chainstate.txt.sha256
99+
../../stx-genesis/chainstate-test.txt
100+
../../stx-genesis/chainstate-test.txt.sha256
101+
#
102+
(craneLib.fileset.commonCargoSources crate)
103+
#
104+
(lib.fileset.fileFilter (file: file.hasExt "clar") ../..)
105+
#
106+
(craneLib.fileset.commonCargoSources ../../clarity)
107+
(craneLib.fileset.commonCargoSources ../../contrib/tools/relay-server)
108+
(craneLib.fileset.commonCargoSources ../../libsigner)
109+
(craneLib.fileset.commonCargoSources ../../libstackerdb)
110+
(craneLib.fileset.commonCargoSources ../../pox-locking)
111+
(craneLib.fileset.commonCargoSources ../../stacks-common)
112+
(craneLib.fileset.commonCargoSources ../../stackslib)
113+
(craneLib.fileset.commonCargoSources ../../stx-genesis)
114+
(craneLib.fileset.commonCargoSources ../../testnet/stacks-node)
115+
];
116+
};
117+
118+
stacks-signer = craneLib.buildPackage (
119+
individualCrateArgs
120+
// rec {
121+
version = versions.stacks_signer_version;
122+
pname = "stacks-signer";
123+
cargoFeatures = "--features monitoring_prom";
124+
cargoExtraArgs = "${cargoFeatures} -p ${pname}";
125+
src = fileSetForCrate ../../stacks-signer;
126+
}
127+
);
128+
129+
# Build the actual crate itself, reusing the dependency
130+
# artifacts from above.
131+
stacks-core = craneLib.buildPackage (
132+
commonArgs
133+
// rec {
134+
inherit version cargoArtifacts;
135+
doCheck = false;
136+
pname = name;
137+
cargoFeatures = "--features monitoring_prom,slog_json";
138+
cargoExtraArgs = "${cargoFeatures}";
139+
src = fileSetForCrate ../..;
140+
}
141+
);
142+
in
143+
with pkgs;
144+
{
145+
packages = {
146+
inherit stacks-signer;
147+
default = stacks-core;
148+
};
149+
150+
apps = rec {
151+
stacks-node = {
152+
type = "app";
153+
program = "${stacks-core}/bin/stacks-node";
154+
};
155+
stacks-signer = {
156+
type = "app";
157+
program = "${stacks-signer}/bin/stacks-signer";
158+
};
159+
default = stacks-node;
160+
};
161+
162+
checks = {
163+
inherit stacks-core;
164+
};
165+
166+
devShells.default = craneLib.devShell {
167+
RUSTFMT = "${toolchain}/bin/rustfmt";
168+
GREETING = "Welcome, stacks-core developer!";
169+
shellHook = ''
170+
echo $GREETING
171+
172+
echo "Setting a few options that will help you when running tests:"
173+
set -x
174+
ulimit -n 10240
175+
set +x
176+
'';
177+
178+
packages =
179+
[
180+
rust-analyzer
181+
bitcoind
182+
]
183+
++ lib.optionals pkgs.stdenv.isDarwin [
184+
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
185+
pkgs.darwin.apple_sdk.frameworks.CoreServices
186+
];
187+
};
188+
}
189+
);
190+
}

0 commit comments

Comments
 (0)