From 8149ca5c3802d0dd757224afb74f6b46cc55a7dd Mon Sep 17 00:00:00 2001 From: sterni Date: Tue, 11 Oct 2022 14:28:27 +0200 Subject: [PATCH] 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 Reviewed-by: grfn Tested-by: BuildkiteCI --- nix/dependency-analyzer/default.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nix/dependency-analyzer/default.nix b/nix/dependency-analyzer/default.nix index c988d9409..e127c82d7 100644 --- a/nix/dependency-analyzer/default.nix +++ b/nix/dependency-analyzer/default.nix @@ -38,7 +38,13 @@ let # string context« through a readFile invocation. This has the side effect # 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. - 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 # 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