about summary refs log tree commit diff
path: root/nix
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2024-03-08T23·17+0100
committerclbot <clbot@tvl.fyi>2024-04-15T19·21+0000
commit4a91197802edbe6257e52cd20cd418122d733c26 (patch)
tree768f6af7dea9d2c127a6a643b69dc505efa08d08 /nix
parentd1da9f5c84b340067fb9daf952bb1a850f8ce7bf (diff)
fix(nix/dependency-analyzer): ignore non-drv paths for Nix < 2.6 r/7933
Looking for .drv file names in non .drv files doesn't make sense, as it
less reliably a reference in those cases. Matches behavior of the
function for Nix >= 2.6.

Change-Id: I79fc1da3e55df869f03702fa5137d030790bc4eb
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11114
Autosubmit: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: aspen <root@gws.fyi>
Diffstat (limited to 'nix')
-rw-r--r--nix/dependency-analyzer/default.nix53
1 files changed, 29 insertions, 24 deletions
diff --git a/nix/dependency-analyzer/default.nix b/nix/dependency-analyzer/default.nix
index 54ff72912ea8..2ec8d7b5b940 100644
--- a/nix/dependency-analyzer/default.nix
+++ b/nix/dependency-analyzer/default.nix
@@ -16,30 +16,35 @@ let
   #
   # TODO(sterni): clean this up and expose it
   directDrvDeps =
-    if lib.versionAtLeast builtins.nixVersion "2.6"
-    then
-    # Since https://github.com/NixOS/nix/pull/1643, Nix apparently »preserves
-    # 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:
-      # 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
-    # a proper derivation parser.
-      drvPath: builtins.concatLists (
-        builtins.filter builtins.isList (
-          builtins.split
-            "\"(${lib.escapeRegex builtins.storeDir}/[[:alnum:]+._?=-]+.drv)\""
-            (builtins.readFile drvPath)
-        )
-      );
+    let
+      getDeps =
+        if lib.versionAtLeast builtins.nixVersion "2.6"
+        then
+        # Since https://github.com/NixOS/nix/pull/1643, Nix apparently »preserves
+        # 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))
+        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 a proper derivation parser.
+          drvPath: builtins.concatLists (
+            builtins.filter builtins.isList (
+              builtins.split
+                "\"(${lib.escapeRegex builtins.storeDir}/[[:alnum:]+._?=-]+.drv)\""
+                (builtins.readFile drvPath)
+            )
+          );
+    in
+    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 getDeps drvPath;
 
   # Maps a list of derivation to the list of corresponding `drvPath`s.
   #