Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pythonPackages.binwalk: add dependencies #94268

Merged
merged 3 commits into from Aug 7, 2020
Merged

Conversation

Pamplemousse
Copy link
Member

Motivation for this change

Allow binwalk to extract CramFS content.
Here is the error I get with the current version:

WARNING: Extractor.execute failed to run external extractor 'cramfsck -x 'cramfs-root' '%e'': [Errno 2] No such file or directory: 'cramfsck', 'cramfsck -x 'cramfs-root'
 '%e'' might not be installed correctly                                             

WARNING: Extractor.execute failed to run external extractor 'cramfsswap '%e' '%e.swap' && cramfsck -x 'cramfs-root' '%e.swap'': [Errno 2] No such file or directory: 'cra
mfsswap', 'cramfsswap '%e' '%e.swap' && cramfsck -x 'cramfs-root' '%e.swap'' might not be installed correctly
128           0x80            CramFS filesystem, little endian, size: 9912320, version 2, sorted_dirs, CRC 0xCA750C65, edition 0, 5736 blocks, 607 files

This comment explicitly states that cramfsck and cramfsswap are required to work.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@jonringer
Copy link
Contributor

This seems like you should package cramfsck and cramfsswap as applications then pass them to the python wrapper so they are available.

I'm not sure if the current PR would solve the issue. IIRC, python packages which are passed through propagatedBuildInputs don't propagate their commands, just the packages.

Comment on lines +34 to 35
propagatedBuildInputs = [ zlib xz ncompress gzip bzip2 gnutar p7zip cabextract cramfsswap cramfsprogs lzma pycrypto ]
++ stdenv.lib.optional visualizationSupport pyqtgraph;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not checked the other tools. I suspect they also should be in PATH rather than
propagatedBuildInputs.

Suggested change
propagatedBuildInputs = [ zlib xz ncompress gzip bzip2 gnutar p7zip cabextract cramfsswap cramfsprogs lzma pycrypto ]
++ stdenv.lib.optional visualizationSupport pyqtgraph;
propagatedBuildInputs = [ zlib xz ncompress gzip bzip2 gnutar p7zip cabextract lzma pycrypto ]
++ stdenv.lib.optional visualizationSupport pyqtgraph;
makeWrapperArgs = ["--prefix" "PATH" ":" (stdenv.lib.makeBinPath [ cramfsswap cramfsprogs ])];

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what this addition is supposed to do:
When I nix-shell --pure -p 'python3.withPackages(ps: with ps; [binwalk])', the $PATH is not changed whether I this line (makeWrapperArgs...) is present in the expression or not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonringer, you made a similar proposition below: What is that supposed to do?

I am not too sure I am testing that correctly 😕: I don't see any difference when I am adding the aforementioned line:

# cramfsswap is still not available via the binwalk package
$ nix-shell --pure -p 'python3.withPackages(ps: with ps; [binwalk])' --run "cramfsswap"
/tmp/nix-shell-13495-0/rc: line 1: cramfsswap: command not found

# while it works when imported itself
$ nix-shell --pure -p cramfsswap --run "cramfsswap"
Usage: cramfsswap <in> <out>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Poke @Mic92 , @jonringer .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pamplemousse you don't want to change the PATH of your nix-shell but the PATH of the binwalk executable. If you execute binwalk from the nix store directly without nix-shell, than cramfs won't be in PATH. Note that nix-shell also packs propagated build inputs into your PATH, however those are not proper runtime dependencies but build dependencies instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this makes sense?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mic92 , thanks for the explanation. So, if I understand correctly:
Using the makeWrapperArgs ... allows to solve the error (aforementioned in the first comment) both when invoking binwalk from a nix-shell, but also from the executable in the nix store.

As for the second part of your remark, I am not quite sure I get the full implications of what you say:

  • So, adding cramfsswap cramfsprogs to the propagatedBuildInputs do not make them runtime dependencies... Is it only incidental that without makeWrapperArgs, and using nix-shell (because they are added to its PATH) the error was solved when I tested?
  • I kinda hoped those binaries to be available in the shell when importing binwalk, is that an over-expectation? (i.e. it is "normal" for import of python modules not to expose in the nix-shell the binaries they rely on)

@Pamplemousse
Copy link
Member Author

Pamplemousse commented Jul 31, 2020

@jonringer Interesting...

It did "solve my issue" (i.e., I can extract the content of a CramFs image using binwalk).

$ nix-shell -p 'python3.withPackages(ps: with ps; [binwalk])' --run "binwalk -e firmwares/FW_BU-2015_1.03.18_2014-06-05"

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
128           0x80            CramFS filesystem, little endian, size: 9912320, version 2, sorted_dirs, CRC 0xCA750C65, edition 0, 5736 blocks, 607 files

However, cramfsswap and cramfsck are not available:

$ nix-shell -p 'python3.withPackages(ps: with ps; [binwalk])' --run "cramfsswap"
/tmp/nix-shell-20130-0/rc: line 1: cramfsswap: command not found
$ nix-shell -p 'python3.withPackages(ps: with ps; [binwalk])' --run "cramfsck" 
/tmp/nix-shell-20177-0/rc: line 1: cramfsck: command not found

I wonder how binwalk ended up working at all 🤔

@Pamplemousse
Copy link
Member Author

I added a commit to update the expression of cramfsswap for the binary to be usable:

# before
$ nix-shell --pure -p 'cramfsswap' --run 'cramfsswap -h'/nixpkgs
/tmp/nix-shell-10374-0/rc: line 1: cramfsswap: command not found

# after
$ nix-shell --pure -p 'cramfsswap' --run 'cramfsswap -h'
Usage: cramfsswap <in> <out>

Copy link
Contributor

@jonringer jonringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could be wrong about the propagatedBuildInputs and PATH, but I still think it would be preferable to do something like:

  makeWrapperArgs = [ "--prefix PATH : ${makeBinPath [ cramfsswap cramfsprogs ]} ';

As I have seen large dev closures when propagating native packages.

Fortunately, this doesnt seem to be the case here:

$ nix path-info -Sh ./result
/nix/store/6h3cq7dk6g3v0zq235sa8plgafifqv5k-python3.8-binwalk-2.2.0	 160.0M
[nix-shell:/home/jon/.cache/nixpkgs-review/pr-94268]$ nix path-info -Sh ./results/python37Packages.binwalk
/nix/store/xxcdvxp77lzwxp8a4gwkap0qb3rdzrkz-python3.7-binwalk-2.2.0	 157.7M

@jonringer
Copy link
Contributor

I think you pushed some commits by accident

Signed-off-by: Pamplemousse <xav.maso@gmail.com>
Signed-off-by: Pamplemousse <xav.maso@gmail.com>
Signed-off-by: Pamplemousse <xav.maso@gmail.com>
Copy link
Contributor

@jonringer jonringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
shows usage

https://github.com/NixOS/nixpkgs/pull/94268
8 packages built:
cramfsprogs cramfsswap python27Packages.binwalk python27Packages.binwalk-full python37Packages.binwalk python37Packages.binwalk-full python38Packages.binwalk python38Packages.binwalk-full

@jonringer jonringer merged commit 35c702c into NixOS:master Aug 7, 2020
@Pamplemousse Pamplemousse deleted the binwalk branch August 20, 2020 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants