summary refs log tree commit diff
path: root/lib/attrsets.nix
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2021-12-02 18:12:51 +0100
committerSilvan Mosberger <contact@infinisil.com>2022-03-18 00:05:08 +0100
commit71b130c581c81bf3bd2a3c777f7cc11d746327ae (patch)
tree9e30497b8edff6f64fe682150a1c5b57c7639831 /lib/attrsets.nix
parent671a068a0166a5474e51b4d151b64250f8feaec8 (diff)
downloadnixpkgs-71b130c581c81bf3bd2a3c777f7cc11d746327ae.tar
nixpkgs-71b130c581c81bf3bd2a3c777f7cc11d746327ae.tar.gz
nixpkgs-71b130c581c81bf3bd2a3c777f7cc11d746327ae.tar.bz2
nixpkgs-71b130c581c81bf3bd2a3c777f7cc11d746327ae.tar.lz
nixpkgs-71b130c581c81bf3bd2a3c777f7cc11d746327ae.tar.xz
nixpkgs-71b130c581c81bf3bd2a3c777f7cc11d746327ae.tar.zst
nixpkgs-71b130c581c81bf3bd2a3c777f7cc11d746327ae.zip
lib.attrsets: Introduce showAttrPath
Diffstat (limited to 'lib/attrsets.nix')
-rw-r--r--lib/attrsets.nix16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/attrsets.nix b/lib/attrsets.nix
index a88947b4585..7a3df9059c0 100644
--- a/lib/attrsets.nix
+++ b/lib/attrsets.nix
@@ -4,7 +4,7 @@
 let
   inherit (builtins) head tail length;
   inherit (lib.trivial) id;
-  inherit (lib.strings) concatStringsSep sanitizeDerivationName;
+  inherit (lib.strings) concatStringsSep concatMapStringsSep escapeNixIdentifier sanitizeDerivationName;
   inherit (lib.lists) foldr foldl' concatMap concatLists elemAt all;
 in
 
@@ -477,6 +477,20 @@ rec {
   overrideExisting = old: new:
     mapAttrs (name: value: new.${name} or value) old;
 
+  /* Turns a list of strings into a human-readable description of those
+    strings represented as an attribute path. The result of this function is
+    not intended to be machine-readable.
+
+    Example:
+      showAttrPath [ "foo" "10" "bar" ]
+      => "foo.\"10\".bar"
+      showAttrPath []
+      => "<root attribute path>"
+  */
+  showAttrPath = path:
+    if path == [] then "<root attribute path>"
+    else concatMapStringsSep "." escapeNixIdentifier path;
+
   /* Get a package output.
      If no output is found, fallback to `.out` and then to the default.