forked from onekey-sec/unblob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.nix
119 lines (105 loc) · 2.87 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
{ lib
, makeWrapper
, mkPoetryApp
, poetry2nix
, glibc
, python3
, rustPlatform
, e2fsprogs
, lz4
, lziprecover
, lzo
, lzop
, p7zip
, pkg-config
, sasquatch
, simg2img
, unar
, file
, zstd
}:
let
# These dependencies are only added to PATH
runtimeDeps = [
e2fsprogs
lz4
lziprecover
lzop
p7zip
sasquatch
sasquatch.bigEndian
simg2img
unar
zstd
];
self = mkPoetryApp {
projectDir = ./.;
preferWheels = true;
# Python dependencies that need special care, like non-python
# build dependencies
overrides = poetry2nix.overrides.withoutDefaults (self: super:
let
# Inject setuptools to dependencies that is required by many non-wheel distributed packages
overrideWithSetuptools = drv: overrides: (drv.overridePythonAttrs overrides).overridePythonAttrs (prev: {
buildInputs = prev.buildInputs or [ ] ++ [
self.setuptools
];
});
in
{
python-lzo = overrideWithSetuptools super.python-lzo (_: {
buildInputs = [
lzo
];
});
jefferson = overrideWithSetuptools super.jefferson (_: {
propagatedBuildInputs = [
# Use the _same_ version as unblob
self.cstruct
self.python-lzo
];
});
python-magic = overrideWithSetuptools (super.python-magic.override { preferWheel = false; }) (_: {
patchPhase = ''
substituteInPlace magic/loader.py --replace "find_library('magic')" "'${file}/lib/libmagic.so'"
'';
});
arpy = overrideWithSetuptools super.arpy { };
yaffshiv = overrideWithSetuptools super.yaffshiv { };
ubi-reader = overrideWithSetuptools super.ubi-reader { };
cairosvg = overrideWithSetuptools super.cairocffi { };
});
python = python3;
postFixup = ''
wrapProgram $out/bin/unblob --prefix PATH : ${lib.makeBinPath runtimeDeps} \
--set LOCALE_ARCHIVE_2_27 ${glibc}/lib/locale/locale-archive \
--set LC_ALL C.UTF-8
'';
UNBLOB_BUILD_RUST_EXTENSION = "1";
cargoDeps = rustPlatform.importCargoLock {
lockFile = ./Cargo.lock;
};
nativeBuildInputs = with rustPlatform; [
cargoSetupHook
makeWrapper
rust.cargo
rust.rustc
];
};
in
self // {
inherit runtimeDeps;
withTests = self.app.overridePythonAttrs (_: {
checkPhase = ''
(
deps_PATH=${lib.makeBinPath runtimeDeps}
# $program_PATH is set to contain all the script-paths of all
# Python dependencies
export PATH=$deps_PATH:$program_PATH:$PATH
# romfs sample file contains some funky symlinks which get
# removed when source is copyed to the nix store.
pytest -vvv -k "not test_all_handlers[filesystem.romfs]" --no-cov
)
'';
});
}