recursiveGetAttrsetWithJqPrefix: fix top level values#434171
recursiveGetAttrsetWithJqPrefix: fix top level values#434171jian-lin merged 1 commit intoNixOS:masterfrom
Conversation
There was a problem hiding this comment.
The implementation looks good.
I guess the intended use case is the same as configFile, which is a bit weird to me. However, the implementation is simple and easy to understand, so I do not mind supporting that use case.
I tested it with NixOS tests for nginx-sso, glance and scrutiny.
I will merge this in a few days if Yinfeng has no other opinion.
|
The idea was more about feature completeness and having less surprise. There's no documentation saying that top level secret is not supported so we should properly implement it. Also the implementation is simple enough that there isn't any reason not to support this use case. |
|
I think the real problem is that the original My fix: diff --git a/nixos/lib/utils.nix b/nixos/lib/utils.nix
index 251e0460dd03..35f5853e3f66 100644
--- a/nixos/lib/utils.nix
+++ b/nixos/lib/utils.nix
@@ -219,14 +219,14 @@ let
let
escapedName = ''"${replaceStrings [ ''"'' "\\" ] [ ''\"'' "\\\\" ] name}"'';
in
- recurse (prefix + "." + escapedName) item.${name}
+ recurse (prefix + (if prefix == "." then "" else ".") + escapedName) item.${name}
) (attrNames item)
else if isList item then
imap0 (index: item: recurse (prefix + "[${toString index}]") item) item
else
[ ];
in
- listToAttrs (flatten (recurse "" item));
+ listToAttrs (flatten (recurse "." item));
/*
Takes an attrset and a file path and generates a bash snippet that
Some test cases that will broken under the original implementation:
|
Co-authored-by: linyinfeng <lin.yinfeng@outlook.com>
8a9cd18 to
c4bfbd8
Compare
jian-lin
left a comment
There was a problem hiding this comment.
Nice catch! @linyinfeng
Also thanks @Prince213 for this PR.
This PR allows recursiveGetAttrsetWithJqPrefix to properly handle top level value such as dictionaries, which will have a empty
nameand causejqto fail, and arrays where[0]would be used instead of the correct.[0].Example:
Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.Add a 👍 reaction to pull requests you find important.