nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 rustPlatform,
6 pkg-config,
7 openssl,
8 onnxruntime,
9 versionCheckHook,
10 runCommand,
11 writeText,
12 testers,
13 nix-update-script,
14 magika-cli,
15}:
16
17rustPlatform.buildRustPackage (finalAttrs: {
18 pname = "magika-cli";
19 version = "1.0.1";
20
21 src = fetchFromGitHub {
22 owner = "google";
23 repo = "magika";
24 tag = "cli/v${finalAttrs.version}";
25 hash = "sha256-g/fnSdh2jpOHOLTuR4DUPB1kbC0eKADHLKcfB1q08XI=";
26 };
27
28 cargoHash = "sha256-uqnTyedry9nWyO2518r0D3hk6oWb4wQE/Ku0cOkSjBA=";
29
30 cargoRoot = "rust/cli";
31 buildAndTestSubdir = finalAttrs.cargoRoot;
32
33 nativeBuildInputs = [
34 pkg-config
35 ];
36
37 buildInputs = [
38 openssl
39 onnxruntime
40 ];
41
42 env = {
43 OPENSSL_NO_VENDOR = "true";
44 };
45
46 doInstallCheck = true;
47 nativeInstallCheckInputs = [
48 versionCheckHook
49 ];
50 versionCheckProgramArg = "--version";
51
52 passthru = {
53 tests = {
54 mime = testers.testEqualContents {
55 assertion = "magika detects the correct language from content even when the file extension is wrong";
56
57 # Magika does not support Nix files yet: https://github.com/google/magika/issues/1247
58 expected = writeText "expected" ''
59 application/x-rust
60 '';
61 actual =
62 runCommand "actual"
63 {
64 nativeBuildInputs = [
65 magika-cli
66 ];
67 }
68 ''
69 magika --format '%m' '${./test.md}' >>"$out"
70 '';
71 };
72 };
73
74 updateScript = nix-update-script {
75 extraArgs = [ "--version-regex=^cli/v([0-9.]+)$" ];
76 };
77 };
78
79 meta = {
80 description = "Determines file content types using AI";
81 homepage = "https://securityresearch.google/magika/";
82 downloadPage = "https://github.com/google/magika";
83 changelog = "https://github.com/google/magika/releases/tag/cli/v${finalAttrs.version}";
84 license = lib.licenses.asl20;
85 maintainers = with lib.maintainers; [
86 kachick
87 ];
88 mainProgram = "magika";
89 platforms = with lib.platforms; unix ++ windows;
90
91 # The package test fails on Darwin with this error, even though the build succeeds:
92 # libc++abi: terminating due to uncaught exception of type std::__1::system_error: mutex lock failed: Invalid argument
93 broken = stdenv.hostPlatform.isDarwin;
94 };
95})