-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathflake.nix
More file actions
125 lines (109 loc) · 4.02 KB
/
flake.nix
File metadata and controls
125 lines (109 loc) · 4.02 KB
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
118
119
120
121
122
123
124
125
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
pname = "clarinet";
inherit (cargoToml.workspace.package) version;
# Hash for clarity git dependency - update this when Cargo.lock changes
# Run `nix run .#check-git-dependencies-hash` to verify or get the new hash
clarityHash = "sha256-ktmxnwyId37u944Q9PsJmk7lR8jbLseHRsgEyxObMGk=";
clarinet = pkgs.rustPlatform.buildRustPackage {
inherit pname version;
src = self;
cargoLock = {
lockFile = ./Cargo.lock;
outputHashes = {
"clarity-0.0.1" = clarityHash;
};
};
preBuild =
let
versionsToml = pkgs.writeText "versions.toml" ''
stacks_node_version = "0.0.0.0.1"
stacks_signer_version = "0.0.0.0.1.0"
'';
in
# Minimal versions.toml for stacks-common build script
# The build.rs in stacks-common expects it at ../versions.toml
# relative to the stacks-common crate in the cargo vendor directory
''
cp ${versionsToml} "$NIX_BUILD_TOP/cargo-vendor-dir/versions.toml"
'';
nativeBuildInputs = [
pkgs.pkg-config
];
buildInputs = [
pkgs.openssl
]
++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isDarwin [
pkgs.apple-sdk_15
];
# Skip tests that require network access or additional setup
doCheck = false;
};
# Script to check git dependency hashes match between Cargo.lock and flake.nix
check-git-dependencies-hash = pkgs.writeShellApplication {
name = "check-git-dependencies-hash";
runtimeInputs = [
pkgs.gnugrep
pkgs.gnused
pkgs.nix-prefetch-git
pkgs.jq
];
text =
let
gitRepo = "https://github.com/stacks-network/stacks-core.git";
in
''
if [ ! -f "Cargo.lock" ]; then
echo "Error: Cargo.lock not found in current directory" >&2
exit 1
fi
current_hash="${clarityHash}"
echo "Current hash in flake.nix: $current_hash"
source_line=$(grep -A2 'name = "clarity"' Cargo.lock | grep 'source = "git+${gitRepo}' || true)
# Extract the commit hash (after the #)
commit=$(echo "$source_line" | sed -n 's/.*#\([a-f0-9]*\)".*/\1/p')
if [ -z "$commit" ]; then
echo "Error: Could not extract clarity commit from Cargo.lock" >&2
exit 1
fi
echo "Fetching Nix hash for clarity commit: $commit"
# Get the hash
sha256=$(nix-prefetch-git --url ${gitRepo} --rev "$commit" --quiet | jq -r '.sha256')
expected_hash=$(nix hash convert --hash-algo sha256 --to sri "$sha256")
echo "Expected hash from Cargo.lock: $expected_hash"
if [ "$expected_hash" != "$current_hash" ]; then
echo ""
echo "Error: clarity hash mismatch!"
echo "Please update outputHashes in flake.nix to:"
echo " \"clarity-0.0.1\" = \"$expected_hash\";"
exit 1
fi
echo ""
echo "Clarity hash is up to date!"
'';
};
in
{
packages.default = clarinet;
packages.clarinet = clarinet;
apps.check-git-dependencies-hash = {
type = "app";
program = toString (pkgs.lib.getExe check-git-dependencies-hash);
};
}
);
}