summary refs log tree commit diff
path: root/pkgs/build-support/trivial-builders.nix
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2021-05-14 17:27:25 +0200
committerRobert Hensing <robert@roberthensing.nl>2021-05-15 17:04:25 +0200
commitcc60f81e69154789ad3e23f0ec60110ed3f7aece (patch)
tree7c70d66ed73617ef073aeebd8f4ffb49620f81a5 /pkgs/build-support/trivial-builders.nix
parent80a3e0dc0ef11ecd7c6171318d2e3f2f5390b6ac (diff)
downloadnixpkgs-cc60f81e69154789ad3e23f0ec60110ed3f7aece.tar
nixpkgs-cc60f81e69154789ad3e23f0ec60110ed3f7aece.tar.gz
nixpkgs-cc60f81e69154789ad3e23f0ec60110ed3f7aece.tar.bz2
nixpkgs-cc60f81e69154789ad3e23f0ec60110ed3f7aece.tar.lz
nixpkgs-cc60f81e69154789ad3e23f0ec60110ed3f7aece.tar.xz
nixpkgs-cc60f81e69154789ad3e23f0ec60110ed3f7aece.tar.zst
nixpkgs-cc60f81e69154789ad3e23f0ec60110ed3f7aece.zip
writeDirectReferencesToFile: init
Diffstat (limited to 'pkgs/build-support/trivial-builders.nix')
-rw-r--r--pkgs/build-support/trivial-builders.nix29
1 files changed, 29 insertions, 0 deletions
diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix
index 142a04f9a10..0bf67d21b3b 100644
--- a/pkgs/build-support/trivial-builders.nix
+++ b/pkgs/build-support/trivial-builders.nix
@@ -438,6 +438,35 @@ rec {
       done < graph
     '';
 
+  /*
+    Write the set of references to a file, that is, their immediate dependencies.
+
+    This produces the equivalent of `nix-store -q --references`.
+   */
+  writeDirectReferencesToFile = path: runCommand "runtime-references"
+    {
+      exportReferencesGraph = ["graph" path];
+      inherit path;
+    }
+    ''
+      touch ./references
+      while read p; do
+        read dummy
+        read nrRefs
+        if [[ $p == $path ]]; then
+          for ((i = 0; i < nrRefs; i++)); do
+            read ref;
+            echo $ref >>./references
+          done
+        else
+          for ((i = 0; i < nrRefs; i++)); do
+            read ref;
+          done
+        fi
+      done < graph
+      sort ./references >$out
+    '';
+
 
   /* Print an error message if the file with the specified name and
    * hash doesn't exist in the Nix store. This function should only