Skip to content

Commit e8b41fa

Browse files
fix nix
1 parent 185bf81 commit e8b41fa

6 files changed

Lines changed: 361 additions & 98 deletions

File tree

flake.nix

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,16 @@
6868
}
6969
);
7070

71-
devShells = forAllSystems (system: {
72-
default = pkgsFor.${system}.callPackage ./nix/shell.nix {
73-
};
74-
});
71+
devShells = forAllSystems (system:
72+
let pkgs = pkgsFor.${system}; in {
73+
default = pkgs.mkShell {
74+
nativeBuildInputs = with pkgs; [
75+
nim-2_2
76+
nimble
77+
];
78+
};
79+
}
80+
);
7581
};
7682

7783
}

nix/default.nix

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,60 @@ let
2222
revision = substring 0 8 (src.rev or src.dirtyRev or "00000000");
2323
version = tools.findKeyValue "^version = \"([a-f0-9.-]+)\"$" ../sds.nimble;
2424

25-
nimbleDeps = callPackage ./deps.nix {
26-
inherit src version revision;
27-
};
25+
# Fetched dep sources, keyed by package name.
26+
deps = import ./deps.nix { inherit pkgs; };
27+
28+
# nimble.lock metadata (version + checksums) for pkgs2 directory naming.
29+
lockFile = builtins.fromJSON (builtins.readFile ../nimble.lock);
30+
lockPkgs = lockFile.packages;
31+
32+
# nimble.paths for the Nim compiler (read by config.nims).
33+
# Paths must be double-quoted so that NimScript can parse the include correctly.
34+
nimblePaths = pkgs.writeText "nimble.paths" (
35+
builtins.concatStringsSep "\n" (
36+
[ "--noNimblePath" ] ++
37+
builtins.concatMap (p: [ "--path:\"${p}\"" "--path:\"${p}/src\"" ])
38+
(builtins.attrValues deps)
39+
)
40+
);
41+
42+
# Shell commands to populate pkgs2 with writable copies of only the Nim
43+
# source files nimble needs for dependency resolution. Full source for
44+
# compilation is provided via nimble.paths pointing to the Nix store.
45+
# Using rsync (same file filter as the old fixed-output deps derivation).
46+
# Each dir also gets a nimblemeta.json so nimble recognises it as installed
47+
# and does not attempt to re-download the package.
48+
pkgs2SetupCmds = lib.concatStringsSep "\n" (
49+
lib.mapAttrsToList (name: dep:
50+
let
51+
meta = lockPkgs.${name};
52+
dirName = "${name}-${meta.version}-${meta.checksums.sha1}";
53+
nimbleMeta = pkgs.writeText "${name}-nimblemeta.json" (builtins.toJSON {
54+
version = 1;
55+
metaData = {
56+
url = meta.url;
57+
downloadMethod = "git";
58+
vcsRevision = meta.vcsRevision;
59+
files = [];
60+
binaries = [];
61+
specialVersions = [ meta.version ];
62+
};
63+
});
64+
in ''
65+
mkdir -p "$NIMBLE_DIR/pkgs2/${dirName}"
66+
rsync -a \
67+
--include='*/' \
68+
--include='*.nim' \
69+
--include='*.nims' \
70+
--include='*.nimble' \
71+
--include='*.json' \
72+
--exclude='*' \
73+
${dep}/ "$NIMBLE_DIR/pkgs2/${dirName}/"
74+
chmod -R u+w "$NIMBLE_DIR/pkgs2/${dirName}"
75+
cp ${nimbleMeta} "$NIMBLE_DIR/pkgs2/${dirName}/nimblemeta.json"
76+
''
77+
) deps
78+
);
2879

2980
in stdenv.mkDerivation {
3081
pname = "nim-sds";
@@ -38,12 +89,12 @@ in stdenv.mkDerivation {
3889
};
3990

4091
buildInputs = with pkgs; [
41-
openssl gmp zip nim git nimble
92+
openssl gmp zip nim-2_2 git nimble
4293
];
4394

4495
# Dependencies that should only exist in the build environment.
4596
nativeBuildInputs = with pkgs; [
46-
nim cmake which patchelf nimbleDeps
97+
nim-2_2 nimble rsync cmake which patchelf
4798
] ++ optionals stdenv.isLinux [
4899
pkgs.lsb-release
49100
];
@@ -52,14 +103,16 @@ in stdenv.mkDerivation {
52103
"V=${toString verbosity}"
53104
];
54105

55-
# Provide dependencies via Nimble deps derivation.
56106
configurePhase = ''
57107
export NIMBLE_DIR=$NIX_BUILD_TOP/nimbledeps
58-
cp -r ${nimbleDeps}/nimbledeps $NIMBLE_DIR
59-
cp ${nimbleDeps}/nimble.paths ./
60-
chmod 775 -R $NIMBLE_DIR
61-
# Fix relative paths to absolute paths
62-
sed -i "s|./nimbledeps|$NIMBLE_DIR|g" nimble.paths
108+
mkdir -p $NIMBLE_DIR/pkgs2
109+
110+
# Populate pkgs2 with writable copies so nimble considers deps installed
111+
# and does not attempt to download them (which fails in the Nix sandbox).
112+
${pkgs2SetupCmds}
113+
114+
# Write nimble.paths so config.nims passes --path: flags to the Nim compiler.
115+
cp ${nimblePaths} ./nimble.paths
63116
'';
64117

65118
installPhase = let

nix/deps.nix

Lines changed: 166 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,167 @@
1-
{ pkgs, stdenv, src, version, revision }:
2-
3-
stdenv.mkDerivation {
4-
pname = "nim-sds-nimble-deps";
5-
version = "${version}-${revision}";
6-
7-
inherit src;
8-
9-
nativeBuildInputs = with pkgs; [
10-
jq rsync git nimble cacert moreutils
11-
];
12-
13-
configurePhase = ''
14-
export XDG_CACHE_HOME=$TMPDIR
15-
export NIMBLE_DIR=$NIX_BUILD_TOP/nimbledir
16-
export HOME=$TMPDIR
17-
'';
18-
19-
buildPhase = ''
20-
nimble --version
21-
nimble --silent --localdeps setup
22-
nimble --silent --localdeps install -y --depsOnly
23-
'';
24-
25-
installPhase = ''
26-
mkdir -p $out/nimbledeps
27-
28-
cp nimble.paths $out/nimble.paths
29-
30-
rsync -ra \
31-
--prune-empty-dirs \
32-
--include='*/' \
33-
--include='*.json' \
34-
--include='*.nim' \
35-
--include='*.nimble' \
36-
--exclude='*' \
37-
$NIMBLE_DIR/pkgs2 $out/nimbledeps
38-
'';
39-
40-
fixupPhase = ''
41-
# Replace build path with deterministic $out.
42-
sed "s|$NIMBLE_DIR|./nimbledeps|g" $out/nimble.paths \
43-
| sort | sponge $out/nimble.paths
44-
45-
# Nimble does not maintain order of files list.
46-
for META_FILE in $(find $out -name nimblemeta.json); do
47-
jq '.metaData.files |= sort' $META_FILE | sponge $META_FILE
48-
done
49-
'';
50-
51-
# Make this a fixed-output derivation to allows internet access for Nimble.
52-
outputHash = "sha256-OnirsXLj4HMVTbk+b4fcC+1K9MSMJyae6I7JO16WDno=";
53-
outputHashAlgo = "sha256";
54-
outputHashMode = "recursive";
1+
# AUTOGENERATED from nimble.lock — do not edit manually.
2+
# Regenerate with: ./tools/gen-nix-deps.sh nimble.lock nix/deps.nix
3+
{ pkgs }:
4+
5+
{
6+
unittest2 = pkgs.fetchgit {
7+
url = "https://github.com/status-im/nim-unittest2";
8+
rev = "26f2ef3ae0ec72a2a75bfe557e02e88f6a31c189";
9+
sha256 = "1n8n36kad50m97b64y7bzzknz9n7szffxhp0bqpk3g2v7zpda8sw";
10+
fetchSubmodules = true;
11+
};
12+
13+
bearssl = pkgs.fetchgit {
14+
url = "https://github.com/status-im/nim-bearssl";
15+
rev = "11e798b62b8e6beabe958e048e9e24c7e0f9ee63";
16+
sha256 = "0qx36iiawrhmx9qjqcyfvz0134ph9dy8ryq3ch8d31gq6ir7aw84";
17+
fetchSubmodules = true;
18+
};
19+
20+
bearssl_pkey_decoder = pkgs.fetchgit {
21+
url = "https://github.com/vacp2p/bearssl_pkey_decoder";
22+
rev = "21dd3710df9345ed2ad8bf8f882761e07863b8e0";
23+
sha256 = "0bl3f147zmkazbhdkr4cj1nipf9rqiw3g4hh1j424k9hpl55zdpg";
24+
fetchSubmodules = true;
25+
};
26+
27+
results = pkgs.fetchgit {
28+
url = "https://github.com/arnetheduck/nim-results";
29+
rev = "df8113dda4c2d74d460a8fa98252b0b771bf1f27";
30+
sha256 = "1h7amas16sbhlr7zb7n3jb5434k98ji375vzw72k1fsc86vnmcr9";
31+
fetchSubmodules = true;
32+
};
33+
34+
stew = pkgs.fetchgit {
35+
url = "https://github.com/status-im/nim-stew";
36+
rev = "b66168735d6f3841c5239c3169d3fe5fe98b1257";
37+
sha256 = "10n71vfa6klzd9dmal96jy0hiqk04gaj8wc9g91z6fclryf0yq92";
38+
fetchSubmodules = true;
39+
};
40+
41+
faststreams = pkgs.fetchgit {
42+
url = "https://github.com/status-im/nim-faststreams";
43+
rev = "ce27581a3e881f782f482cb66dc5b07a02bd615e";
44+
sha256 = "0y6bw2scnmr8cxj4fg18w7f34l2bh9qwg5nhlgd84m9fpr5bqarn";
45+
fetchSubmodules = true;
46+
};
47+
48+
serialization = pkgs.fetchgit {
49+
url = "https://github.com/status-im/nim-serialization";
50+
rev = "b0f2fa32960ea532a184394b0f27be37bd80248b";
51+
sha256 = "0wip1fjx7ka39ck1g1xvmyarzq1p5dlngpqil6zff8k8z5skiz27";
52+
fetchSubmodules = true;
53+
};
54+
55+
json_serialization = pkgs.fetchgit {
56+
url = "https://github.com/status-im/nim-json-serialization";
57+
rev = "c343b0e243d9e17e2c40f3a8a24340f7c4a71d44";
58+
sha256 = "0i8sq51nqj8lshf6bfixaz9a7sq0ahsbvq3chkxdvv4khsqvam91";
59+
fetchSubmodules = true;
60+
};
61+
62+
testutils = pkgs.fetchgit {
63+
url = "https://github.com/status-im/nim-testutils";
64+
rev = "e4d37dc1652d5c63afb89907efb5a5e812261797";
65+
sha256 = "0nv0a9jm5b1rn3y52cxvyj8xz3jg235mp0xbirfp2cda0icgy1si";
66+
fetchSubmodules = true;
67+
};
68+
69+
chronicles = pkgs.fetchgit {
70+
url = "https://github.com/status-im/nim-chronicles";
71+
rev = "27ec507429a4eb81edc20f28292ee8ec420be05b";
72+
sha256 = "1xx9fcfwgcaizq3s7i3s03mclz253r5j8va38l9ycl19fcbc96z9";
73+
fetchSubmodules = true;
74+
};
75+
76+
httputils = pkgs.fetchgit {
77+
url = "https://github.com/status-im/nim-http-utils";
78+
rev = "c53852d9e24205b6363bba517fa8ee7bde823691";
79+
sha256 = "1b332smfyp2yvhvfjrfqy4kvh9pc5w6hqh17f1yclz5z1j5xdpf1";
80+
fetchSubmodules = true;
81+
};
82+
83+
chronos = pkgs.fetchgit {
84+
url = "https://github.com/status-im/nim-chronos";
85+
rev = "0646c444fce7c7ed08ef6f2c9a7abfd172ffe655";
86+
sha256 = "1r499jl0lhnjq7hgddwgjl0gh3y1mprnqkhk0h6yh3cwgsmr5ym9";
87+
fetchSubmodules = true;
88+
};
89+
90+
dnsclient = pkgs.fetchgit {
91+
url = "https://github.com/ba0f3/dnsclient.nim";
92+
rev = "23214235d4784d24aceed99bbfe153379ea557c8";
93+
sha256 = "03mf3lw5c0m5nq9ppa49nylrl8ibkv2zzlc0wyhqg7w09kz6hks6";
94+
fetchSubmodules = true;
95+
};
96+
97+
jwt = pkgs.fetchgit {
98+
url = "https://github.com/vacp2p/nim-jwt.git";
99+
rev = "18f8378de52b241f321c1f9ea905456e89b95c6f";
100+
sha256 = "1986czmszdxj6g9yr7xn1fx8y2y9mwpb3f1bn9nc6973qawsdm0p";
101+
fetchSubmodules = true;
102+
};
103+
104+
nimcrypto = pkgs.fetchgit {
105+
url = "https://github.com/cheatfate/nimcrypto";
106+
rev = "b3dbc9c4d08e58c5b7bfad6dc7ef2ee52f2f4c08";
107+
sha256 = "1v4rz42lwcazs6isi3kmjylkisr84mh0kgmlqycx4i885dn3g0l4";
108+
fetchSubmodules = true;
109+
};
110+
111+
metrics = pkgs.fetchgit {
112+
url = "https://github.com/status-im/nim-metrics";
113+
rev = "11d0cddfb0e711aa2a8c75d1892ae24a64c299fc";
114+
sha256 = "1jrf2cf7v3iqjsk6grzvivxic1shhaxnvab6d35rxs2kcy6b5dv0";
115+
fetchSubmodules = true;
116+
};
117+
118+
secp256k1 = pkgs.fetchgit {
119+
url = "https://github.com/status-im/nim-secp256k1";
120+
rev = "d8f1288b7c72f00be5fc2c5ea72bf5cae1eafb15";
121+
sha256 = "1qjrmwbngb73f6r1fznvig53nyal7wj41d1cmqfksrmivk2sgrn2";
122+
fetchSubmodules = true;
123+
};
124+
125+
zlib = pkgs.fetchgit {
126+
url = "https://github.com/status-im/nim-zlib";
127+
rev = "e680f269fb01af2c34a2ba879ff281795a5258fe";
128+
sha256 = "1xw9f1gjsgqihdg7kdkbaq1wankgnx2vn9l3ihc6nqk2jzv5bvk5";
129+
fetchSubmodules = true;
130+
};
131+
132+
websock = pkgs.fetchgit {
133+
url = "https://github.com/status-im/nim-websock";
134+
rev = "35ae76f1559e835c80f9c1a3943bf995d3dd9eb5";
135+
sha256 = "1j6dklzb6b6bv2aiglbiyflja2vdpmyxfirv98f49y62mykq0yrw";
136+
fetchSubmodules = true;
137+
};
138+
139+
lsquic = pkgs.fetchgit {
140+
url = "https://github.com/vacp2p/nim-lsquic";
141+
rev = "4fb03ee7bfb39aecb3316889fdcb60bec3d0936f";
142+
sha256 = "0qdhcd4hyp185szc9sv3jvwdwc9zp3j0syy7glxv13k9bchfmkfg";
143+
fetchSubmodules = true;
144+
};
145+
146+
libp2p = pkgs.fetchgit {
147+
url = "https://github.com/vacp2p/nim-libp2p";
148+
rev = "ca48c3718246bb411ff0e354a70cb82d9a28de0d";
149+
sha256 = "07qfjjrq6w7bj9dbchvcrpla47jidngbrgmigbhl7fh3cfkdabc9";
150+
fetchSubmodules = true;
151+
};
152+
153+
stint = pkgs.fetchgit {
154+
url = "https://github.com/status-im/nim-stint";
155+
rev = "470b7892561b5179ab20bd389a69217d6213fe58";
156+
sha256 = "1isfwmbj98qfi5pm9acy0yyvq0vlz38nxp30xl43jx2mmaga2w22";
157+
fetchSubmodules = true;
158+
};
159+
160+
taskpools = pkgs.fetchgit {
161+
url = "https://github.com/status-im/nim-taskpools";
162+
rev = "9e8ccc754631ac55ac2fd495e167e74e86293edb";
163+
sha256 = "1y78l33vdjxmb9dkr455pbphxa73rgdsh8m9gpkf4d9b1wm1yivy";
164+
fetchSubmodules = true;
165+
};
166+
55167
}

nix/shell.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
pkgs ? import <nixpkgs> { },
3-
nim ? null,
43
}:
54

65
let
@@ -12,7 +11,8 @@ in pkgs.mkShell {
1211
];
1312

1413
buildInputs = with pkgs; [
15-
nim
14+
nim-2_2
15+
nimble
1616
which
1717
git
1818
cmake

0 commit comments

Comments
 (0)