Skip to content

Commit f28dca6

Browse files
qkaiserrxpha3l
authored andcommitted
chore(nix): re-organize nix packaging
Instead of adding patches on top of unlob package available on nixpkgs, we keep our own package.nix version here so that it's easy to add new third party dependencies that new handlers may require. It also makes it easier to upstream it since we just have to submit the package.nix file to nixpkgs.
1 parent c505395 commit f28dca6

File tree

3 files changed

+131
-39
lines changed

3 files changed

+131
-39
lines changed

overlay.nix

+1-38
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,5 @@ final: prev:
88
nativeCheckInputs = (super.nativeCheckInputs or [ ]) ++ [ final.which ];
99
});
1010

11-
unblob =
12-
let
13-
pyproject_toml = (builtins.fromTOML (builtins.readFile ./pyproject.toml));
14-
version = pyproject_toml.project.version;
15-
in
16-
(prev.unblob.override { e2fsprogs = final.e2fsprogs-nofortify; }).overridePythonAttrs (super: rec {
17-
inherit version;
18-
19-
src = final.nix-filter {
20-
root = ./.;
21-
include = [
22-
"Cargo.lock"
23-
"Cargo.toml"
24-
"pyproject.toml"
25-
"python"
26-
"rust"
27-
"tests"
28-
"README.md"
29-
];
30-
};
31-
32-
dependencies = (super.dependencies or [ ]) ++ [ final.python3.pkgs.pyzstd ];
33-
34-
# remove this when packaging changes are upstreamed
35-
cargoDeps = final.rustPlatform.importCargoLock {
36-
lockFile = ./Cargo.lock;
37-
};
38-
39-
nativeBuildInputs = with final.rustPlatform; [
40-
cargoSetupHook
41-
maturinBuildHook
42-
];
43-
44-
# override disabling of 'test_all_handlers[filesystem.extfs]' from upstream
45-
pytestFlagsArray = [
46-
"--no-cov"
47-
];
48-
});
11+
unblob = final.callPackage ./package.nix { };
4912
}

package.nix

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
{
2+
lib,
3+
python3,
4+
fetchFromGitHub,
5+
makeWrapper,
6+
e2fsprogs-nofortify,
7+
jefferson,
8+
lz4,
9+
lziprecover,
10+
lzop,
11+
p7zip,
12+
nix-filter,
13+
sasquatch,
14+
sasquatch-v4be,
15+
simg2img,
16+
ubi_reader,
17+
unar,
18+
zstd,
19+
versionCheckHook,
20+
rustPlatform,
21+
}:
22+
23+
let
24+
# These dependencies are only added to PATH
25+
runtimeDeps = [
26+
e2fsprogs-nofortify
27+
jefferson
28+
lziprecover
29+
lzop
30+
p7zip
31+
sasquatch
32+
sasquatch-v4be
33+
ubi_reader
34+
simg2img
35+
unar
36+
zstd
37+
lz4
38+
];
39+
pyproject_toml = (builtins.fromTOML (builtins.readFile ./pyproject.toml));
40+
version = pyproject_toml.project.version;
41+
in
42+
python3.pkgs.buildPythonApplication rec {
43+
pname = "unblob";
44+
pyproject = true;
45+
disabled = python3.pkgs.pythonOlder "3.9";
46+
inherit version;
47+
src = nix-filter {
48+
root = ./.;
49+
include = [
50+
"Cargo.lock"
51+
"Cargo.toml"
52+
"pyproject.toml"
53+
"python"
54+
"rust"
55+
"tests"
56+
"README.md"
57+
];
58+
};
59+
60+
strictDeps = true;
61+
62+
build-system = with python3.pkgs; [ poetry-core ];
63+
64+
dependencies = with python3.pkgs; [
65+
arpy
66+
attrs
67+
click
68+
cryptography
69+
dissect-cstruct
70+
lark
71+
lief.py
72+
python3.pkgs.lz4 # shadowed by pkgs.lz4
73+
plotext
74+
pluggy
75+
pyfatfs
76+
pyperscan
77+
python-magic
78+
pyzstd
79+
rarfile
80+
rich
81+
structlog
82+
treelib
83+
unblob-native
84+
];
85+
86+
cargoDeps = rustPlatform.importCargoLock {
87+
lockFile = ./Cargo.lock;
88+
};
89+
90+
nativeBuildInputs = with rustPlatform; [
91+
cargoSetupHook
92+
maturinBuildHook
93+
makeWrapper
94+
];
95+
96+
# These are runtime-only CLI dependencies, which are used through
97+
# their CLI interface
98+
pythonRemoveDeps = [
99+
"jefferson"
100+
"ubi-reader"
101+
];
102+
103+
pythonImportsCheck = [ "unblob" ];
104+
105+
makeWrapperArgs = [
106+
"--prefix PATH : ${lib.makeBinPath runtimeDeps}"
107+
];
108+
109+
nativeCheckInputs =
110+
with python3.pkgs;
111+
[
112+
pytestCheckHook
113+
pytest-cov
114+
versionCheckHook
115+
]
116+
++ runtimeDeps;
117+
118+
versionCheckProgramArg = "--version";
119+
120+
pytestFlagsArray = [
121+
"--no-cov"
122+
];
123+
124+
passthru = {
125+
# helpful to easily add these to a nix-shell environment
126+
inherit runtimeDeps;
127+
};
128+
129+
}

shell.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ let
44
./flake.lock
55
./flake.nix
66
./overlay.nix
7-
./nix
7+
./package.nix
88
];
99

1010
lock = builtins.fromJSON (builtins.readFile ./flake.lock);

0 commit comments

Comments
 (0)