1{
2 lib,
3 stdenv,
4 rustPlatform,
5 fetchFromGitHub,
6 iconv,
7 installShellFiles,
8 versionCheckHook,
9 nix-update-script,
10}:
11
12rustPlatform.buildRustPackage rec {
13 pname = "topiary";
14 version = "0.6.0";
15
16 src = fetchFromGitHub {
17 owner = "tweag";
18 repo = "topiary";
19 tag = "v${version}";
20 hash = "sha256-nRVxjdEtYvgF8Vpw0w64hUd1scZh7f+NjFtbTg8L5Qc=";
21 };
22
23 nativeBuildInputs = [ installShellFiles ];
24 nativeInstallCheckInputs = [ versionCheckHook ];
25
26 cargoHash = "sha256-EqalIF1wx3F/5CiD21IaYsPdks6Mv1VfwL8OTRWsWaU=";
27
28 # https://github.com/NixOS/nixpkgs/pull/359145#issuecomment-2542418786
29 depsExtraArgs.postBuild = ''
30 find $out -name '*.ps1' -print | while read -r file; do
31 if [ "$(file --brief --mime-encoding "$file")" == utf-16be ]; then
32 ${iconv}/bin/iconv -f UTF-16BE -t UTF16LE "$file" > tmp && mv tmp "$file"
33 fi
34 done
35 '';
36
37 cargoBuildFlags = [
38 "-p"
39 "topiary-cli"
40 ];
41 cargoTestFlags = cargoBuildFlags;
42
43 # Skip tests that cannot be executed in sandbox (operation not permitted)
44 checkFlags = [
45 "--skip=test_fmt_dir"
46 "--skip=test_fmt_files"
47 "--skip=test_fmt_files_query_fallback"
48 "--skip=test_fmt_invalid"
49 "--skip=test_fmt_stdin"
50 "--skip=test_fmt_stdin_query"
51 "--skip=test_fmt_stdin_query_fallback"
52 "--skip=test_vis"
53 "--skip=formatted_query_tester"
54 "--skip=input_output_tester"
55 "--skip=coverage_tester"
56 ];
57
58 env.TOPIARY_LANGUAGE_DIR = "${placeholder "out"}/share/queries";
59
60 postInstall = ''
61 install -Dm444 topiary-queries/queries/* -t $out/share/queries
62 ''
63 + lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
64 installShellCompletion --cmd topiary \
65 --bash <($out/bin/topiary completion bash) \
66 --fish <($out/bin/topiary completion fish) \
67 --zsh <($out/bin/topiary completion zsh)
68 '';
69
70 doInstallCheck = true;
71 versionCheckProgramArg = "--version";
72
73 passthru.updateScript = nix-update-script { };
74
75 meta = {
76 description = "Uniform formatter for simple languages, as part of the Tree-sitter ecosystem";
77 mainProgram = "topiary";
78 homepage = "https://github.com/tweag/topiary";
79 changelog = "https://github.com/tweag/topiary/blob/${src.tag}/CHANGELOG.md";
80 license = lib.licenses.mit;
81 maintainers = with lib.maintainers; [
82 figsoda
83 nartsiss
84 ];
85 };
86}