[Nix-dev] Nix language: converting an attribute set to a list

2014-04-14 Thread Sergey Mironov
Hi. Nix language has a built-in function builtins.listToAttrs which
converts list to the Attrs. I'm searching a way to make an opposite
thing - convert attrs to a list. Say, I'd like to convert

  users = {
root = { name = root; group = groups.root; };
ssh = { name = ssh ; group = groups.nogroup ; severity = 33; };
  };

to a list like this:

  [
{ name = root; group = groups.root; }
{ name = ssh ; group = groups.nogroup ; severity = 33; }
  ];

to use it later both in shell scripting, as list

lib.map  (toList users) (u: ''
  adduser ${u.name} ${u.group}
'');

.. and in derivations, by reference

stdenv.mkDerivation ssh {
  user = users.ssh;
};

In order to workaround the problem I have to add additional field
`list' (like below) but this way I have to duplicate field names which
is not good (easy to forget). So Is it possible to do the
transformation in a more
safe way?

Regards,
Sergey

# A workaround

  users = rec {
root = { name = root; group = groups.root; };
ssh = { name = ssh ; group = groups.nogroup ; severity = 33; };
list = [ root ssh ];
  };
___
nix-dev mailing list
nix-dev@lists.science.uu.nl
http://lists.science.uu.nl/mailman/listinfo/nix-dev


Re: [Nix-dev] Nix language: converting an attribute set to a list

2014-04-14 Thread Marc Weber
attrValues (mapAttrs (name: vals: merge or check that name is same as name key) 
) attrs

Marc Weber
___
nix-dev mailing list
nix-dev@lists.science.uu.nl
http://lists.science.uu.nl/mailman/listinfo/nix-dev