···2 stdenv,
3 lib,
4 fetchurl,
5+ writeShellScript,
6}:
7let
8 versionMetadata = import ./sysdig-cli-scanner.versions.nix;
9 fetchForSystem = versionMetadata.${stdenv.system} or (throw "unsupported system ${stdenv.system}");
10+11+ wrapper = writeShellScript "sysdig-cli-scanner-wrapper" ''
12+ for arg in "$@"; do
13+ # We must not pass --dbpath to the cli in case it has been called with --iac
14+ # IaC Scanning does not make use of the vulnerability database
15+ if [ "$arg" = "--iac" ]; then
16+ exec @out@/libexec/sysdig-cli-scanner-unwrapped "$@"
17+ fi
18+ done
19+20+ # --dbpath argument is needed for vulnerability scanning mode, otherwise it tries to download
21+ # the vulnerability database in the same path as the binary, which is read-only in the case of the
22+ # nix store
23+ exec @out@/libexec/sysdig-cli-scanner-unwrapped \
24+ --dbpath="$HOME/.cache/sysdig-cli-scanner/" "$@"
25+ '';
26in
27stdenv.mkDerivation {
28 pname = "sysdig-cli-scanner";
29 version = versionMetadata.version;
3031 src = fetchurl { inherit (fetchForSystem) url hash; };
00032 dontUnpack = true;
3334 installPhase = ''
35 runHook preInstall
3637+ install -Dm755 -T $src $out/libexec/sysdig-cli-scanner-unwrapped
38+ install -Dm755 -T ${wrapper} $out/bin/sysdig-cli-scanner
39+ substituteInPlace $out/bin/sysdig-cli-scanner --subst-var out
04041 runHook postInstall
42 '';