fix(nix/dependency-analyzer): don't read from non-drv store paths

Emitting dependencies on non-drv store paths from drv directDrvDeps is
fine and actually correct, even though the Nix 2.3 version can't do it
at the moment (but this would change when the placeholder implementation
is replaced using a drv parser). However, we can't necessarily determine
the dependencies of non-drv store paths because such store paths may be
binary files that can't be read in by readFile due to NUL bytes.

Change-Id: Ifbd101adaee4f32f10c010fa79e19b9b1127fc6a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6945
Autosubmit: sterni <sternenseemann@systemli.org>
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
This commit is contained in:
sterni 2022-10-11 14:28:27 +02:00 committed by clbot
parent 0025a6fd64
commit 8149ca5c38

View file

@ -38,7 +38,13 @@ let
# string context« through a readFile invocation. This has the side effect # string context« through a readFile invocation. This has the side effect
# that it becomes possible to query the actual references a store path has. # that it becomes possible to query the actual references a store path has.
# Not a 100% sure this is intended, but _very_ convenient for us here. # Not a 100% sure this is intended, but _very_ convenient for us here.
drvPath: builtins.attrNames (builtins.getContext (builtins.readFile drvPath)) drvPath:
# if the passed path is not a derivation we can't necessarily get its
# dependencies, since it may not be representable as a Nix string due to
# NUL bytes, e.g. compressed patch files imported into the Nix store.
if builtins.match "^.+\\.drv$" drvPath == null
then [ ]
else builtins.attrNames (builtins.getContext (builtins.readFile drvPath))
else else
# For Nix < 2.6 we have to rely on HACK, namely grepping for quoted store # For Nix < 2.6 we have to rely on HACK, namely grepping for quoted store
# path references in the file. In the future this should be replaced by # path references in the file. In the future this should be replaced by