Skip to content

Instantly share code, notes, and snippets.

@maxsei
Created April 4, 2023 15:39
Show Gist options
  • Select an option

  • Save maxsei/57ee470aef0b9cc8a81e008e85e69d3c to your computer and use it in GitHub Desktop.

Select an option

Save maxsei/57ee470aef0b9cc8a81e008e85e69d3c to your computer and use it in GitHub Desktop.
Get the keys of a nested object in a flat data structure in nix
let
flatkeys = cur:
if builtins.isAttrs cur then
(builtins.concatMap
(k: builtins.map (x: [ k ] ++ x) (flatkeys cur."${k}"))
(builtins.attrNames cur))
else if builtins.isList cur then
builtins.concatLists (builtins.genList
(i: builtins.map (x: [ i ] ++ x) (flatkeys (builtins.elemAt cur i)))
(builtins.length cur))
else
[ [ ] ];
in
flatkeys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment