Skip to content

Commit d06c07d

Browse files
committed
wip
1 parent 08d5baf commit d06c07d

1 file changed

Lines changed: 91 additions & 3 deletions

File tree

flake.nix

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,65 @@
4040
craneLib = crane.mkLib pkgs;
4141
src = craneLib.cleanCargoSource ./.;
4242

43+
baseArgs = {
44+
src = craneLib.cleanCargoSource ./.;
45+
# src = fileSetForCrate;
46+
};
47+
48+
# cargoVendorDir
49+
50+
# isLinderaRepo = p: lib.hasPrefix
51+
# "git+https://github.com/seanmonstar/num_cpus.git"
52+
# p.source;
53+
httplz_port = "34567";
54+
cargoVendorDir = craneLib.vendorCargoDeps (baseArgs // {
55+
# Use this function to override crates coming from git dependencies
56+
# overrideVendorGitCheckout = ps: drv:
57+
# # For example, patch a specific repository and tag, in this case num_cpus-1.13.1
58+
# # if lib.any (p: (isLinderaRepo p) ) ps then
59+
# # drv.overrideAttrs (_old: {
60+
# # })
61+
# # else
62+
# # Nothing to change, leave the derivations as is
63+
# drv;
64+
65+
66+
# Use this function to override crates coming from any registry checkout
67+
overrideVendorCargoPackage = p: drv:
68+
# For example, patch a specific crate, in this case byteorder-1.5.0
69+
if p.name == "lindera-unidic" then
70+
builtins.trace "MATCHED LINDERA-UNIDIC" drv.overrideAttrs(_old: {
71+
CARGO_BUILD_RUSTFLAGS = "--verbose";
72+
73+
# Specifying an arbitrary patch to apply
74+
# patches = [
75+
# ./0001-patch-num-cpus.patch
76+
# ];
77+
78+
# Similarly we can also run additional hooks to make changes
79+
# lindera = { version = "0.43.1" }
80+
81+
postPatch = ''
82+
echo "PATCHING"
83+
ls -l
84+
cat build.rs
85+
substituteInPlace build.rs --replace-fail \
86+
"https://Lindera.dev/unidic-mecab-2.1.2.tar.gz" \
87+
"http://localhost:${httplz_port}/unidic-mecab-2.1.2.tar.gz"
88+
89+
cat build.rs
90+
91+
'';
92+
})
93+
else
94+
# Nothing to change, leave the derivations as is
95+
drv;
96+
});
97+
4398
# Common arguments can be set here to avoid repeating them later
4499
commonArgs = {
45100
inherit src;
101+
inherit cargoVendorDir;
46102
strictDeps = true;
47103

48104
buildInputs =
@@ -63,7 +119,39 @@
63119
# so we can reuse all of that work (e.g. via cachix) when running in CI
64120
# It is *highly* recommended to use something like cargo-hakari to avoid
65121
# cache misses when building individual top-level-crates
66-
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
122+
cargoArtifacts = (craneLib.buildDepsOnly commonArgs).overrideAttrs(oa: {
123+
pname = builtins.trace "pname=${oa.pname}" oa.pname;
124+
125+
nativeBuildInputs = oa.nativeBuildInputs ++ [ pkgs.httplz];
126+
doCheck = false;
127+
preBuild = ''
128+
echo "PATCHING"
129+
ls -l
130+
set -x
131+
(
132+
set -x
133+
# serve lindera-unidic on localhost vacant port
134+
httplz_port="${
135+
if pkgs.stdenv.buildPlatform.isDarwin then
136+
''$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()')''
137+
else
138+
"34567"
139+
}"
140+
mkdir .lindera-http-plz
141+
ln -s ${lindera-unidic-src} .lindera-http-plz/unidic-mecab-2.1.2.tar.gz
142+
httplz --port "$httplz_port" -- .lindera-http-plz/ &
143+
echo $! >$TMPDIR/.httplz_pid
144+
145+
echo "$out"
146+
echo "Trying to substitute"
147+
ls -l
148+
149+
# not needed with useFetchCargoVendor=true, but kept in case it is required again
150+
#newHash=$(sha256sum build.rs | cut -d " " -f 1)
151+
#substituteInPlace .cargo-checksum.json --replace-fail $oldHash $newHash
152+
)'';
153+
154+
});
67155

68156
individualCrateArgs = commonArgs // {
69157
inherit cargoArtifacts;
@@ -215,8 +303,8 @@
215303
nixfmt-tree
216304

217305
# Rust
218-
rustToolchain
219-
taplo
306+
# rustToolchain
307+
# taplo
220308
cargo-shear
221309
pkg-config
222310
openssl

0 commit comments

Comments
 (0)