Skip to content

Commit 38ea31c

Browse files
authored
pagefind: support file:// URI for prefetched tarballs (#417919)
2 parents ba92ab5 + 01ecc34 commit 38ea31c

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

pkgs/applications/misc/pagefind/default.nix

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
fetchFromGitHub,
66
fetchNpmDeps,
77
fetchurl,
8-
httplz,
98
binaryen,
109
gzip,
1110
nodejs,
@@ -88,30 +87,11 @@ rustPlatform.buildRustPackage rec {
8887
8988
# patch a build-time dependency download
9089
(
91-
realpath $cargoDepsCopy/* | grep lindera-unidic # debug for when version number changes
92-
cd $cargoDepsCopy/lindera-unidic-0.32.2
93-
#oldHash=$(sha256sum build.rs | cut -d " " -f 1)
94-
95-
# serve lindera-unidic on localhost vacant port
96-
httplz_port="${
97-
if stdenv.buildPlatform.isDarwin then
98-
''$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()')''
99-
else
100-
"34567"
101-
}"
102-
mkdir .lindera-http-plz
103-
ln -s ${lindera-unidic-src} .lindera-http-plz/unidic-mecab-2.1.2.tar.gz
104-
httplz --port "$httplz_port" -- .lindera-http-plz/ &
105-
echo $! >$TMPDIR/.httplz_pid
106-
107-
# file:// does not work
108-
substituteInPlace build.rs --replace-fail \
109-
"https://dlwqk3ibdg1xh.cloudfront.net/unidic-mecab-2.1.2.tar.gz" \
110-
"http://localhost:$httplz_port/unidic-mecab-2.1.2.tar.gz"
111-
112-
# not needed with useFetchCargoVendor=true, but kept in case it is required again
113-
#newHash=$(sha256sum build.rs | cut -d " " -f 1)
114-
#substituteInPlace .cargo-checksum.json --replace-fail $oldHash $newHash
90+
patch -d $cargoDepsCopy/lindera-assets-*/ -p1 < ${./lindera-assets-support-file-paths.patch}
91+
92+
substituteInPlace $cargoDepsCopy/lindera-unidic-*/build.rs --replace-fail \
93+
"${lindera-unidic-src.url}" \
94+
"file://${lindera-unidic-src}"
11595
)
11696
'';
11797

@@ -126,7 +106,6 @@ rustPlatform.buildRustPackage rec {
126106
rustc.llvmPackages.lld
127107
wasm-bindgen-cli_0_2_92
128108
wasm-pack
129-
httplz
130109
]
131110
++ lib.optionals stdenv.buildPlatform.isDarwin [
132111
python3
@@ -162,11 +141,6 @@ rustPlatform.buildRustPackage rec {
162141
)
163142
'';
164143

165-
# the file is also fetched during checkPhase
166-
preInstall = ''
167-
kill ${lib.optionalString stdenv.hostPlatform.isDarwin "-9"} $(cat $TMPDIR/.httplz_pid)
168-
'';
169-
170144
buildFeatures = [ "extended" ];
171145

172146
doInstallCheck = true;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
diff --git a/src/lib.rs b/src/lib.rs
2+
index 6f86cc4..a9ca418 100644
3+
--- a/src/lib.rs
4+
+++ b/src/lib.rs
5+
@@ -128,12 +128,17 @@ pub fn fetch(params: FetchParams, builder: impl DictionaryBuilder) -> Result<(),
6+
// copy(&source_path, &source_path_for_build)?;
7+
let tmp_path = Path::new(&build_dir).join(params.file_name.to_owned() + ".download");
8+
9+
+ if let Some(path) = params.download_url.strip_prefix("file://") {
10+
+ std::fs::copy(path, &tmp_path)?;
11+
+ }
12+
+ else {
13+
// Download a tarball
14+
let resp = ureq::get(params.download_url).call()?;
15+
let mut dest = File::create(&tmp_path)?;
16+
17+
io::copy(&mut resp.into_reader(), &mut dest)?;
18+
dest.flush()?;
19+
+ }
20+
21+
rename(tmp_path, source_path_for_build).expect("Failed to rename temporary file");
22+
23+
@@ -153,7 +158,6 @@ pub fn fetch(params: FetchParams, builder: impl DictionaryBuilder) -> Result<(),
24+
archive.unpack(&tmp_extract_path)?;
25+
rename(tmp_extracted_path, &input_dir).expect("Failed to rename archive directory");
26+
let _ = std::fs::remove_dir_all(&tmp_extract_path);
27+
- drop(dest);
28+
let _ = std::fs::remove_file(source_path_for_build);
29+
}
30+

0 commit comments

Comments
 (0)