···22 stdenv,
33 lib,
44 fetchurl,
55- makeWrapper,
55+ writeShellScript,
66}:
77let
88 versionMetadata = import ./sysdig-cli-scanner.versions.nix;
99 fetchForSystem = versionMetadata.${stdenv.system} or (throw "unsupported system ${stdenv.system}");
1010+1111+ wrapper = writeShellScript "sysdig-cli-scanner-wrapper" ''
1212+ for arg in "$@"; do
1313+ # We must not pass --dbpath to the cli in case it has been called with --iac
1414+ # IaC Scanning does not make use of the vulnerability database
1515+ if [ "$arg" = "--iac" ]; then
1616+ exec @out@/libexec/sysdig-cli-scanner-unwrapped "$@"
1717+ fi
1818+ done
1919+2020+ # --dbpath argument is needed for vulnerability scanning mode, otherwise it tries to download
2121+ # the vulnerability database in the same path as the binary, which is read-only in the case of the
2222+ # nix store
2323+ exec @out@/libexec/sysdig-cli-scanner-unwrapped \
2424+ --dbpath="$HOME/.cache/sysdig-cli-scanner/" "$@"
2525+ '';
1026in
1127stdenv.mkDerivation {
1228 pname = "sysdig-cli-scanner";
1329 version = versionMetadata.version;
14301531 src = fetchurl { inherit (fetchForSystem) url hash; };
1616-1717- nativeBuildInputs = [ makeWrapper ];
1818-1932 dontUnpack = true;
20332134 installPhase = ''
2235 runHook preInstall
23362424- install -Dm755 -T $src $out/bin/sysdig-cli-scanner
2525-2626- wrapProgram $out/bin/sysdig-cli-scanner \
2727- --add-flags --dbpath="\$HOME/.cache/sysdig-cli-scanner/"
3737+ install -Dm755 -T $src $out/libexec/sysdig-cli-scanner-unwrapped
3838+ install -Dm755 -T ${wrapper} $out/bin/sysdig-cli-scanner
3939+ substituteInPlace $out/bin/sysdig-cli-scanner --subst-var out
28402941 runHook postInstall
3042 '';