Skip to content

Instantly share code, notes, and snippets.

@risicle
Last active June 26, 2022 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save risicle/b51e58f77e9ef2a78e4eda5dc778813e to your computer and use it in GitHub Desktop.
Save risicle/b51e58f77e9ef2a78e4eda5dc778813e to your computer and use it in GitHub Desktop.
src-inspector.nix
{ lib, stdenv, unzip, toInspect }:
builtins.mapAttrs (
name: value: let
res = builtins.tryEval value.src or null;
in if (builtins.match "" name) != null && res.success && res.value != null then (stdenv.mkDerivation {
inherit name;
src = res.value;
sourceRoot = ".";
preUnpack = ''
if [ "''${src: -4:4}" = '.whl' ] ; then
oldSrc="$src"
src="$(mktemp -d)/src.zip"
ln -s "$oldSrc" "$src"
fi
'';
nativeBuildInputs = [ unzip ];
dontPatch = true;
dontConfigure = true;
dontBuild = true;
dontFixup = true;
installPhase = ''
find . \
-type f \
-size +0c \
'(' \
-name '*.jar' \
-o \
-exec sed -e '1b p ; Q1 ; :p ; /^\x7fELF/Q0 ; /^[\xce\xcf]\xfa\xed\xfe/Q0 ; /^MZ/Q0 ; Q1' '{}' ';'
')' \
-print > $out || true
'';
}) else null
) toInspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment